This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
/
account.go
79 lines (69 loc) · 1.94 KB
/
account.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package apiv1
import (
"time"
"lockbox.dev/accounts"
)
// Account is the API representation of an Account.
// it dictates what the JSON representation of Accounts
// will be.
type Account struct {
ID string `json:"id"`
ProfileID string `json:"profileID"`
IsRegistration bool `json:"isRegistration"`
CreatedAt time.Time `json:"createdAt"`
LastSeenAt time.Time `json:"lastSeenAt,omitempty"`
LastUsedAt time.Time `json:"lastUsedAt,omitempty"`
}
// Change is the API representation of a Change.
// It dictates what the JSON representation of Changes
// will be.
type Change struct {
LastSeenAt *time.Time `json:"lastSeenAt,omitempty"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}
func coreAccount(account Account) accounts.Account {
return accounts.Account{
ID: account.ID,
ProfileID: account.ProfileID,
IsRegistration: account.IsRegistration,
Created: account.CreatedAt,
LastSeen: account.LastSeenAt,
LastUsed: account.LastUsedAt,
}
}
func coreAccounts(accts []Account) []accounts.Account {
res := make([]accounts.Account, 0, len(accts))
for _, acct := range accts {
res = append(res, coreAccount(acct))
}
return res
}
func apiAccount(account accounts.Account) Account {
return Account{
ID: account.ID,
ProfileID: account.ProfileID,
IsRegistration: account.IsRegistration,
CreatedAt: account.Created,
LastSeenAt: account.LastSeen,
LastUsedAt: account.LastUsed,
}
}
func apiAccounts(accts []accounts.Account) []Account {
res := make([]Account, 0, len(accts))
for _, acct := range accts {
res = append(res, apiAccount(acct))
}
return res
}
func coreChange(change Change) accounts.Change {
return accounts.Change{
LastSeen: change.LastSeenAt,
LastUsed: change.LastUsedAt,
}
}
func apiChange(change accounts.Change) Change {
return Change{
LastSeenAt: change.LastSeen,
LastUsedAt: change.LastUsed,
}
}