From 7d9e46e771e3b0abd2a2362147c63e5b623531ff Mon Sep 17 00:00:00 2001 From: iChemy Date: Sun, 24 Sep 2023 14:28:04 +0900 Subject: [PATCH 1/4] :construction: add new query for get belong and admin group --- router/groups.go | 11 +++++++++++ router/presentation/query.go | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/router/groups.go b/router/groups.go index f1b9b921..d1e16f5b 100644 --- a/router/groups.go +++ b/router/groups.go @@ -129,6 +129,17 @@ 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) + } + + groupIDs = append(belongingGroupIDs, adminGroupIDs...) } return c.JSON(http.StatusOK, groupIDs) diff --git a/router/presentation/query.go b/router/presentation/query.go index 0df86dc3..badd5d45 100644 --- a/router/presentation/query.go +++ b/router/presentation/query.go @@ -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 = iota + RelationAdmins = iota + RelationBelongsOrAdmins = iota ) func GetUserRelationQuery(values url.Values) UserRelation { @@ -38,6 +39,8 @@ func GetUserRelationQuery(values url.Values) UserRelation { return RelationBelongs case "admins": return RelationAdmins + case "belongsoradmins": + return RelationBelongsOrAdmins } return RelationBelongs From 05bec269d2455d3a19124fbb24b042d20096c120 Mon Sep 17 00:00:00 2001 From: iChemy Date: Sun, 24 Sep 2023 18:36:28 +0900 Subject: [PATCH 2/4] :art: remove duplication --- router/groups.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/router/groups.go b/router/groups.go index d1e16f5b..d71224c9 100644 --- a/router/groups.go +++ b/router/groups.go @@ -139,7 +139,20 @@ func (h *Handlers) HandleGetMeGroupIDs(c echo.Context) error { return judgeErrorResponse(err) } - groupIDs = append(belongingGroupIDs, adminGroupIDs...) + uniqueIDs := make(map[uuid.UUID]struct{}) + + for _, id := range belongingGroupIDs { + uniqueIDs[id] = struct{}{} + } + + for _, id := range adminGroupIDs { + uniqueIDs[id] = struct{}{} + } + + for id := range uniqueIDs { + groupIDs = append(groupIDs, id) + } + } return c.JSON(http.StatusOK, groupIDs) From 4a6e1ee1dddd45a83967ed95b2783e412b1dd206 Mon Sep 17 00:00:00 2001 From: iChemy Date: Mon, 16 Oct 2023 14:03:23 +0900 Subject: [PATCH 3/4] :recycle: change uniqueid related program and chnage swagger --- docs/swagger.yaml | 9 +++++---- router/groups.go | 19 ++++++++----------- router/presentation/query.go | 4 ++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 24efbef4..0714911e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1200,15 +1200,16 @@ 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: diff --git a/router/groups.go b/router/groups.go index d71224c9..32caaff9 100644 --- a/router/groups.go +++ b/router/groups.go @@ -139,20 +139,17 @@ func (h *Handlers) HandleGetMeGroupIDs(c echo.Context) error { return judgeErrorResponse(err) } - uniqueIDs := make(map[uuid.UUID]struct{}) + allGroupIDs := append(belongingGroupIDs, adminGroupIDs...) + uniqueIDMap := make(map[uuid.UUID]struct{}) - for _, id := range belongingGroupIDs { - uniqueIDs[id] = struct{}{} - } - - for _, id := range adminGroupIDs { - uniqueIDs[id] = struct{}{} - } + for _, groupID := range allGroupIDs { + if _, ok := uniqueIDMap[groupID]; ok { + continue + } - for id := range uniqueIDs { - groupIDs = append(groupIDs, id) + uniqueIDMap[groupID] = struct{}{} + groupIDs = append(groupIDs, groupID) } - } return c.JSON(http.StatusOK, groupIDs) diff --git a/router/presentation/query.go b/router/presentation/query.go index badd5d45..a8256567 100644 --- a/router/presentation/query.go +++ b/router/presentation/query.go @@ -39,11 +39,11 @@ func GetUserRelationQuery(values url.Values) UserRelation { return RelationBelongs case "admins": return RelationAdmins - case "belongsoradmins": + case "belongs-or-admins": return RelationBelongsOrAdmins } - return RelationBelongs + return RelationBelongsOrAdmins } func GetExcludeEventID(values url.Values) (uuid.UUID, error) { From 2ff351e4f89c0d6e4f180c1da804ab0ea61594f4 Mon Sep 17 00:00:00 2001 From: iChemy Date: Thu, 2 Nov 2023 18:37:23 +0900 Subject: [PATCH 4/4] :recycle: fix some --- docs/swagger.yaml | 9 +++++---- router/presentation/query.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0714911e..4235f2b4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1200,10 +1200,11 @@ components: name: relation in: query required: false - description: どのような関係性でユーザーと結びつけるか。 - |取り得る値は、admins(ユーザーが管理者), belongs(ユーザーが所属している), belongs-or-admins(ユーザーが管理者または所属している) - |イベントはさらに、attendees(not absent) - |値がない場合は、belongs として振る舞う + description: | + どのような関係性でユーザーと結びつけるか。 取り得る値は、 + admins(ユーザーが管理者), belongs(ユーザーが所属している), + belongs-or-admins(ユーザーが管理者または所属している) + イベントはさらに、attendees(not absent) 値がない場合は、belongs として振る舞う schema: type: string enum: diff --git a/router/presentation/query.go b/router/presentation/query.go index a8256567..ec90f8a7 100644 --- a/router/presentation/query.go +++ b/router/presentation/query.go @@ -27,9 +27,9 @@ func GetTiemRange(values url.Values) (start time.Time, end time.Time, err error) type UserRelation int const ( - RelationBelongs = iota - RelationAdmins = iota - RelationBelongsOrAdmins = iota + RelationBelongs UserRelation = iota + RelationAdmins + RelationBelongsOrAdmins ) func GetUserRelationQuery(values url.Values) UserRelation {