63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package jointaccount
|
|
|
|
import (
|
|
"nos-comptes/internal/storage/dao"
|
|
"nos-comptes/internal/storage/model"
|
|
)
|
|
|
|
type Service struct {
|
|
db *Database
|
|
}
|
|
|
|
func (s *Service) GetAllJointaccountOfUser(userId string) ([]*Jointaccount, error) {
|
|
jointaccounts, err := s.db.GetAllJointaccountOfUser(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 jointaccounts == nil {
|
|
return nil, &model.ErrNotFound
|
|
}
|
|
return jointaccounts, nil
|
|
}
|
|
|
|
func (s *Service) GetJointaccountWithNameForUser(name string, id string) (*Jointaccount, error) {
|
|
jointaccount, err := s.db.GetJointaccountWithNameForUser(name, id)
|
|
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 jointaccount, nil
|
|
}
|
|
|
|
func (s *Service) CreateJointaccount(jointaccount Jointaccount) (*Jointaccount, error) {
|
|
err := s.db.CreateJointaccount(&jointaccount)
|
|
return &jointaccount, err
|
|
}
|
|
|
|
func (s *Service) DeleteJointaccountOfUser(userId, jointaccountId string) error {
|
|
return s.db.DeleteJointaccountOfAnUser(userId, jointaccountId)
|
|
}
|
|
|
|
func (s *Service) GetASpecificJointaccountForUser(userId, jointaccountId string) (*Jointaccount, error) {
|
|
return s.db.GetASpecificJointaccountForUser(userId, jointaccountId)
|
|
|
|
}
|
|
|
|
func NewService(database *Database) *Service {
|
|
return &Service{db: database}
|
|
}
|