account_user.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_VIEWER RoleType = "Viewer"
  13. ROLE_EDITOR RoleType = "Editor"
  14. ROLE_ADMIN RoleType = "Admin"
  15. )
  16. func (r RoleType) IsValid() bool {
  17. return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR
  18. }
  19. type AccountUser struct {
  20. AccountId int64
  21. UserId int64
  22. Role RoleType
  23. Created time.Time
  24. Updated time.Time
  25. }
  26. // ---------------------
  27. // COMMANDS
  28. type RemoveAccountUserCommand struct {
  29. UserId int64
  30. AccountId int64
  31. }
  32. type AddAccountUserCommand struct {
  33. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  34. Role RoleType `json:"role" binding:"Required"`
  35. AccountId int64 `json:"-"`
  36. UserId int64 `json:"-"`
  37. }
  38. // ----------------------
  39. // QUERIES
  40. type GetAccountUsersQuery struct {
  41. AccountId int64
  42. Result []*AccountUserDTO
  43. }
  44. // ----------------------
  45. // Projections and DTOs
  46. type AccountUserDTO struct {
  47. AccountId int64 `json:"accountId"`
  48. UserId int64 `json:"userId"`
  49. Email string `json:"email"`
  50. Login string `json:"login"`
  51. Role string `json:"role"`
  52. }