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 FaultTypeApi struct{}
|
|
// Add
|
// @Tags 故障类别管理
|
// @Summary 添加故障类别
|
// @Produce application/json
|
// @Param object body request.AddFaultType true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/faultType/add [post]
|
func (s *FaultTypeApi) Add(c *gin.Context) {
|
var params request.AddFaultType
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := service.NewFaultTypeService().AddFaultType(¶ms.FaultType)
|
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/faultType/delete/{id} [delete]
|
func (s *FaultTypeApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := service.NewFaultTypeService().DeleteFaultType(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
// @Tags 故障类别管理
|
// @Summary 更新故障类别
|
// @Produce application/json
|
// @Param object body request.UpdateFaultType true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/faultType/update [put]
|
func (s *FaultTypeApi) Update(c *gin.Context) {
|
var params request.UpdateFaultType
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
if params.Id == 0 {
|
ctx.Fail(ecode.ParamsErr)
|
}
|
params.FaultType.Id = params.Id
|
|
errCode := service.NewFaultTypeService().UpdateFaultType(¶ms.FaultType)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
// @Tags 故障类别管理
|
// @Summary 获取故障类别列表
|
// @Produce application/json
|
// @Success 200 {object} response.ListResponse{data=[]model.FaultType}
|
// @Router /api/faultType/list [get]
|
func (s *FaultTypeApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
faultType, total, errCode := service.NewFaultTypeService().GetFaultTypeList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.ListResponse{
|
Data: faultType,
|
Count: total,
|
})
|
}
|