Files
budget-backend/internal/account/service.go
kratisto a9bca767a9
Some checks failed
golangci-lint / lint (push) Failing after 1m20s
Test / test (push) Failing after 2m15s
chore: migrate to gitea
2026-01-27 00:40:46 +01:00

63 lines
1.5 KiB
Go

package account
import (
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/dao"
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/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 (s *Service) GetAccountWithNameForUser(name string, id string) (*Account, error) {
account, err := s.db.GetAccountWithNameForUser(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 account, nil
}
func (s *Service) CreateAccount(account Account) (*Account, error) {
err := s.db.CreateAccount(&account)
return &account, err
}
func (s *Service) DeleteAccountOfUser(userId, accountId string) error {
return s.db.DeleteAccountOfAnUser(userId, accountId)
}
func (s *Service) GetASpecificAccountForUser(userId, accountId string) (*Account, error) {
return s.db.GetASpecificAccountForUser(userId, accountId)
}
func NewService(database *Database) *Service {
return &Service{db: database}
}