修复swagger

This commit is contained in:
2025-09-19 15:55:56 +08:00
parent 3af1b4949f
commit 88e0fbfb64
9 changed files with 187 additions and 63 deletions

View File

@@ -106,7 +106,7 @@ func newListDeviceResponse(devices []*models.Device) []*DeviceResponse {
// @Param device body CreateDeviceRequest true "设备信息"
// @Success 200 {object} controller.Response{data=DeviceResponse} "业务码为201代表创建成功"
// @Failure 200 {object} controller.Response "业务失败,具体错误码和信息见响应体"
// @Router /devices [post]
// @Router /api/v1/devices [post]
func (c *Controller) CreateDevice(ctx *gin.Context) {
var req CreateDeviceRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
@@ -141,7 +141,7 @@ func (c *Controller) CreateDevice(ctx *gin.Context) {
// @Param id path string true "设备ID"
// @Success 200 {object} controller.Response{data=DeviceResponse} "业务码为200代表获取成功"
// @Failure 200 {object} controller.Response "业务失败,具体错误码和信息见响应体"
// @Router /devices/{id} [get]
// @Router /api/v1/devices/{id} [get]
func (c *Controller) GetDevice(ctx *gin.Context) {
deviceID := ctx.Param("id")
@@ -170,7 +170,7 @@ func (c *Controller) GetDevice(ctx *gin.Context) {
// @Produce json
// @Success 200 {object} controller.Response{data=[]DeviceResponse} "业务码为200代表获取成功"
// @Failure 200 {object} controller.Response "业务失败,具体错误码和信息见响应体"
// @Router /devices [get]
// @Router /api/v1/devices [get]
func (c *Controller) ListDevices(ctx *gin.Context) {
devices, err := c.repo.ListAll()
if err != nil {
@@ -192,7 +192,7 @@ func (c *Controller) ListDevices(ctx *gin.Context) {
// @Param device body UpdateDeviceRequest true "要更新的设备信息"
// @Success 200 {object} controller.Response{data=DeviceResponse} "业务码为200代表更新成功"
// @Failure 200 {object} controller.Response "业务失败,具体错误码和信息见响应体"
// @Router /devices/{id} [put]
// @Router /api/v1/devices/{id} [put]
func (c *Controller) UpdateDevice(ctx *gin.Context) {
deviceID := ctx.Param("id")
@@ -246,7 +246,7 @@ func (c *Controller) UpdateDevice(ctx *gin.Context) {
// @Param id path string true "设备ID"
// @Success 200 {object} controller.Response "业务码为200代表删除成功"
// @Failure 200 {object} controller.Response "业务失败,具体错误码和信息见响应体"
// @Router /devices/{id} [delete]
// @Router /api/v1/devices/{id} [delete]
func (c *Controller) DeleteDevice(ctx *gin.Context) {
deviceID := ctx.Param("id")

View File

@@ -118,7 +118,7 @@ func NewController(logger *logs.Logger, planRepo repository.PlanRepository, anal
// @Param plan body CreatePlanRequest true "计划信息"
// @Success 200 {object} controller.Response{data=plan.PlanResponse} "业务码为201代表创建成功"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 500"
// @Router /plans [post]
// @Router /api/v1/plans [post]
func (c *Controller) CreatePlan(ctx *gin.Context) {
var req CreatePlanRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
@@ -160,7 +160,7 @@ func (c *Controller) CreatePlan(ctx *gin.Context) {
// @Param id path int true "计划ID"
// @Success 200 {object} controller.Response{data=plan.PlanResponse} "业务码为200代表成功获取"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id} [get]
// @Router /api/v1/plans/{id} [get]
func (c *Controller) GetPlan(ctx *gin.Context) {
// 1. 从 URL 路径中获取 ID
idStr := ctx.Param("id")
@@ -198,7 +198,7 @@ func (c *Controller) GetPlan(ctx *gin.Context) {
// @Produce json
// @Success 200 {object} controller.Response{data=plan.ListPlansResponse} "业务码为200代表成功获取列表"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 500"
// @Router /plans [get]
// @Router /api/v1/plans [get]
func (c *Controller) ListPlans(ctx *gin.Context) {
// 1. 调用仓库层获取所有计划
plans, err := c.planRepo.ListBasicPlans()
@@ -232,7 +232,7 @@ func (c *Controller) ListPlans(ctx *gin.Context) {
// @Param plan body UpdatePlanRequest true "更新后的计划信息"
// @Success 200 {object} controller.Response{data=plan.PlanResponse} "业务码为200代表更新成功"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id} [put]
// @Router /api/v1/plans/{id} [put]
func (c *Controller) UpdatePlan(ctx *gin.Context) {
// 1. 从 URL 路径中获取 ID
idStr := ctx.Param("id")
@@ -304,7 +304,7 @@ func (c *Controller) UpdatePlan(ctx *gin.Context) {
// @Param id path int true "计划ID"
// @Success 200 {object} controller.Response "业务码为200代表删除成功"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id} [delete]
// @Router /api/v1/plans/{id} [delete]
func (c *Controller) DeletePlan(ctx *gin.Context) {
// 1. 从 URL 路径中获取 ID
idStr := ctx.Param("id")
@@ -333,7 +333,7 @@ func (c *Controller) DeletePlan(ctx *gin.Context) {
// @Param id path int true "计划ID"
// @Success 200 {object} controller.Response "业务码为200代表成功启动计划"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id}/start [post]
// @Router /api/v1/plans/{id}/start [post]
func (c *Controller) StartPlan(ctx *gin.Context) {
// 占位符:此处应调用服务层或仓库层来启动计划
c.logger.Infof("收到启动计划请求 (占位符)")
@@ -348,7 +348,7 @@ func (c *Controller) StartPlan(ctx *gin.Context) {
// @Param id path int true "计划ID"
// @Success 200 {object} controller.Response "业务码为200代表成功停止计划"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 404, 500"
// @Router /plans/{id}/stop [post]
// @Router /api/v1/plans/{id}/stop [post]
func (c *Controller) StopPlan(ctx *gin.Context) {
// 占位符:此处应调用服务层或仓库层来停止计划
c.logger.Infof("收到停止计划请求 (占位符)")

View File

@@ -60,7 +60,7 @@ type LoginResponse struct {
// @Param user body CreateUserRequest true "用户信息"
// @Success 200 {object} controller.Response{data=user.CreateUserResponse} "业务码为201代表创建成功"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 409, 500"
// @Router /users [post]
// @Router /api/v1/users [post]
func (c *Controller) CreateUser(ctx *gin.Context) {
var req CreateUserRequest
if err := ctx.ShouldBindJSON(&req); err != nil {
@@ -104,7 +104,7 @@ func (c *Controller) CreateUser(ctx *gin.Context) {
// @Param credentials body LoginRequest true "登录凭证"
// @Success 200 {object} controller.Response{data=user.LoginResponse} "业务码为200代表登录成功"
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 401, 500"
// @Router /users/login [post]
// @Router /api/v1/users/login [post]
func (c *Controller) Login(ctx *gin.Context) {
var req LoginRequest
if err := ctx.ShouldBindJSON(&req); err != nil {