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 ServiceContractTypeApi struct{} // Add // // @Tags ServiceContractType // @Summary 添加服务合同类型 // @Produce application/json // @Param object body request.AddServiceContractType true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceContractType/add [post] func (s *ServiceContractTypeApi) Add(c *gin.Context) { var params request.AddServiceContractType ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } serviceContractType := new(model.ServiceContractType) serviceContractType.Name = params.Name errCode := serviceContractTypeService.AddServiceContractType(serviceContractType) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // // @Tags ServiceContractType // @Summary 删除服务合同类型 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceContractType/delete/{id} [delete] func (s *ServiceContractTypeApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := serviceContractTypeService.DeleteServiceContractType(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // // @Tags ServiceContractType // @Summary 更新服务合同类型 // @Produce application/json // @Param object body request.UpdateServiceContractTypes true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceContractType/update [put] func (s *ServiceContractTypeApi) Update(c *gin.Context) { var params request.UpdateServiceContractTypes ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := serviceContractTypeService.UpdateServiceContractType(params.ServiceContractTypes) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // // @Tags ServiceContractType // @Summary 获取服务合同类型列表 // @Produce application/json // @Success 200 {object} contextx.Response{data=response.ServiceContractTypeResponse} // @Router /api/serviceContractType/list [get] func (s *ServiceContractTypeApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } serviceContractTypes, errCode := serviceContractTypeService.GetServiceContractTypeList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ServiceContractTypeResponse{ List: serviceContractTypes, }) }