Skip to content

Commit

Permalink
Merge pull request #461 from traPtitech/fix/issue-400
Browse files Browse the repository at this point in the history
Fix/issue 400
  • Loading branch information
iChemy authored Nov 11, 2023
2 parents c3f263e + 2ff351e commit ecb2c44
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
10 changes: 6 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1200,15 +1200,17 @@ components:
name: relation
in: query
required: false
description: どのような関係性でユーザーと結びつけるか。|
取り得る値は、admins(ユーザーが管理者), belongs(ユーザーが所属している) |
イベントはさらに、attendees(not absent)|
値がない場合は、belongs として振る舞う
description: |
どのような関係性でユーザーと結びつけるか。 取り得る値は、
admins(ユーザーが管理者), belongs(ユーザーが所属している),
belongs-or-admins(ユーザーが管理者または所属している)
イベントはさらに、attendees(not absent) 値がない場合は、belongs として振る舞う
schema:
type: string
enum:
- admins
- belongs
- belongs-or-admins
- attendees

userID:
Expand Down
21 changes: 21 additions & 0 deletions router/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ func (h *Handlers) HandleGetMeGroupIDs(c echo.Context) error {
if err != nil {
return judgeErrorResponse(err)
}
case presentation.RelationBelongsOrAdmins:
belongingGroupIDs, err := h.Repo.GetUserBelongingGroupIDs(userID, getConinfo(c))
if err != nil {
return judgeErrorResponse(err)
}
adminGroupIDs, err := h.Repo.GetUserAdminGroupIDs(userID)
if err != nil {
return judgeErrorResponse(err)
}

allGroupIDs := append(belongingGroupIDs, adminGroupIDs...)
uniqueIDMap := make(map[uuid.UUID]struct{})

for _, groupID := range allGroupIDs {
if _, ok := uniqueIDMap[groupID]; ok {
continue
}

uniqueIDMap[groupID] = struct{}{}
groupIDs = append(groupIDs, groupID)
}
}

return c.JSON(http.StatusOK, groupIDs)
Expand Down
9 changes: 6 additions & 3 deletions router/presentation/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func GetTiemRange(values url.Values) (start time.Time, end time.Time, err error)
type UserRelation int

const (
RelationBelongs = iota
RelationAdmins = iota
RelationBelongs UserRelation = iota
RelationAdmins
RelationBelongsOrAdmins
)

func GetUserRelationQuery(values url.Values) UserRelation {
Expand All @@ -38,9 +39,11 @@ func GetUserRelationQuery(values url.Values) UserRelation {
return RelationBelongs
case "admins":
return RelationAdmins
case "belongs-or-admins":
return RelationBelongsOrAdmins
}

return RelationBelongs
return RelationBelongsOrAdmins
}

func GetExcludeEventID(values url.Values) (uuid.UUID, error) {
Expand Down

0 comments on commit ecb2c44

Please sign in to comment.