account.go 870 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. type CollaboratorLink struct {
  7. AccountId int
  8. Role string
  9. ModifiedOn time.Time
  10. CreatedOn time.Time
  11. }
  12. type UserAccount struct {
  13. Id int `gorethink:"id"`
  14. UserName string
  15. Login string
  16. Email string
  17. Password string
  18. NextDashboardId int
  19. UsingAccountId int
  20. Collaborators []CollaboratorLink
  21. CreatedOn time.Time
  22. ModifiedOn time.Time
  23. }
  24. func (account *UserAccount) AddCollaborator(accountId int) error {
  25. for _, collaborator := range account.Collaborators {
  26. if collaborator.AccountId == accountId {
  27. return errors.New("Collaborator already exists")
  28. }
  29. }
  30. account.Collaborators = append(account.Collaborators, CollaboratorLink{
  31. AccountId: accountId,
  32. Role: "admin",
  33. CreatedOn: time.Now(),
  34. ModifiedOn: time.Now(),
  35. })
  36. return nil
  37. }