fix(account): add account creante and fix incorrect field for getting all
This commit is contained in:
@@ -12,7 +12,6 @@ type Service struct {
|
||||
|
||||
func (s *Service) GetAllAccountOfUser(userId string) ([]*Account, error) {
|
||||
accounts, err := s.db.GetAllAccountOfUser(userId)
|
||||
utils.GetLogger().Warn(err)
|
||||
if e, ok := err.(*dao.Error); ok {
|
||||
switch {
|
||||
case e.Type == dao.ErrTypeNotFound:
|
||||
@@ -30,6 +29,27 @@ func (s *Service) GetAllAccountOfUser(userId string) ([]*Account, error) {
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetAccountWithNameForUser(name string, id string) (*Account, error) {
|
||||
account, err := s.db.GetAccountWithNameForUser(name, id)
|
||||
utils.GetLogger().Warn(err)
|
||||
if e, ok := err.(*dao.Error); ok {
|
||||
switch {
|
||||
case e.Type == dao.ErrTypeNotFound:
|
||||
return nil, &model.ErrNotFound
|
||||
default:
|
||||
return nil, &model.ErrInternalServer
|
||||
}
|
||||
} else if err != nil {
|
||||
return nil, &model.ErrInternalServer
|
||||
}
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (s *Service) CreateAccount(account Account) (*Account, error) {
|
||||
err := s.db.CreateAccount(&account)
|
||||
return &account, err
|
||||
}
|
||||
|
||||
func NewService(database *Database) *Service {
|
||||
return &Service{db: database}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user