collaborator.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrInvalidRoleType = errors.New("Invalid role type")
  9. )
  10. type RoleType string
  11. const (
  12. ROLE_OWNER RoleType = "Owner"
  13. ROLE_VIEWER RoleType = "Viewer"
  14. ROLE_EDITOR RoleType = "Editor"
  15. ROLE_ADMIN RoleType = "Admin"
  16. )
  17. func (r RoleType) Validate() error {
  18. if r == ROLE_OWNER || r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR {
  19. return nil
  20. }
  21. return ErrInvalidRoleType
  22. }
  23. type Collaborator struct {
  24. Id int64
  25. AccountId int64 `xorm:"not null unique(uix_account_id_for_account_id)"`
  26. Role RoleType `xorm:"not null"`
  27. CollaboratorId int64 `xorm:"not null unique(uix_account_id_for_account_id)"`
  28. Created time.Time
  29. Updated time.Time
  30. }
  31. // ---------------------
  32. // COMMANDS
  33. type RemoveCollaboratorCommand struct {
  34. CollaboratorId int64
  35. AccountId int64
  36. }
  37. type AddCollaboratorCommand struct {
  38. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  39. Role RoleType `json:"role" binding:"Required"`
  40. AccountId int64 `json:"-"`
  41. CollaboratorId int64 `json:"-"`
  42. }
  43. // ----------------------
  44. // QUERIES
  45. type GetCollaboratorsQuery struct {
  46. AccountId int64
  47. Result []*CollaboratorDTO
  48. }
  49. // ----------------------
  50. // Projections and DTOs
  51. type CollaboratorDTO struct {
  52. CollaboratorId int64 `json:"id"`
  53. Email string `json:"email"`
  54. Login string `json:"login"`
  55. Role string `json:"role"`
  56. }