|
package service
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/pkg/ecode"
|
)
|
|
type CurrencyService struct{}
|
|
func (CurrencyService) AddCurrency(currency *model.Currency) int {
|
err := model.NewCurrencySearch().Create(currency)
|
if err != nil {
|
return ecode.CurrencyExist
|
}
|
|
return ecode.OK
|
}
|
|
func (CurrencyService) DeleteCurrency(id int) int {
|
_, err := model.NewCurrencySearch().SetId(id).Find()
|
if err != nil {
|
return ecode.CurrencyNotExist
|
}
|
|
err = model.NewCurrencySearch().SetId(id).Delete()
|
if err != nil {
|
return ecode.CurrencyNotExist
|
}
|
return ecode.OK
|
}
|
|
func (CurrencyService) GetCurrencyList() ([]*model.Currency, int) {
|
list, err := model.NewCurrencySearch().FindAll()
|
if err != nil {
|
return nil, ecode.CurrencyListErr
|
}
|
|
return list, ecode.OK
|
}
|
|
func (CurrencyService) UpdateCurrency(currencys []*request.UpdateCurrency) int {
|
for _, v := range currencys {
|
// check currency exist
|
_, err := model.NewCurrencySearch().SetId(v.Id).Find()
|
if err != nil {
|
return ecode.CurrencyNotExist
|
}
|
|
err = model.NewCurrencySearch().SetId(v.Id).Updates(map[string]interface{}{
|
"name": v.Name,
|
})
|
if err != nil {
|
return ecode.CurrencySetErr
|
}
|
}
|
|
return ecode.OK
|
}
|
|
func (CurrencyService) GetCurrencyDetail(id int) (*model.Currency, int) {
|
currency, err := model.NewCurrencySearch().SetId(id).Find()
|
if err != nil {
|
return nil, ecode.CurrencyNotExist
|
}
|
|
return currency, ecode.OK
|
}
|