2017-03-27 20:36:28 +08:00
|
|
|
package models
|
|
|
|
|
2017-04-09 06:55:07 +08:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Typed errors
|
|
|
|
var (
|
2019-03-08 22:46:15 +08:00
|
|
|
ErrTeamNotFound = errors.New("Team not found")
|
|
|
|
ErrTeamNameTaken = errors.New("Team name is taken")
|
|
|
|
ErrTeamMemberNotFound = errors.New("Team member not found")
|
2019-03-12 23:59:39 +08:00
|
|
|
ErrLastTeamAdmin = errors.New("Not allowed to remove last admin")
|
2019-03-08 22:46:15 +08:00
|
|
|
ErrNotAllowedToUpdateTeam = errors.New("User not allowed to update team")
|
|
|
|
ErrNotAllowedToUpdateTeamInDifferentOrg = errors.New("User not allowed to update team in another org")
|
2017-04-09 06:55:07 +08:00
|
|
|
)
|
2017-03-27 20:36:28 +08:00
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
// Team model
|
|
|
|
type Team struct {
|
2017-04-10 07:24:16 +08:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
Name string `json:"name"`
|
2017-12-21 04:20:12 +08:00
|
|
|
Email string `json:"email"`
|
2017-03-27 20:36:28 +08:00
|
|
|
|
2017-04-10 07:24:16 +08:00
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Updated time.Time `json:"updated"`
|
2017-03-27 20:36:28 +08:00
|
|
|
}
|
2017-04-09 06:55:07 +08:00
|
|
|
|
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type CreateTeamCommand struct {
|
2017-04-09 06:55:07 +08:00
|
|
|
Name string `json:"name" binding:"Required"`
|
2017-12-21 04:20:12 +08:00
|
|
|
Email string `json:"email"`
|
2017-04-10 07:24:16 +08:00
|
|
|
OrgId int64 `json:"-"`
|
2017-04-09 06:55:07 +08:00
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
Result Team `json:"-"`
|
2017-04-09 06:55:07 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type UpdateTeamCommand struct {
|
2017-12-21 04:20:12 +08:00
|
|
|
Id int64
|
|
|
|
Name string
|
|
|
|
Email string
|
2018-02-10 00:26:15 +08:00
|
|
|
OrgId int64 `json:"-"`
|
2017-04-18 21:01:05 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type DeleteTeamCommand struct {
|
2018-02-10 00:26:15 +08:00
|
|
|
OrgId int64
|
|
|
|
Id int64
|
2017-04-09 06:55:07 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type GetTeamByIdQuery struct {
|
2018-02-10 00:26:15 +08:00
|
|
|
OrgId int64
|
2017-04-09 06:55:07 +08:00
|
|
|
Id int64
|
2018-07-12 02:23:07 +08:00
|
|
|
Result *TeamDTO
|
2017-04-09 06:55:07 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type GetTeamsByUserQuery struct {
|
2018-02-10 00:26:15 +08:00
|
|
|
OrgId int64
|
2018-07-12 02:23:07 +08:00
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
Result []*TeamDTO `json:"teams"`
|
2017-05-22 16:33:17 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type SearchTeamsQuery struct {
|
2019-03-11 21:40:57 +08:00
|
|
|
Query string
|
|
|
|
Name string
|
|
|
|
Limit int
|
|
|
|
Page int
|
|
|
|
OrgId int64
|
|
|
|
UserIdFilter int64
|
2017-04-09 06:55:07 +08:00
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
Result SearchTeamQueryResult
|
2017-04-10 07:24:16 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 02:23:07 +08:00
|
|
|
type TeamDTO struct {
|
2019-03-14 21:24:13 +08:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
MemberCount int64 `json:"memberCount"`
|
|
|
|
Permission PermissionType `json:"permission"`
|
2017-12-15 00:22:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-08 23:25:45 +08:00
|
|
|
type SearchTeamQueryResult struct {
|
2018-07-12 02:23:07 +08:00
|
|
|
TotalCount int64 `json:"totalCount"`
|
|
|
|
Teams []*TeamDTO `json:"teams"`
|
|
|
|
Page int `json:"page"`
|
|
|
|
PerPage int `json:"perPage"`
|
2017-04-09 06:55:07 +08:00
|
|
|
}
|