-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
membership.go
65 lines (56 loc) · 1.58 KB
/
membership.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
package model
import (
"fmt"
"time"
"github.com/neoxelox/odin/internal/class"
"github.com/neoxelox/odin/internal/utility"
"github.com/rs/xid"
)
const (
MEMBERSHIP_DOOR_MAX_LENGTH = 25
MEMBERSHIP_DOOR_MIN_LENGTH = 0
)
type Membership struct {
class.Model
ID string `db:"id"`
UserID string `db:"user_id"`
CommunityID string `db:"community_id"`
Door string `db:"door"`
Role string `db:"role"`
CreatedAt time.Time `db:"created_at"`
DeletedAt *time.Time `db:"deleted_at"`
}
var MembershipRole = struct {
ADMINISTRATOR string
PRESIDENT string
SECRETARY string
RESIDENT string
LESSEE string
Has func(role string) bool
}{"ADMINISTRATOR", "PRESIDENT", "SECRETARY", "RESIDENT", "LESSEE",
func(role string) bool {
return role == "ADMINISTRATOR" || role == "PRESIDENT" ||
role == "SECRETARY" || role == "RESIDENT" || role == "LESSEE"
},
}
func NewMembership() *Membership {
now := time.Now()
return &Membership{
ID: xid.New().String(),
CreatedAt: now,
}
}
func (self Membership) String() string {
return fmt.Sprintf("<%s <-> %s: %s>", self.UserID, self.CommunityID, self.ID)
}
func (self *Membership) Copy() *Membership {
return &Membership{
ID: *utility.CopyString(&self.ID),
UserID: *utility.CopyString(&self.UserID),
CommunityID: *utility.CopyString(&self.CommunityID),
Door: *utility.CopyString(&self.Door),
Role: *utility.CopyString(&self.Role),
CreatedAt: *utility.CopyTime(&self.CreatedAt),
DeletedAt: utility.CopyTime(self.DeletedAt),
}
}