collaborator.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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) IsValid() bool {
  18. return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
  19. }
  20. type Collaborator struct {
  21. Id int64
  22. AccountId int64 `xorm:"not null unique(uix_account_id_for_account_id)"`
  23. Role RoleType `xorm:"not null"`
  24. CollaboratorId int64 `xorm:"not null unique(uix_account_id_for_account_id)"`
  25. Created time.Time
  26. Updated time.Time
  27. }
  28. // ---------------------
  29. // COMMANDS
  30. type RemoveCollaboratorCommand struct {
  31. CollaboratorId int64
  32. AccountId int64
  33. }
  34. type AddCollaboratorCommand struct {
  35. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  36. Role RoleType `json:"role" binding:"Required"`
  37. AccountId int64 `json:"-"`
  38. CollaboratorId int64 `json:"-"`
  39. }
  40. // ----------------------
  41. // QUERIES
  42. type GetCollaboratorsQuery struct {
  43. AccountId int64
  44. Result []*CollaboratorDTO
  45. }
  46. // ----------------------
  47. // Projections and DTOs
  48. type CollaboratorDTO struct {
  49. CollaboratorId int64 `json:"id"`
  50. Email string `json:"email"`
  51. Login string `json:"login"`
  52. Role string `json:"role"`
  53. }