-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community.go
67 lines (58 loc) · 1.44 KB
/
community.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
package model
import (
"fmt"
"time"
"github.com/neoxelox/odin/internal/class"
"github.com/neoxelox/odin/internal/utility"
"github.com/rs/xid"
)
const (
COMMUNITY_ADDRESS_MAX_LENGTH = 100
COMMUNITY_ADDRESS_MIN_LENGTH = 1
COMMUNITY_NAME_MAX_LENGTH = 100
COMMUNITY_NAME_MIN_LENGTH = 1
)
var (
COMMUNITY_DEFAULT_CATEGORIES = []string{
"Suministros",
"Desagües",
"Cerrajería",
"Ascensor",
"Estructural",
"Zonas Comunes",
"Otros",
}
)
type Community struct {
class.Model
ID string `db:"id"`
Address string `db:"address"`
Name string `db:"name"`
Categories []string `db:"categories"`
PinnedIDs []string `db:"pinned_ids"`
CreatedAt time.Time `db:"created_at"`
DeletedAt *time.Time `db:"deleted_at"`
}
func NewCommunity() *Community {
now := time.Now()
return &Community{
ID: xid.New().String(),
Categories: []string{},
PinnedIDs: []string{},
CreatedAt: now,
}
}
func (self Community) String() string {
return fmt.Sprintf("<%s: %s>", self.Name, self.ID)
}
func (self *Community) Copy() *Community {
return &Community{
ID: *utility.CopyString(&self.ID),
Address: *utility.CopyString(&self.Address),
Name: *utility.CopyString(&self.Name),
Categories: *utility.CopyStringSlice(&self.Categories),
PinnedIDs: *utility.CopyStringSlice(&self.PinnedIDs),
CreatedAt: *utility.CopyTime(&self.CreatedAt),
DeletedAt: utility.CopyTime(self.DeletedAt),
}
}