2023-07-14 16:47:59 +08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
jwt "github.com/appleboy/gin-jwt/v2"
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-07-27 16:59:55 +08:00
|
|
|
"joylink.club/bj-rtsts-server/db/model"
|
2023-07-14 16:47:59 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
|
|
|
"joylink.club/bj-rtsts-server/middleware"
|
|
|
|
"joylink.club/bj-rtsts-server/service"
|
2023-10-20 18:08:06 +08:00
|
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
2023-07-14 16:47:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
2023-08-30 09:28:21 +08:00
|
|
|
authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
2023-07-18 17:19:03 +08:00
|
|
|
authed.GET("/paging", pageQueryDrafting)
|
2023-10-12 17:55:41 +08:00
|
|
|
authed.GET("/list", listQueryDrafting)
|
2023-07-14 16:47:59 +08:00
|
|
|
authed.POST("", createDrafting)
|
|
|
|
authed.POST("/:id/saveAs", saveAsDrafting)
|
2023-07-14 18:09:07 +08:00
|
|
|
authed.GET("/:id", queryDraftingInfo)
|
|
|
|
authed.PUT("/:id", updateDraftingInfo)
|
2023-07-25 17:18:37 +08:00
|
|
|
authed.DELETE("/:id", deleteDrafting)
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 分页查询草稿
|
|
|
|
//
|
|
|
|
// @Summary 分页查询草稿
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 可以通过草稿名称过滤,分页查询草稿
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param PageDraftingReqDto query dto.PageDraftingReqDto true "草稿查询条件带分页信息"
|
2023-07-14 18:09:07 +08:00
|
|
|
// @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]
|
2023-07-14 16:47:59 +08:00
|
|
|
func pageQueryDrafting(c *gin.Context) {
|
|
|
|
req := dto.PageDraftingReqDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("查询失败,参数格式错误", err))
|
2023-07-28 14:13:03 +08:00
|
|
|
}
|
2023-10-20 18:08:06 +08:00
|
|
|
c.JSON(http.StatusOK, service.PageDraftingQuery(&req))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 17:55:41 +08:00
|
|
|
// 列表查询草稿
|
|
|
|
//
|
|
|
|
// @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
|
2023-10-18 13:53:17 +08:00
|
|
|
// @Router /api/v1/drafting/list [get]
|
2023-10-12 17:55:41 +08:00
|
|
|
func listQueryDrafting(c *gin.Context) {
|
|
|
|
req := dto.ListDraftingReqDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("查询失败,参数格式错误", err))
|
2023-10-12 17:55:41 +08:00
|
|
|
}
|
2023-10-20 18:08:06 +08:00
|
|
|
c.JSON(http.StatusOK, service.ListDraftingQuery(&req))
|
2023-10-12 17:55:41 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 创建草稿
|
|
|
|
//
|
|
|
|
// @Summary 创建草稿
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 创建草稿数据
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param draftingDto query dto.DraftingDto true "创建的草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
|
|
|
// @Router /api/v1/drafting [post]
|
2023-07-14 16:47:59 +08:00
|
|
|
func createDrafting(c *gin.Context) {
|
2023-07-27 16:59:55 +08:00
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
2023-07-28 14:13:03 +08:00
|
|
|
createId := user.(*model.User).ID
|
2023-07-14 16:47:59 +08:00
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("创建失败,参数格式错误", err))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
2023-10-20 18:08:06 +08:00
|
|
|
c.JSON(http.StatusOK, service.CreateDrafting(createId, &req))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 18:09:07 +08:00
|
|
|
// 草稿另存为
|
|
|
|
//
|
|
|
|
// @Summary 草稿另存为
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 草稿另存为
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "源草稿id"
|
|
|
|
// @Param draftingDto query dto.DraftingDto true "另存为草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id}/saveAs [post]
|
2023-07-14 16:47:59 +08:00
|
|
|
func saveAsDrafting(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("另存为失败,缺少主键"))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
2023-07-27 16:59:55 +08:00
|
|
|
user, _ := c.Get(middleware.IdentityKey)
|
2023-07-28 14:13:03 +08:00
|
|
|
createrId := user.(*model.User).ID
|
2023-07-14 16:47:59 +08:00
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("另存为失败,参数格式错误", err))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
2023-10-20 18:08:06 +08:00
|
|
|
c.JSON(http.StatusOK, service.SaveAsDrafting(createrId, int32(int64Id), &req))
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 查询草稿详情
|
|
|
|
//
|
|
|
|
// @Summary 查询草稿详情
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 查询草稿详情
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "草稿ID"
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Success 200 {object} model.Drafting
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [get]
|
2023-07-14 18:09:07 +08:00
|
|
|
func queryDraftingInfo(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("查询失败,缺少主键"))
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
|
|
|
c.JSON(http.StatusOK, service.QueryDrafting(int32(int64Id)))
|
|
|
|
}
|
|
|
|
|
2023-07-28 14:13:03 +08:00
|
|
|
// 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
//
|
2023-07-28 14:13:03 +08:00
|
|
|
// @Summary 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
2023-07-28 14:13:03 +08:00
|
|
|
// @Description 修改草稿信息
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
2023-07-25 17:18:37 +08:00
|
|
|
// @Param id path int true "草稿ID"
|
|
|
|
// @Param draftingDto query dto.DraftingDto true "修改的草稿信息"
|
2023-07-18 17:19:03 +08:00
|
|
|
// @Success 200 {object} nil
|
2023-07-14 18:09:07 +08:00
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [put]
|
2023-07-14 18:09:07 +08:00
|
|
|
func updateDraftingInfo(c *gin.Context) {
|
|
|
|
id, exist := c.Params.Get("id")
|
|
|
|
if !exist {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("更新失败,缺少主键"))
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
req := dto.DraftingDto{}
|
|
|
|
if err := c.ShouldBind(&req); err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("更新失败,参数格式错误", err))
|
2023-07-14 18:09:07 +08:00
|
|
|
}
|
|
|
|
int64Id, _ := strconv.ParseInt(id, 10, 64)
|
2023-10-20 18:08:06 +08:00
|
|
|
c.JSON(http.StatusOK, service.UpdateDrafting(int32(int64Id), &req))
|
2023-07-14 16:47:59 +08:00
|
|
|
}
|
2023-07-25 17:18:37 +08:00
|
|
|
|
|
|
|
// 删除草稿数据
|
|
|
|
//
|
|
|
|
// @Summary 删除草稿数据
|
|
|
|
//
|
|
|
|
// @Security JwtAuth
|
|
|
|
//
|
|
|
|
// @Description 删除草稿数据
|
|
|
|
// @Tags 草稿Api
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id path int true "草稿ID"
|
|
|
|
// @Success 200 {object} nil
|
|
|
|
// @Failure 401 {object} dto.ErrorDto
|
|
|
|
// @Failure 404 {object} dto.ErrorDto
|
|
|
|
// @Failure 500 {object} dto.ErrorDto
|
2023-08-28 15:24:17 +08:00
|
|
|
// @Router /api/v1/drafting/{id} [delete]
|
2023-07-25 17:18:37 +08:00
|
|
|
func deleteDrafting(c *gin.Context) {
|
|
|
|
idStr := c.Param("id")
|
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
|
if err != nil {
|
2023-10-20 18:08:06 +08:00
|
|
|
panic(sys_error.New("删除失败,主键格式错误", err))
|
2023-07-25 17:18:37 +08:00
|
|
|
}
|
|
|
|
service.DeleteDraftingById(id)
|
2023-07-28 14:13:03 +08:00
|
|
|
c.JSON(http.StatusOK, true)
|
2023-07-25 17:18:37 +08:00
|
|
|
}
|