-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.go
49 lines (42 loc) · 1.29 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package service
import (
"github.com/artem-malko/auth-and-go/infrastructure/database"
"github.com/artem-malko/auth-and-go/models"
accountRepository "github.com/artem-malko/auth-and-go/repositories/account"
"github.com/artem-malko/auth-and-go/services/account"
"github.com/google/uuid"
"github.com/pkg/errors"
)
func (s *accountService) UpdateAccountName(
executor database.QueryExecutor,
accountID uuid.UUID,
name string,
) (err error) {
err = s.accountRepository.UpdateAccountName(executor, accountID, name)
if err != nil {
switch errors.Cause(err) {
case database.ErrRepositoryNoRowsAffected:
return account.ErrNoAccountsUpdated
case accountRepository.ErrRepositoryAccountNameConstraint:
return account.ErrAccountNameExists
default:
return errors.Wrap(err, "account service: UpdateAccountName error")
}
}
return nil
}
func (s *accountService) ConfirmAccount(
executor database.QueryExecutor,
accountID uuid.UUID,
) (*models.Account, error) {
updatedAccount, err := s.accountRepository.ConfirmAccount(executor, accountID)
if err != nil {
switch errors.Cause(err) {
case database.ErrRepositoryNoRowsAffected:
return nil, account.ErrNoAccountsUpdated
default:
return nil, errors.Wrap(err, "account service: ConfirmAccount error")
}
}
return updatedAccount, err
}