-
Notifications
You must be signed in to change notification settings - Fork 1
/
account.go
49 lines (41 loc) · 1.52 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
package account
import (
"errors"
"time"
"github.com/energietransitie/twomes-backoffice-api/twomes/building"
"github.com/energietransitie/twomes-backoffice-api/twomes/campaign"
"github.com/energietransitie/twomes-backoffice-api/twomes/cloudfeedauth"
)
var (
ErrAccountAlreadyActivated = errors.New("account is already activated")
)
// An Account is registered to a research subject.
type Account struct {
ID uint `json:"id"`
Campaign campaign.Campaign `json:"campaign"`
ActivatedAt *time.Time `json:"activated_at"`
InvitationToken string `json:"invitation_token,omitempty"`
InvitationURL string `json:"invitation_url,omitempty"`
AuthorizationToken string `json:"authorization_token,omitempty"`
Buildings []building.Building `json:"buildings,omitempty"`
CloudFeedAuths []cloudfeedauth.CloudFeedAuth `json:"cloud_feed_auths,omitempty"`
// Maybe use separate pseudonym field,
// but right now we can derive a pseudonym
// using the ID or the campaign ID + account ID.
}
// Create a new Account.
func MakeAccount(campaign campaign.Campaign) Account {
return Account{
Campaign: campaign,
}
}
// Activate an account.
// An error will be returned if the account is already activated.
func (a *Account) Activate() error {
if a.ActivatedAt != nil {
return ErrAccountAlreadyActivated
}
now := time.Now().UTC()
a.ActivatedAt = &now
return nil
}