package service import ( "aps_crm/model" "aps_crm/model/request" "aps_crm/pkg/ecode" ) type IndustryService struct{} func (IndustryService) AddIndustry(industry *model.Industry) int { err := model.NewIndustrySearch().Create(industry) if err != nil { return ecode.IndustryExist } return ecode.OK } func (IndustryService) DeleteIndustry(id int) int { _, err := model.NewIndustrySearch().SetId(id).Find() if err != nil { return ecode.IndustryNotExist } err = model.NewIndustrySearch().SetId(id).Delete() if err != nil { return ecode.IndustryNotExist } return ecode.OK } func (IndustryService) GetIndustryList() ([]*model.Industry, int) { list, err := model.NewIndustrySearch().FindAll() if err != nil { return nil, ecode.IndustryListErr } return list, ecode.OK } func (IndustryService) UpdateIndustry(industries []*request.UpdateIndustry) int { for _, v := range industries { // check industry exist _, err := model.NewIndustrySearch().SetId(v.Id).Find() if err != nil { return ecode.IndustryNotExist } err = model.NewIndustrySearch().SetId(v.Id).Updates(map[string]interface{}{ "name": v.Name, }) if err != nil { return ecode.IndustrySetErr } } return ecode.OK }