-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.go
63 lines (55 loc) · 1.48 KB
/
converter.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
53
54
55
56
57
58
59
60
61
62
63
package gapi
import (
db "github.com/aradwann/eenergy/db/store"
"github.com/aradwann/eenergy/pb"
"google.golang.org/protobuf/types/known/timestamppb"
)
func convertUser(user db.User) *pb.User {
return &pb.User{
Username: user.Username,
FullName: user.FullName,
Email: user.Email,
PasswordChangedAt: timestamppb.New(user.PasswordChangedAt),
CreatedAt: timestamppb.New(user.CreatedAt),
}
}
func convertTransfer(transfer db.Transfer) *pb.Transfer {
return &pb.Transfer{
Id: transfer.ID,
FromAccountId: transfer.FromAccountID,
ToAccountId: transfer.ToAccountID,
Amount: transfer.Amount,
CreatedAt: timestamppb.New(transfer.CreatedAt),
}
}
func convertAccount(account db.Account) *pb.Account {
return &pb.Account{
Id: account.ID,
Owner: account.Owner,
Balance: account.Balance,
Unit: account.Unit,
CreatedAt: timestamppb.New(account.CreatedAt),
}
}
func convertAccounts(accounts []db.Account) []*pb.Account {
var accs []*pb.Account
for _, acc := range accounts {
accs = append(accs, convertAccount(acc))
}
return accs
}
func convertEntries(entries []db.Entry) []*pb.Entry {
var ents []*pb.Entry
for _, entry := range entries {
ents = append(ents, convertEntry(entry))
}
return ents
}
func convertEntry(entry db.Entry) *pb.Entry {
return &pb.Entry{
Id: entry.ID,
AccountId: entry.AccountID,
Amount: entry.Amount,
CreatedAt: timestamppb.New(entry.CreatedAt),
}
}