3
0

regenerate everything from spec

This commit is contained in:
Tit Petric 2018-07-06 10:19:05 +00:00
parent 0a5179edfb
commit 788de33607
7 changed files with 197 additions and 111 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

17
sam/user.util.go Normal file
View File

@ -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
}

View File

@ -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
}