diff --git a/sam/channel.structs.go b/sam/channel.structs.go index a76bede29..6c343cc85 100644 --- a/sam/channel.structs.go +++ b/sam/channel.structs.go @@ -4,29 +4,32 @@ import ( "time" ) -// Channels -type Channel struct { - ID uint64 - Name string - Topic string +type ( + // Channels + Channel struct { + ID uint64 + Name string + Topic string + ArchivedAt *time.Time `json:",omitempty"` + DeletedAt *time.Time `json:",omitempty"` - ArchivedAt *time.Time `json:",omitempty"` - DeletedAt *time.Time `json:",omitempty"` + changed []string + } +) - changed []string -} - -func (Channel) new() *Channel { +/* Constructors */ +func (Channel) New() *Channel { return &Channel{} } +/* Getters/setters */ func (c *Channel) GetID() uint64 { return c.ID } func (c *Channel) SetID(value uint64) *Channel { if c.ID != value { - c.changed = append(c.changed, "id") + c.changed = append(c.changed, "ID") c.ID = value } return c @@ -37,7 +40,7 @@ func (c *Channel) GetName() string { func (c *Channel) SetName(value string) *Channel { if c.Name != value { - c.changed = append(c.changed, "name") + c.changed = append(c.changed, "Name") c.Name = value } return c @@ -48,8 +51,24 @@ func (c *Channel) GetTopic() string { func (c *Channel) SetTopic(value string) *Channel { if c.Topic != value { - c.changed = append(c.changed, "topic") + c.changed = append(c.changed, "Topic") c.Topic = value } return c } +func (c *Channel) GetArchivedAt() *time.Time { + return c.ArchivedAt +} + +func (c *Channel) SetArchivedAt(value *time.Time) *Channel { + c.ArchivedAt = value + return c +} +func (c *Channel) GetDeletedAt() *time.Time { + return c.DeletedAt +} + +func (c *Channel) SetDeletedAt(value *time.Time) *Channel { + c.DeletedAt = value + return c +} diff --git a/sam/message.structs.go b/sam/message.structs.go index 90b65a5c8..c60068da1 100644 --- a/sam/message.structs.go +++ b/sam/message.structs.go @@ -1,31 +1,35 @@ package sam -// Messages -type Message struct { - Service string - Channel string - UserName string - UserID uint64 - User *User - UserAvatar string - Message string - MessageID string - Type MessageType +type ( + // Messages + Message struct { + Service string + Channel string + UserName string + UserID uint64 + User *User + UserAvatar string + Message string + MessageID string + Type MessageType - changed []string -} + changed []string + } +) -func (Message) new() *Message { +/* Constructors */ +func (Message) New() *Message { return &Message{} } +/* Getters/setters */ func (m *Message) GetService() string { return m.Service } func (m *Message) SetService(value string) *Message { if m.Service != value { - m.changed = append(m.changed, "service") + m.changed = append(m.changed, "Service") m.Service = value } return m @@ -36,7 +40,7 @@ func (m *Message) GetChannel() string { func (m *Message) SetChannel(value string) *Message { if m.Channel != value { - m.changed = append(m.changed, "channel") + m.changed = append(m.changed, "Channel") m.Channel = value } return m @@ -47,7 +51,7 @@ func (m *Message) GetUserName() string { func (m *Message) SetUserName(value string) *Message { if m.UserName != value { - m.changed = append(m.changed, "username") + m.changed = append(m.changed, "UserName") m.UserName = value } return m @@ -58,7 +62,7 @@ func (m *Message) GetUserID() uint64 { func (m *Message) SetUserID(value uint64) *Message { if m.UserID != value { - m.changed = append(m.changed, "userid") + m.changed = append(m.changed, "UserID") m.UserID = value } return m @@ -68,10 +72,7 @@ func (m *Message) GetUser() *User { } func (m *Message) SetUser(value *User) *Message { - if m.User != value { - m.changed = append(m.changed, "user") - m.User = value - } + m.User = value return m } func (m *Message) GetUserAvatar() string { @@ -80,7 +81,7 @@ func (m *Message) GetUserAvatar() string { func (m *Message) SetUserAvatar(value string) *Message { if m.UserAvatar != value { - m.changed = append(m.changed, "useravatar") + m.changed = append(m.changed, "UserAvatar") m.UserAvatar = value } return m @@ -91,7 +92,7 @@ func (m *Message) GetMessage() string { func (m *Message) SetMessage(value string) *Message { if m.Message != value { - m.changed = append(m.changed, "message") + m.changed = append(m.changed, "Message") m.Message = value } return m @@ -102,7 +103,7 @@ func (m *Message) GetMessageID() string { func (m *Message) SetMessageID(value string) *Message { if m.MessageID != value { - m.changed = append(m.changed, "messageid") + m.changed = append(m.changed, "MessageID") m.MessageID = value } return m @@ -113,7 +114,7 @@ func (m *Message) GetType() MessageType { func (m *Message) SetType(value MessageType) *Message { if m.Type != value { - m.changed = append(m.changed, "type") + m.changed = append(m.changed, "Type") m.Type = value } return m diff --git a/sam/organisation.structs.go b/sam/organisation.structs.go index 370ece26b..e873ffcce 100644 --- a/sam/organisation.structs.go +++ b/sam/organisation.structs.go @@ -4,28 +4,31 @@ import ( "time" ) -// Organisations -type Organisation struct { - ID uint64 - Name string +type ( + // Organisations + Organisation struct { + ID uint64 + Name string + ArchivedAt *time.Time `json:",omitempty"` + DeletedAt *time.Time `json:",omitempty"` - ArchivedAt *time.Time - DeletedAt *time.Time + changed []string + } +) - changed []string -} - -func (Organisation) new() *Organisation { +/* Constructors */ +func (Organisation) New() *Organisation { return &Organisation{} } +/* Getters/setters */ func (o *Organisation) GetID() uint64 { return o.ID } func (o *Organisation) SetID(value uint64) *Organisation { if o.ID != value { - o.changed = append(o.changed, "id") + o.changed = append(o.changed, "ID") o.ID = value } return o @@ -36,8 +39,24 @@ func (o *Organisation) GetName() string { func (o *Organisation) SetName(value string) *Organisation { if o.Name != value { - o.changed = append(o.changed, "name") + o.changed = append(o.changed, "Name") o.Name = value } return o } +func (o *Organisation) GetArchivedAt() *time.Time { + return o.ArchivedAt +} + +func (o *Organisation) SetArchivedAt(value *time.Time) *Organisation { + o.ArchivedAt = value + return o +} +func (o *Organisation) GetDeletedAt() *time.Time { + return o.DeletedAt +} + +func (o *Organisation) SetDeletedAt(value *time.Time) *Organisation { + o.DeletedAt = value + return o +} diff --git a/sam/team.structs.go b/sam/team.structs.go index 82c209cab..202fbac62 100644 --- a/sam/team.structs.go +++ b/sam/team.structs.go @@ -4,30 +4,33 @@ import ( "time" ) -// Teams -type Team struct { - ID uint64 - Name string - MemberIDs []uint64 `json:"-"` - Members []User `json:",omitempty"` +type ( + // Teams + Team struct { + ID uint64 + Name string + MemberIDs []uint64 `json:"-"` + Members []User `json:",omitempty"` + ArchivedAt *time.Time `json:",omitempty"` + DeletedAt *time.Time `json:",omitempty"` - ArchivedAt *time.Time `json:",omitempty"` - DeletedAt *time.Time `json:",omitempty"` + changed []string + } +) - changed []string -} - -func (Team) new() *Team { +/* Constructors */ +func (Team) New() *Team { return &Team{} } +/* Getters/setters */ func (t *Team) GetID() uint64 { return t.ID } func (t *Team) SetID(value uint64) *Team { if t.ID != value { - t.changed = append(t.changed, "id") + t.changed = append(t.changed, "ID") t.ID = value } return t @@ -38,7 +41,7 @@ func (t *Team) GetName() string { func (t *Team) SetName(value string) *Team { if t.Name != value { - t.changed = append(t.changed, "name") + t.changed = append(t.changed, "Name") t.Name = value } return t @@ -59,3 +62,19 @@ func (t *Team) SetMembers(value []User) *Team { t.Members = value return t } +func (t *Team) GetArchivedAt() *time.Time { + return t.ArchivedAt +} + +func (t *Team) SetArchivedAt(value *time.Time) *Team { + t.ArchivedAt = value + return t +} +func (t *Team) GetDeletedAt() *time.Time { + return t.DeletedAt +} + +func (t *Team) SetDeletedAt(value *time.Time) *Team { + t.DeletedAt = value + return t +} diff --git a/sam/user.structs.go b/sam/user.structs.go index 7678803c9..f5cc56827 100644 --- a/sam/user.structs.go +++ b/sam/user.structs.go @@ -1,38 +1,35 @@ package sam import ( - "golang.org/x/crypto/bcrypt" "time" ) -// Users -type User struct { - ID uint64 - Username string - Password []byte `json:"-"` +type ( + // Users + User struct { + ID uint64 + Username string + Password []byte `json:"-"` + SuspendedAt *time.Time `json:",omitempty"` + DeletedAt *time.Time `json:",omitempty"` - SuspendedAt *time.Time `json:",omitempty"` - DeletedAt *time.Time `json:",omitempty"` + changed []string + } +) - changed []string -} - -func (User) new() *User { +/* Constructors */ +func (User) New() *User { return &User{} } -// Basic user validation -func (u *User) CanLogin() bool { - return u.ID > 0 -} - +/* Getters/setters */ func (u *User) GetID() uint64 { return u.ID } func (u *User) SetID(value uint64) *User { if u.ID != value { - u.changed = append(u.changed, "id") + u.changed = append(u.changed, "ID") u.ID = value } return u @@ -43,25 +40,35 @@ func (u *User) GetUsername() string { func (u *User) SetUsername(value string) *User { if u.Username != value { - u.changed = append(u.changed, "username") + u.changed = append(u.changed, "Username") u.Username = value } return u } +func (u *User) GetPassword() []byte { + return u.Password +} -func (u *User) SetPassword(value string) error { - if !u.ValidatePassword(value) { - if encrypted, err := bcrypt.GenerateFromPassword([]byte(value), bcrypt.DefaultCost); err != nil { - return err - } else { - u.Password = encrypted - u.changed = append(u.changed, "password") - } +func (u *User) SetPassword(value []byte) *User { + if u.Password != value { + u.changed = append(u.changed, "Password") + u.Password = value } - - return nil + return u +} +func (u *User) GetSuspendedAt() *time.Time { + return u.SuspendedAt } -func (u User) ValidatePassword(value string) bool { - return bcrypt.CompareHashAndPassword(u.Password, []byte(value)) == nil +func (u *User) SetSuspendedAt(value *time.Time) *User { + u.SuspendedAt = value + return u +} +func (u *User) GetDeletedAt() *time.Time { + return u.DeletedAt +} + +func (u *User) SetDeletedAt(value *time.Time) *User { + u.DeletedAt = value + return u } diff --git a/sam/user.util.go b/sam/user.util.go new file mode 100644 index 000000000..42e1734e6 --- /dev/null +++ b/sam/user.util.go @@ -0,0 +1,17 @@ +package sam + +import ( + "golang.org/x/crypto/bcrypt" +) + +func (u *User) CanLogin() bool { + return u.ID > 0 +} + +func (u *User) GeneratePassword(value string) ([]byte, error) { + return bcrypt.GenerateFromPassword([]byte(value), bcrypt.DefaultCost) +} + +func (u User) ValidatePassword(value string) bool { + return bcrypt.CompareHashAndPassword(u.Password, []byte(value)) == nil +} diff --git a/sam/websocket.structs.go b/sam/websocket.structs.go index aaa2144a2..19687fbbb 100644 --- a/sam/websocket.structs.go +++ b/sam/websocket.structs.go @@ -1,33 +1,37 @@ package sam -// Websocket -type Websocket struct { - UserID uint64 - User User +type ( + // Websocket + WebSocket struct { + UserID uint64 + User User - changed []string + changed []string + } +) + +/* Constructors */ +func (WebSocket) New() *WebSocket { + return &WebSocket{} } -func (Websocket) new() *Websocket { - return &Websocket{} -} - -func (w *Websocket) GetUserID() uint64 { +/* Getters/setters */ +func (w *WebSocket) GetUserID() uint64 { return w.UserID } -func (w *Websocket) SetUserID(value uint64) *Websocket { +func (w *WebSocket) SetUserID(value uint64) *WebSocket { if w.UserID != value { - w.changed = append(w.changed, "userid") + w.changed = append(w.changed, "UserID") w.UserID = value } return w } -func (w *Websocket) GetUser() User { +func (w *WebSocket) GetUser() User { return w.User } -func (w *Websocket) SetUser(value User) *Websocket { +func (w *WebSocket) SetUser(value User) *WebSocket { w.User = value return w }