account_user.go 1.2 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. ErrLastAccountAdmin = errors.New("Cannot remove last account admin")
  10. )
  11. type RoleType string
  12. const (
  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 AccountUser struct {
  21. AccountId int64
  22. UserId int64
  23. Role RoleType
  24. Created time.Time
  25. Updated time.Time
  26. }
  27. // ---------------------
  28. // COMMANDS
  29. type RemoveAccountUserCommand struct {
  30. UserId int64
  31. AccountId int64
  32. }
  33. type AddAccountUserCommand struct {
  34. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  35. Role RoleType `json:"role" binding:"Required"`
  36. AccountId int64 `json:"-"`
  37. UserId int64 `json:"-"`
  38. }
  39. // ----------------------
  40. // QUERIES
  41. type GetAccountUsersQuery struct {
  42. AccountId int64
  43. Result []*AccountUserDTO
  44. }
  45. // ----------------------
  46. // Projections and DTOs
  47. type AccountUserDTO struct {
  48. AccountId int64 `json:"accountId"`
  49. UserId int64 `json:"userId"`
  50. Email string `json:"email"`
  51. Login string `json:"login"`
  52. Role string `json:"role"`
  53. }