debut ajout compte joint

This commit is contained in:
2022-05-13 01:38:03 +02:00
parent cc6aa27d5d
commit 19a642b4d4
14 changed files with 785 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
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}
}