-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
56 lines (43 loc) · 1.22 KB
/
organization.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
package domain
import (
"github.com/haleyrc/cheevos/internal/lib/stringutil"
)
// Organization represents a group of users belonging to a related parent
// entity. This may be an actual organization or simply a group of friends who
// want to recognize each other for significant events. An organization also
// acts as a boundary for managing cheevos, since every cheevo is "owned" by an
// organization and can only be granted to members of that organization.
type Organization struct {
// A unique identifier for the organization.
ID string
// The name of the organization.
Name string
OwnerID string
}
func (o *Organization) Model() string { return "Organization" }
func (o *Organization) Normalize() {
o.Name = stringutil.MakeSafe(o.Name)
}
func (o *Organization) Validate() error {
o.Normalize()
var fes []FieldError
if o.ID == "" {
fes = append(fes, FieldError{
Field: "ID", Msg: "ID can't be blank.",
})
}
if o.Name == "" {
fes = append(fes, FieldError{
Field: "Name", Msg: "Name can't be blank.",
})
}
if o.OwnerID == "" {
fes = append(fes, FieldError{
Field: "OwnerID", Msg: "Owner ID can't be blank.",
})
}
if len(fes) > 0 {
return NewValidationError("Organization", fes)
}
return nil
}