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/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..e1034936 100644 --- a/domain/user.go +++ b/domain/user.go @@ -25,4 +25,5 @@ type UserRepository interface { GetMyiCalSecret(info *ConInfo) (string, error) IsPrevilege(info *ConInfo) bool + SyncUsers(info *ConInfo) error } diff --git a/main.go b/main.go index e970c280..5adc4829 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/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, } diff --git a/usecase/production/converter.go b/repository/converter.go similarity index 98% rename from usecase/production/converter.go rename to repository/converter.go index ab8693c3..2f7f6fb4 100644 --- a/usecase/production/converter.go +++ b/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/repository/errors.go similarity index 98% rename from usecase/production/errors.go rename to repository/errors.go index da7de6de..a740e5d2 100644 --- a/usecase/production/errors.go +++ b/repository/errors.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" diff --git a/usecase/production/event.go b/repository/event.go similarity index 99% rename from usecase/production/event.go rename to repository/event.go index 2952d823..80f033f2 100644 --- a/usecase/production/event.go +++ b/repository/event.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/gofrs/uuid" diff --git a/usecase/production/group.go b/repository/group.go similarity index 92% rename from usecase/production/group.go rename to repository/group.go index ab929f09..374870e9 100644 --- a/usecase/production/group.go +++ b/repository/group.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" @@ -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 { diff --git a/usecase/production/production.go b/repository/repository.go similarity index 91% rename from usecase/production/production.go rename to repository/repository.go index 4775d118..8ac73d46 100644 --- a/usecase/production/production.go +++ b/repository/repository.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/traPtitech/knoQ/infra/db" diff --git a/usecase/production/room.go b/repository/room.go similarity index 99% rename from usecase/production/room.go rename to repository/room.go index 862ce384..d57533de 100644 --- a/usecase/production/room.go +++ b/repository/room.go @@ -1,4 +1,4 @@ -package production +package repository import ( "time" diff --git a/usecase/production/tag.go b/repository/tag.go similarity index 96% rename from usecase/production/tag.go rename to repository/tag.go index 687afd0d..3d682b17 100644 --- a/usecase/production/tag.go +++ b/repository/tag.go @@ -1,4 +1,4 @@ -package production +package repository import ( "github.com/gofrs/uuid" diff --git a/usecase/production/user.go b/repository/user.go similarity index 99% rename from usecase/production/user.go rename to repository/user.go index b36e4ccb..83abb4c3 100644 --- a/usecase/production/user.go +++ b/repository/user.go @@ -1,4 +1,4 @@ -package production +package repository import ( "errors" 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/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