-
Notifications
You must be signed in to change notification settings - Fork 4
/
create.go
52 lines (46 loc) · 1.04 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package transferspg
import (
"context"
"fmt"
"github.com/jpgsaraceni/suricate-bank/app/domain/entities/transfer"
)
func (r Repository) Create(ctx context.Context, transferInstance transfer.Transfer) (transfer.Transfer, error) {
const query = `
INSERT INTO
transfers (
id,
account_origin_id,
account_destination_id,
amount,
created_at
)
VALUES
($1, $2, $3, $4, $5)
RETURNING
id,
account_origin_id,
account_destination_id,
amount,
created_at;
`
var transferReturned transfer.Transfer
err := r.pool.QueryRow(
ctx,
query,
transferInstance.ID,
transferInstance.AccountOriginID,
transferInstance.AccountDestinationID,
transferInstance.Amount.Cents(),
transferInstance.CreatedAt,
).Scan(
&transferReturned.ID,
&transferReturned.AccountOriginID,
&transferReturned.AccountDestinationID,
&transferReturned.Amount,
&transferReturned.CreatedAt,
)
if err != nil {
return transfer.Transfer{}, fmt.Errorf("%w: %s", ErrCreateTransfer, err.Error())
}
return transferReturned, nil
}