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 RegularCustomersApi struct{} // Add // // @Tags RegularCustomers // @Summary 添加常客 // @Produce application/json // @Param object body request.AddRegularCustomers true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/regularCustomers/add [post] func (s *RegularCustomersApi) Add(c *gin.Context) { var params request.AddRegularCustomers ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } regularCustomers := new(model.RegularCustomers) regularCustomers.Name = params.Name errCode := regularCustomersService.AddRegularCustomers(regularCustomers) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // // @Tags RegularCustomers // @Summary 删除常客 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/regularCustomers/delete/{id} [delete] func (s *RegularCustomersApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := regularCustomersService.DeleteRegularCustomers(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // // @Tags RegularCustomers // @Summary 更新常客 // @Produce application/json // @Param object body request.UpdateRegularCustomersList true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/regularCustomers/update [put] func (s *RegularCustomersApi) Update(c *gin.Context) { var params request.UpdateRegularCustomersList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := regularCustomersService.UpdateRegularCustomers(params.RegularCustomers) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // // @Tags RegularCustomers // @Summary 常客列表 // @Produce application/json // @Success 200 {object} contextx.Response{data=response.RegularCustomersResponse} // @Router /api/regularCustomers/list [get] func (s *RegularCustomersApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } regularCustomers, errCode := regularCustomersService.GetRegularCustomersList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.RegularCustomersResponse{ List: regularCustomers, }) }