package v1
|
|
import (
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"aps_crm/service"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type PriorityLevelApi struct{}
|
|
// Add
|
// @Tags 优先级别管理
|
// @Summary 添加优先级别
|
// @Produce application/json
|
// @Param object body request.AddPriorityLevel true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/priorityLevel/add [post]
|
func (s *PriorityLevelApi) Add(c *gin.Context) {
|
var params request.AddPriorityLevel
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := service.NewPriorityLevelService().AddPriorityLevel(¶ms.PriorityLevel)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
// @Tags 优先级别管理
|
// @Summary 删除优先级别
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/priorityLevel/delete/{id} [delete]
|
func (s *PriorityLevelApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := service.NewPriorityLevelService().DeletePriorityLevel(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
// @Tags 优先级别管理
|
// @Summary 更新优先级别
|
// @Produce application/json
|
// @Param object body request.UpdatePriorityLevel true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/priorityLevel/update [put]
|
func (s *PriorityLevelApi) Update(c *gin.Context) {
|
var params request.UpdatePriorityLevel
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
if params.Id == 0 {
|
ctx.Fail(ecode.ParamsErr)
|
}
|
params.PriorityLevel.Id = params.Id
|
|
errCode := service.NewPriorityLevelService().UpdatePriorityLevel(¶ms.PriorityLevel)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
// @Tags 优先级别管理
|
// @Summary 获取优先级别列表
|
// @Produce application/json
|
// @Success 200 {object} response.ListResponse{data=[]model.PriorityLevel}
|
// @Router /api/priorityLevel/list [get]
|
func (s *PriorityLevelApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
priorityLevel, total, errCode := service.NewPriorityLevelService().GetPriorityLevelList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.ListResponse{
|
Data: priorityLevel,
|
Count: total,
|
})
|
}
|