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 ServiceTypeApi struct{} // Add // @Tags 服务类型管理 // @Summary 添加服务类型 // @Produce application/json // @Param object body request.AddServiceType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceType/add [post] func (s *ServiceTypeApi) Add(c *gin.Context) { var params request.AddServiceType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := service.NewServiceTypeService().AddServiceType(¶ms.ServiceType) 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/serviceType/delete/{id} [delete] func (s *ServiceTypeApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := service.NewServiceTypeService().DeleteServiceType(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // @Tags 服务类型管理 // @Summary 更新服务类型 // @Produce application/json // @Param object body request.UpdateServiceType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceType/update [put] func (s *ServiceTypeApi) Update(c *gin.Context) { var params request.UpdateServiceType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := service.NewServiceTypeService().UpdateServiceType(¶ms.ServiceType) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // @Tags 服务类型管理 // @Summary 获取服务类型列表 // @Produce application/json // @Success 200 {object} response.ListResponse{data=[]model.ServiceType} // @Router /api/serviceType/list [get] func (s *ServiceTypeApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } serviceType, total, errCode := service.NewServiceTypeService().GetServiceTypeList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ListResponse{ Data: serviceType, Count: total, }) }