team.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. ErrNotAllowedToUpdateTeam = errors.New("User not allowed to update team")
  12. ErrNotAllowedToUpdateTeamInDifferentOrg = errors.New("User not allowed to update team in another org")
  13. )
  14. // Team model
  15. type Team struct {
  16. Id int64 `json:"id"`
  17. OrgId int64 `json:"orgId"`
  18. Name string `json:"name"`
  19. Email string `json:"email"`
  20. Created time.Time `json:"created"`
  21. Updated time.Time `json:"updated"`
  22. }
  23. // ---------------------
  24. // COMMANDS
  25. type CreateTeamCommand struct {
  26. Name string `json:"name" binding:"Required"`
  27. Email string `json:"email"`
  28. OrgId int64 `json:"-"`
  29. Result Team `json:"-"`
  30. }
  31. type UpdateTeamCommand struct {
  32. Id int64
  33. Name string
  34. Email string
  35. OrgId int64 `json:"-"`
  36. }
  37. type DeleteTeamCommand struct {
  38. OrgId int64
  39. Id int64
  40. }
  41. type GetTeamByIdQuery struct {
  42. OrgId int64
  43. Id int64
  44. Result *TeamDTO
  45. }
  46. type GetTeamsByUserQuery struct {
  47. OrgId int64
  48. UserId int64 `json:"userId"`
  49. Result []*TeamDTO `json:"teams"`
  50. }
  51. type SearchTeamsQuery struct {
  52. Query string
  53. Name string
  54. Limit int
  55. Page int
  56. OrgId int64
  57. Result SearchTeamQueryResult
  58. }
  59. type TeamDTO struct {
  60. Id int64 `json:"id"`
  61. OrgId int64 `json:"orgId"`
  62. Name string `json:"name"`
  63. Email string `json:"email"`
  64. AvatarUrl string `json:"avatarUrl"`
  65. MemberCount int64 `json:"memberCount"`
  66. }
  67. type SearchTeamQueryResult struct {
  68. TotalCount int64 `json:"totalCount"`
  69. Teams []*TeamDTO `json:"teams"`
  70. Page int `json:"page"`
  71. PerPage int `json:"perPage"`
  72. }