From 681bad18d2e0628f63a57b7f94bb4ea2ae7a5003 Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 21:34:09 +0900 Subject: [PATCH 1/7] :fire: remove dependance to usecase/production --- domain/group.go | 1 + domain/user.go | 5 ++++- router/middleware.go | 22 +++++++--------------- router/users.go | 7 +------ usecase/production/group.go | 21 +++++++++++++++++++++ 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/domain/group.go b/domain/group.go index 19e8b1db..6a082a6b 100644 --- a/domain/group.go +++ b/domain/group.go @@ -36,6 +36,7 @@ type GroupRepository interface { GetUserBelongingGroupIDs(userID uuid.UUID, info *ConInfo) ([]uuid.UUID, error) GetUserAdminGroupIDs(userID uuid.UUID) ([]uuid.UUID, error) IsGroupAdmins(groupID uuid.UUID, info *ConInfo) bool + GetGradeGroupNames(info *ConInfo) ([]string, error) } func (g *Group) AdminsValidation() bool { diff --git a/domain/user.go b/domain/user.go index 55c70803..cceb9d00 100644 --- a/domain/user.go +++ b/domain/user.go @@ -1,6 +1,8 @@ package domain -import "github.com/gofrs/uuid" +import ( + "github.com/gofrs/uuid" +) type User struct { ID uuid.UUID @@ -25,4 +27,5 @@ type UserRepository interface { GetMyiCalSecret(info *ConInfo) (string, error) IsPrevilege(info *ConInfo) bool + SyncUsers(info *ConInfo) error } diff --git a/router/middleware.go b/router/middleware.go index d23bb8e1..d040017e 100644 --- a/router/middleware.go +++ b/router/middleware.go @@ -10,7 +10,6 @@ import ( "github.com/traPtitech/knoQ/domain" log "github.com/traPtitech/knoQ/logging" "github.com/traPtitech/knoQ/presentation" - "github.com/traPtitech/knoQ/usecase/production" "github.com/traPtitech/knoQ/utils" "github.com/gofrs/uuid" @@ -194,7 +193,7 @@ func (h *Handlers) WebhookEventHandler(c echo.Context, reqBody, resBody []byte) return } usersMap := createUserMap(users) - nofiticationTargets := make([]string, 0) + notificationTargets := make([]string, 0) if e.TimeEnd.Before(time.Now()) { return @@ -203,32 +202,25 @@ func (h *Handlers) WebhookEventHandler(c echo.Context, reqBody, resBody []byte) // TODO fix: IDを環境変数などで定義すべき traPGroupID := uuid.Must(uuid.FromString("11111111-1111-1111-1111-111111111111")) if e.Group.ID == traPGroupID { - repo, ok := h.Repo.(*production.Repository) - if !ok { - return - } - t, err := repo.GormRepo.GetToken(getConinfo(c).ReqUserID) + groups, err := h.Repo.GetGradeGroupNames(getConinfo(c)) if err != nil { + h.Logger.Error("failed to get groups", zap.Error(err)) return } - groups, _ := repo.TraQRepo.GetAllGroups(t) - for _, g := range groups { - if g.Type == "grade" { - nofiticationTargets = append(nofiticationTargets, g.Name) - } - } + + notificationTargets = append(notificationTargets, groups...) } else { for _, attendee := range e.Attendees { if attendee.Schedule == presentation.Pending { user, ok := usersMap[attendee.ID] if ok { - nofiticationTargets = append(nofiticationTargets, user.Name) + notificationTargets = append(notificationTargets, user.Name) } } } } - content := presentation.GenerateEventWebhookContent(c.Request().Method, e, nofiticationTargets, h.Origin, !domain.DEVELOPMENT) + content := presentation.GenerateEventWebhookContent(c.Request().Method, e, notificationTargets, h.Origin, !domain.DEVELOPMENT) _ = utils.RequestWebhook(content, h.WebhookSecret, h.ActivityChannelID, h.WebhookID, 1) } diff --git a/router/users.go b/router/users.go index d4357a7c..930fe6a4 100644 --- a/router/users.go +++ b/router/users.go @@ -7,7 +7,6 @@ import ( "github.com/traPtitech/knoQ/domain" "github.com/traPtitech/knoQ/presentation" - "github.com/traPtitech/knoQ/usecase/production" "github.com/labstack/echo/v4" ) @@ -68,11 +67,7 @@ func (h *Handlers) HandleUpdateiCal(c echo.Context) error { // 停止されているユーザーの`token`を削除して、 // 活動中のユーザーを追加する(userIDをDBに保存) func (h *Handlers) HandleSyncUser(c echo.Context) error { - repo, ok := h.Repo.(*production.Repository) - if !ok { - return internalServerError(errors.New("not implemented")) - } - err := repo.SyncUsers(getConinfo(c)) + err := h.Repo.SyncUsers(getConinfo(c)) if err != nil { return judgeErrorResponse(err) } diff --git a/usecase/production/group.go b/usecase/production/group.go index ab929f09..382ec48e 100644 --- a/usecase/production/group.go +++ b/usecase/production/group.go @@ -194,6 +194,27 @@ func (repo *Repository) getTraPGroup(info *domain.ConInfo) *domain.Group { } } +func (repo *Repository) GetGradeGroupNames(info *domain.ConInfo) ([]string, error) { + t, err := repo.GormRepo.GetToken(info.ReqUserID) + if err != nil { + return nil, defaultErrorHandling(err) + } + + groups, err := repo.TraQRepo.GetAllGroups(t) + if err != nil { + return nil, defaultErrorHandling(err) + } + + names := make([]string, 0) + for _, g := range groups { + if g.Type == "grade" { + names = append(names, g.Name) + } + } + + return names, nil +} + func convSPdomainUserToSdomainUser(src []*domain.User) (dst []domain.User) { dst = make([]domain.User, len(src)) for i := range src { From 228a749eb0aae0b55f160963fbc6ba898c5afa85 Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 21:37:33 +0900 Subject: [PATCH 2/7] :fire: usecase/common --- usecase/common/common.go | 1 - 1 file changed, 1 deletion(-) delete mode 100644 usecase/common/common.go diff --git a/usecase/common/common.go b/usecase/common/common.go deleted file mode 100644 index 805d0c79..00000000 --- a/usecase/common/common.go +++ /dev/null @@ -1 +0,0 @@ -package common From a32355ca0f2b4321d828feb73f39c43d94687b9d Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 21:44:36 +0900 Subject: [PATCH 3/7] :fire: move usecase/production to infra/repository --- {usecase/production => infra/repository}/converter.go | 2 +- {usecase/production => infra/repository}/errors.go | 2 +- {usecase/production => infra/repository}/event.go | 2 +- {usecase/production => infra/repository}/group.go | 2 +- {usecase/production => infra/repository}/production.go | 2 +- {usecase/production => infra/repository}/room.go | 2 +- {usecase/production => infra/repository}/tag.go | 2 +- {usecase/production => infra/repository}/user.go | 2 +- main.go | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) rename {usecase/production => infra/repository}/converter.go (98%) rename {usecase/production => infra/repository}/errors.go (98%) rename {usecase/production => infra/repository}/event.go (99%) rename {usecase/production => infra/repository}/group.go (99%) rename {usecase/production => infra/repository}/production.go (91%) rename {usecase/production => infra/repository}/room.go (99%) rename {usecase/production => infra/repository}/tag.go (96%) rename {usecase/production => infra/repository}/user.go (99%) diff --git a/usecase/production/converter.go b/infra/repository/converter.go similarity index 98% rename from usecase/production/converter.go rename to infra/repository/converter.go index ab8693c3..2f7f6fb4 100644 --- a/usecase/production/converter.go +++ b/infra/repository/converter.go @@ -1,6 +1,6 @@ // FIXME: ↓が動かないので一時的に手動で作成 // //go:generate go run github.com/fuji8/gotypeconverter/cmd/gotypeconverter@latest -s []*traq.UserGroup -d []*domain.Group -o converter.go . -package production +package repository import ( "github.com/gofrs/uuid" diff --git a/usecase/production/errors.go b/infra/repository/errors.go similarity index 98% rename from usecase/production/errors.go rename to infra/repository/errors.go index da7de6de..a740e5d2 100644 --- a/usecase/production/errors.go +++ b/infra/repository/errors.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" diff --git a/usecase/production/event.go b/infra/repository/event.go similarity index 99% rename from usecase/production/event.go rename to infra/repository/event.go index 2952d823..80f033f2 100644 --- a/usecase/production/event.go +++ b/infra/repository/event.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/gofrs/uuid" diff --git a/usecase/production/group.go b/infra/repository/group.go similarity index 99% rename from usecase/production/group.go rename to infra/repository/group.go index 382ec48e..374870e9 100644 --- a/usecase/production/group.go +++ b/infra/repository/group.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" diff --git a/usecase/production/production.go b/infra/repository/production.go similarity index 91% rename from usecase/production/production.go rename to infra/repository/production.go index 4775d118..8ac73d46 100644 --- a/usecase/production/production.go +++ b/infra/repository/production.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/traPtitech/knoQ/infra/db" diff --git a/usecase/production/room.go b/infra/repository/room.go similarity index 99% rename from usecase/production/room.go rename to infra/repository/room.go index 862ce384..d57533de 100644 --- a/usecase/production/room.go +++ b/infra/repository/room.go @@ -1,4 +1,4 @@ -package production +package repository import ( "time" diff --git a/usecase/production/tag.go b/infra/repository/tag.go similarity index 96% rename from usecase/production/tag.go rename to infra/repository/tag.go index 687afd0d..3d682b17 100644 --- a/usecase/production/tag.go +++ b/infra/repository/tag.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/gofrs/uuid" diff --git a/usecase/production/user.go b/infra/repository/user.go similarity index 99% rename from usecase/production/user.go rename to infra/repository/user.go index b36e4ccb..83abb4c3 100644 --- a/usecase/production/user.go +++ b/infra/repository/user.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" diff --git a/main.go b/main.go index e970c280..97127f0d 100644 --- a/main.go +++ b/main.go @@ -10,8 +10,8 @@ import ( "github.com/traPtitech/knoQ/domain" "github.com/traPtitech/knoQ/infra/db" + "github.com/traPtitech/knoQ/infra/repository" "github.com/traPtitech/knoQ/infra/traq" - "github.com/traPtitech/knoQ/usecase/production" "github.com/traPtitech/knoQ/utils" "golang.org/x/oauth2" @@ -69,7 +69,7 @@ func main() { }, URL: "https://q.trap.jp/api/v3", } - repo := &production.Repository{ + repo := &repository.Repository{ GormRepo: gormRepo, TraQRepo: traqRepo, } From aaedbd7066b05c29c80205838b7974e70e7ddf3b Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 21:52:58 +0900 Subject: [PATCH 4/7] :recycle: rename to repository.go --- infra/repository/{production.go => repository.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename infra/repository/{production.go => repository.go} (100%) diff --git a/infra/repository/production.go b/infra/repository/repository.go similarity index 100% rename from infra/repository/production.go rename to infra/repository/repository.go From a7a17307562b9f36a625a08df1ed756b882d5492 Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 22:02:06 +0900 Subject: [PATCH 5/7] :recycle: move to /repository --- docker-compose.yml | 2 +- {infra/repository => repository}/converter.go | 0 {infra/repository => repository}/errors.go | 0 {infra/repository => repository}/event.go | 0 {infra/repository => repository}/group.go | 0 {infra/repository => repository}/repository.go | 0 {infra/repository => repository}/room.go | 0 {infra/repository => repository}/tag.go | 0 {infra/repository => repository}/user.go | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename {infra/repository => repository}/converter.go (100%) rename {infra/repository => repository}/errors.go (100%) rename {infra/repository => repository}/event.go (100%) rename {infra/repository => repository}/group.go (100%) rename {infra/repository => repository}/repository.go (100%) rename {infra/repository => repository}/room.go (100%) rename {infra/repository => repository}/tag.go (100%) rename {infra/repository => repository}/user.go (100%) diff --git a/docker-compose.yml b/docker-compose.yml index 9aea2c6f..0a77dd9d 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,7 +38,7 @@ services: - ./domain:/srv/knoq/domain - ./infra:/srv/knoq/infra - ./presentation:/srv/knoq/presentation - - ./usecase:/srv/knoq/usecase + - ./repository:/srv/knoq/repository - ./parsing:/srv/knoq/parsing ports: - "6006:3000" diff --git a/infra/repository/converter.go b/repository/converter.go similarity index 100% rename from infra/repository/converter.go rename to repository/converter.go diff --git a/infra/repository/errors.go b/repository/errors.go similarity index 100% rename from infra/repository/errors.go rename to repository/errors.go diff --git a/infra/repository/event.go b/repository/event.go similarity index 100% rename from infra/repository/event.go rename to repository/event.go diff --git a/infra/repository/group.go b/repository/group.go similarity index 100% rename from infra/repository/group.go rename to repository/group.go diff --git a/infra/repository/repository.go b/repository/repository.go similarity index 100% rename from infra/repository/repository.go rename to repository/repository.go diff --git a/infra/repository/room.go b/repository/room.go similarity index 100% rename from infra/repository/room.go rename to repository/room.go diff --git a/infra/repository/tag.go b/repository/tag.go similarity index 100% rename from infra/repository/tag.go rename to repository/tag.go diff --git a/infra/repository/user.go b/repository/user.go similarity index 100% rename from infra/repository/user.go rename to repository/user.go From dbcc2d7f7b7bf386a598a82315b367eebac41620 Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 22:03:17 +0900 Subject: [PATCH 6/7] :bug: fix compile --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 97127f0d..5adc4829 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "github.com/traPtitech/knoQ/domain" "github.com/traPtitech/knoQ/infra/db" - "github.com/traPtitech/knoQ/infra/repository" + "github.com/traPtitech/knoQ/repository" "github.com/traPtitech/knoQ/infra/traq" "github.com/traPtitech/knoQ/utils" "golang.org/x/oauth2" From b5a11e6da5e449719f31c050073858627289d81e Mon Sep 17 00:00:00 2001 From: ras0q Date: Mon, 28 Aug 2023 22:24:15 +0900 Subject: [PATCH 7/7] :art: import format --- domain/user.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/domain/user.go b/domain/user.go index cceb9d00..e1034936 100644 --- a/domain/user.go +++ b/domain/user.go @@ -1,8 +1,6 @@ package domain -import ( - "github.com/gofrs/uuid" -) +import "github.com/gofrs/uuid" type User struct { ID uuid.UUID