team.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. UserIdFilter int64
  58. Result SearchTeamQueryResult
  59. }
  60. type TeamDTO struct {
  61. Id int64 `json:"id"`
  62. OrgId int64 `json:"orgId"`
  63. Name string `json:"name"`
  64. Email string `json:"email"`
  65. AvatarUrl string `json:"avatarUrl"`
  66. MemberCount int64 `json:"memberCount"`
  67. }
  68. type SearchTeamQueryResult struct {
  69. TotalCount int64 `json:"totalCount"`
  70. Teams []*TeamDTO `json:"teams"`
  71. Page int `json:"page"`
  72. PerPage int `json:"perPage"`
  73. }