package v1
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type StatusApi struct{}
|
|
// Add
|
//
|
// @Tags SalesReturnStatus
|
// @Summary 添加状态
|
// @Produce application/json
|
// @Param object body request.AddStatus true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/status/add [post]
|
func (s *StatusApi) Add(c *gin.Context) {
|
var params request.AddStatus
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
status := new(model.Status)
|
status.Name = params.Name
|
|
errCode := statusService.AddStatus(status)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags SalesReturnStatus
|
// @Summary 删除状态
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/status/delete/{id} [delete]
|
func (s *StatusApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := statusService.DeleteStatus(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags SalesReturnStatus
|
// @Summary 更新状态
|
// @Produce application/json
|
// @Param object body request.UpdateStatusList true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/status/update [put]
|
func (s *StatusApi) Update(c *gin.Context) {
|
var params request.UpdateStatusList
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := statusService.UpdateStatus(params.List)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags SalesReturnStatus
|
// @Summary 状态列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/status/list [get]
|
func (s *StatusApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
list, errCode := statusService.GetStatusList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.StatusResponse{
|
List: list,
|
})
|
}
|