diff --git a/api/drafting.go b/api/drafting.go index 5fbacec..47c3170 100644 --- a/api/drafting.go +++ b/api/drafting.go @@ -19,6 +19,7 @@ import ( func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware) authed.GET("/paging", pageQueryDrafting) + authed.GET("/list", listQueryDrafting) authed.POST("", createDrafting) authed.POST("/:id/saveAs", saveAsDrafting) authed.GET("/:id", queryDraftingInfo) @@ -58,6 +59,37 @@ func pageQueryDrafting(c *gin.Context) { c.JSON(http.StatusOK, page) } +// 列表查询草稿 +// +// @Summary 列表查询草稿 +// +// @Security JwtAuth +// +// @Description 可以通过草稿类型过滤,列表查询草稿 +// @Tags 草稿Api +// @Accept json +// @Produce json +// @Param ListDraftingReqDto query dto.ListDraftingReqDto true "草稿查询条件带分页信息" +// @Success 200 {object} dto.PageDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/drafting/paging [get] +func listQueryDrafting(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + slog.Debug("列表查询草稿", user) + req := dto.ListDraftingReqDto{} + if err := c.ShouldBind(&req); err != nil { + panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()}) + } + slog.Debug("列表查草稿参数", req) + list, err := service.ListDraftingQuery(&req) + if err != nil { + panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) + } + c.JSON(http.StatusOK, list) +} + // 创建草稿 // // @Summary 创建草稿 diff --git a/bj-rtss-message b/bj-rtss-message index c772733..85290a8 160000 --- a/bj-rtss-message +++ b/bj-rtss-message @@ -1 +1 @@ -Subproject commit c772733535c2f9b370d2bfaf220cc686344b755e +Subproject commit 85290a8ba96ee41ab47a61f44e913f308c8599d7 diff --git a/dto/drafting.go b/dto/drafting.go index b3f9bb7..d94d0c3 100644 --- a/dto/drafting.go +++ b/dto/drafting.go @@ -7,6 +7,10 @@ type PageDraftingReqDto struct { Name string `json:"name" form:"name"` } +type ListDraftingReqDto struct { + Type int32 `json:"type" form:"type"` +} + type DraftingDto struct { Id int `json:"id" form:"id"` Name string `json:"name" form:"name"` diff --git a/service/drafting.go b/service/drafting.go index 96ceb0e..19584a7 100644 --- a/service/drafting.go +++ b/service/drafting.go @@ -23,6 +23,19 @@ func PageDraftingQuery(query *dto.PageDraftingReqDto) (*dto.PageDto, error) { return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil } +func ListDraftingQuery(query *dto.ListDraftingReqDto) ([]*model.Drafting, error) { + d := dbquery.Drafting + dq := d.Where() + if query.Type != 0 { + dq = dq.Where(d.Type.Eq(query.Type)) + } + records, err := dq.Debug().Omit(d.Proto).Find() + if err != nil { + panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) + } + return records, nil +} + // 创建草稿 func CreateDrafting(createId int32, dd *dto.DraftingDto) (*model.Drafting, error) { if err := checkDraftingInfo(dd.Name); err != nil {