rts-sim-testing-service/api/simulation.go
2023-07-28 14:36:16 +08:00

74 lines
2.0 KiB
Go

package api
import (
"fmt"
"net/http"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"joylink.club/bj-rtsts-server/dto"
)
func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc())
authed.POST("/create", create)
authed.POST("/train/add", addTrain)
}
// 创建ATS测试仿真
//
// @Summary 创建ATS测试仿真
//
// @Security JwtAuth
//
// @Description 创建ATS测试仿真
// @Tags ATS测试仿真Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
// @Param SimulationCreateReqDto body dto.SimulationCreateReqDto true "创建仿真请求"
// @Success 200 {object} dto.SimulationCreateRspDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/create [post]
func create(c *gin.Context) {
//user,_:=c.Get(middleware.IdentityKey)
req := dto.SimulationCreateReqDto{}
if err := c.ShouldBind(&req); nil != err {
panic(err)
}
zap.S().Debug("创建仿真请求:", req)
rsp := dto.SimulationCreateRspDto{}
rsp.MapId = req.MapId
rsp.SimulationId = fmt.Sprintf("sim-%d", req.MapId)
c.JSON(http.StatusOK, &rsp)
}
// ATS测试仿真-添加列车
//
// @Summary ATS测试仿真-添加列车
//
// @Security JwtAuth
//
// @Description ATS测试仿真-添加列车
// @Tags ATS测试仿真Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
// @Param AddTrainReqDto body dto.AddTrainReqDto true "ATS测试仿真-添加列车"
// @Success 200 {object} dto.AddTrainRspDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/train/add [post]
func addTrain(c *gin.Context) {
//user,_:=c.Get(middleware.IdentityKey)
req := dto.AddTrainReqDto{}
if err := c.ShouldBind(&req); nil != err {
panic(err)
}
zap.S().Debug("ATS测试仿真-添加列车,请求:", req)
rsp := dto.AddTrainRspDto{}
rsp.SimulationId = req.SimulationId
rsp.TrainId = "666"
c.JSON(http.StatusOK, &rsp)
}