-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
36 lines (32 loc) · 1.13 KB
/
create.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
package usecase
import (
"context"
"errors"
"github.com/patriciapedrosaa/transfer-me/app/domain/entities"
"github.com/patriciapedrosaa/transfer-me/app/domain/transfer"
)
var (
ErrUnexpected = errors.New("something went wrong")
)
func (t Transfer) Create(ctx context.Context, input transfer.CreateTransferInput) (entities.Transfer, error) {
log := t.logger.With().
Str("account_ID", input.OriginAccount.AccountID).
Str("account_ID", input.DestinationAccount.AccountID).
Int("amount", input.Amount).
Logger()
log.Info().Msg("creating transfer.")
newTransfer, err := entities.NewTransfer(input.OriginAccount, input.DestinationAccount, input.Amount)
if err != nil {
log.Error().Err(err).Msg("error occurred when was trying to create transfer")
return entities.Transfer{}, err
}
err = t.transferRepository.CreateTransfer(ctx, newTransfer, input.OriginAccount.AccountID)
if err != nil {
log.Error().Err(err).Msg("error occurred when was trying to create transfer")
return entities.Transfer{}, ErrUnexpected
}
log.Info().
Str("transfer_ID", newTransfer.TransferID).
Msg("transfer created with success!")
return newTransfer, nil
}