package service import ( "aps_crm/model" "aps_crm/pkg/ecode" ) type QuotationService struct{} func (QuotationService) AddQuotation(quotation *model.Quotation) int { err := model.NewQuotationSearch().Create(quotation) if err != nil { return ecode.QuotationExist } return ecode.OK } func (QuotationService) DeleteQuotation(id int) int { _, err := model.NewQuotationSearch().SetId(id).Find() if err != nil { return ecode.QuotationNotExist } err = model.NewQuotationSearch().SetId(id).Delete() if err != nil { return ecode.QuotationNotExist } return ecode.OK } func (QuotationService) GetQuotationList() ([]*model.Quotation, int) { list, err := model.NewQuotationSearch().FindAll() if err != nil { return nil, ecode.QuotationListErr } return list, ecode.OK } func (QuotationService) UpdateQuotation(quotation *model.Quotation) int { // check quotation exist _, err := model.NewQuotationSearch().SetId(quotation.Id).Find() if err != nil { return ecode.QuotationNotExist } err = model.NewQuotationSearch().SetId(quotation.Id).Update(quotation) if err != nil { return ecode.QuotationSetErr } return ecode.OK }