package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type SatisfactionService struct{}
|
|
func (SatisfactionService) AddSatisfaction(satisfaction *model.Satisfaction) int {
|
err := model.NewSatisfactionSearch().Create(satisfaction)
|
if err != nil {
|
return ecode.SatisfactionExist
|
}
|
|
return ecode.OK
|
}
|
|
func (SatisfactionService) DeleteSatisfaction(id int) int {
|
_, err := model.NewSatisfactionSearch().SetId(id).Find()
|
if err != nil {
|
return ecode.SatisfactionNotExist
|
}
|
|
err = model.NewSatisfactionSearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.SatisfactionNotExist
|
}
|
return ecode.OK
|
}
|
|
func (SatisfactionService) GetSatisfactionList() ([]*model.Satisfaction, int) {
|
list, err := model.NewSatisfactionSearch().FindAll()
|
if err != nil {
|
return nil, ecode.SatisfactionListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (SatisfactionService) UpdateSatisfaction(satisfactions []*request.UpdateSatisfaction) int {
|
for _, v := range satisfactions {
|
// check satisfaction exist
|
_, err := model.NewSatisfactionSearch().SetId(v.Id).Find()
|
if err != nil {
|
return ecode.SatisfactionNotExist
|
}
|
|
err = model.NewSatisfactionSearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.SatisfactionSetErr
|
}
|
}
|
|
return ecode.OK
|
}
|