Files
noscomptes-back/internal/account/service.go
2021-11-03 14:10:58 +01:00

34 lines
672 B
Go

package account
import (
"nos-comptes/internal/storage/dao"
"nos-comptes/internal/storage/model"
)
type Service struct {
db *Database
}
func (s *Service) GetAllAccountOfUser(userId string) ([]*Account, error) {
accounts, err := s.db.GetAllAccountOfUser(userId)
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
}
if accounts == nil {
return nil, &model.ErrNotFound
}
return accounts, nil
}
func NewService(database *Database) *Service {
return &Service{db: database}
}