team.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrTeamNotFound = errors.New("Team not found")
  9. ErrTeamNameTaken = errors.New("Team name is taken")
  10. ErrTeamMemberNotFound = errors.New("Team member not found")
  11. ErrLastTeamAdmin = errors.New("Not allowed to remove last admin")
  12. ErrNotAllowedToUpdateTeam = errors.New("User not allowed to update team")
  13. ErrNotAllowedToUpdateTeamInDifferentOrg = errors.New("User not allowed to update team in another org")
  14. )
  15. // Team model
  16. type Team struct {
  17. Id int64 `json:"id"`
  18. OrgId int64 `json:"orgId"`
  19. Name string `json:"name"`
  20. Email string `json:"email"`
  21. Created time.Time `json:"created"`
  22. Updated time.Time `json:"updated"`
  23. }
  24. // ---------------------
  25. // COMMANDS
  26. type CreateTeamCommand struct {
  27. Name string `json:"name" binding:"Required"`
  28. Email string `json:"email"`
  29. OrgId int64 `json:"-"`
  30. Result Team `json:"-"`
  31. }
  32. type UpdateTeamCommand struct {
  33. Id int64
  34. Name string
  35. Email string
  36. OrgId int64 `json:"-"`
  37. }
  38. type DeleteTeamCommand struct {
  39. OrgId int64
  40. Id int64
  41. }
  42. type GetTeamByIdQuery struct {
  43. OrgId int64
  44. Id int64
  45. Result *TeamDTO
  46. }
  47. type GetTeamsByUserQuery struct {
  48. OrgId int64
  49. UserId int64 `json:"userId"`
  50. Result []*TeamDTO `json:"teams"`
  51. }
  52. type SearchTeamsQuery struct {
  53. Query string
  54. Name string
  55. Limit int
  56. Page int
  57. OrgId int64
  58. UserIdFilter int64
  59. Result SearchTeamQueryResult
  60. }
  61. type TeamDTO struct {
  62. Id int64 `json:"id"`
  63. OrgId int64 `json:"orgId"`
  64. Name string `json:"name"`
  65. Email string `json:"email"`
  66. AvatarUrl string `json:"avatarUrl"`
  67. MemberCount int64 `json:"memberCount"`
  68. Permission PermissionType `json:"permission"`
  69. }
  70. type SearchTeamQueryResult struct {
  71. TotalCount int64 `json:"totalCount"`
  72. Teams []*TeamDTO `json:"teams"`
  73. Page int `json:"page"`
  74. PerPage int `json:"perPage"`
  75. }