package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/pkg/ecode"
|
"gorm.io/gorm"
|
)
|
|
type CountryService struct{}
|
|
func (CountryService) AddCountry(country *model.Country) int {
|
err := model.NewCountrySearch(nil).Create(country)
|
if err != nil {
|
return ecode.CountryExist
|
}
|
return ecode.OK
|
}
|
|
func (CountryService) DeleteCountry(id int) int {
|
_, err := model.NewCountrySearch(nil).SetId(id).First()
|
if err == gorm.ErrRecordNotFound {
|
return ecode.CountryNotExist
|
}
|
|
err = model.NewCountrySearch(nil).SetId(id).Delete()
|
if err != nil {
|
return ecode.CountryNotExist
|
}
|
return ecode.OK
|
}
|
|
func (CountryService) UpdateCountry(country *model.Country) int {
|
_, err := model.NewCountrySearch(nil).SetId(country.Id).First()
|
if err == gorm.ErrRecordNotFound {
|
return ecode.CountryNotExist
|
}
|
|
err = model.NewCountrySearch(nil).SetId(country.Id).Update(country)
|
if err != nil {
|
return ecode.CountryNotExist
|
}
|
return ecode.OK
|
}
|
|
func (CountryService) GetCountryList() ([]*model.Country, int) {
|
list, err := model.NewCountrySearch(nil).FindAll()
|
if err != nil {
|
return nil, ecode.CountryGetListErr
|
}
|
|
return list, ecode.OK
|
}
|