make service handling of non-error-not-founds explicit

This commit is contained in:
ari melody 2026-07-31 10:40:50 +01:00
parent 6eb204bfce
commit 32bcb894ee
Signed by: ari
GPG key ID: CF99829C92678188
2 changed files with 24 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"arimelody-web/model"
repository "arimelody-web/repository/account"
"errors"
"fmt"
"log"
)
@ -28,15 +29,33 @@ func (s *AccountService) GetCount() (int, error) {
}
func (s *AccountService) GetByID(id string) (*model.Account, error) {
return s.repo.GetByID(id)
if account, err := s.repo.GetByID(id); err != nil {
return nil, err
} else if account == nil {
return nil, fmt.Errorf("Account does not exist: %s", id)
} else {
return account, nil
}
}
func (s *AccountService) GetByUsername(username string) (*model.Account, error) {
return s.repo.GetByUsername(username)
if account, err := s.repo.GetByUsername(username); err != nil {
return nil, err
} else if account == nil {
return nil, fmt.Errorf("Account does not exist: %s", username)
} else {
return account, nil
}
}
func (s *AccountService) GetByEmail(email string) (*model.Account, error) {
return s.repo.GetByEmail(email)
if account, err := s.repo.GetByEmail(email); err != nil {
return nil, err
} else if account == nil {
return nil, fmt.Errorf("Account does not exist with email: %s", email)
} else {
return account, nil
}
}
func (s *AccountService) Create(