From 9c2489c0c360c8dda36d3cbe1dba79222096b2dd Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期一, 07 八月 2023 10:16:39 +0800 Subject: [PATCH] Merge branch 'master' into fly --- api/v1/faultType.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 110 insertions(+), 0 deletions(-) diff --git a/api/v1/faultType.go b/api/v1/faultType.go new file mode 100644 index 0000000..233652f --- /dev/null +++ b/api/v1/faultType.go @@ -0,0 +1,110 @@ +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, + }) +} -- Gitblit v1.8.0