Working on collaborators

This commit is contained in:
Torkel Ödegaard
2014-09-19 17:37:18 +02:00
parent 1705734435
commit a9a06ad51d
11 changed files with 174 additions and 98 deletions
+43
View File
@@ -0,0 +1,43 @@
package models
import (
"errors"
"time"
)
type CollaboratorLink struct {
AccountId int
Role string
ModifiedOn time.Time
CreatedOn time.Time
}
type UserAccount struct {
Id int `gorethink:"id"`
UserName string
Login string
Email string
Password string
NextDashboardId int
UsingAccountId int
Collaborators []CollaboratorLink
CreatedOn time.Time
ModifiedOn time.Time
}
func (account *UserAccount) AddCollaborator(accountId int) error {
for _, collaborator := range account.Collaborators {
if collaborator.AccountId == accountId {
return errors.New("Collaborator already exists")
}
}
account.Collaborators = append(account.Collaborators, CollaboratorLink{
AccountId: accountId,
Role: "admin",
CreatedOn: time.Now(),
ModifiedOn: time.Now(),
})
return nil
}
-34
View File
@@ -21,31 +21,6 @@ type Dashboard struct {
Data map[string]interface{}
}
type CollaboratorLink struct {
AccountId int
Role string
ModifiedOn time.Time
CreatedOn time.Time
}
type UserAccount struct {
Id int `gorethink:"id"`
UserName string
Login string
Email string
Password string
NextDashboardId int
UsingAccountId int
Collaborators []CollaboratorLink
CreatedOn time.Time
ModifiedOn time.Time
}
type UserContext struct {
UserId string
AccountId string
}
type SearchResult struct {
Id string `json:"id"`
Title string `json:"title"`
@@ -87,12 +62,3 @@ func (dash *Dashboard) UpdateSlug() {
re2 := regexp.MustCompile("\\s")
dash.Slug = re2.ReplaceAllString(re.ReplaceAllString(title, ""), "-")
}
func (account *UserAccount) AddCollaborator(accountId int) {
account.Collaborators = append(account.Collaborators, CollaboratorLink{
AccountId: accountId,
Role: "admin",
CreatedOn: time.Now(),
ModifiedOn: time.Now(),
})
}