Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usecase/productionをrepositoryに移行する #448

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions domain/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ type UserRepository interface {
GetMyiCalSecret(info *ConInfo) (string, error)

IsPrevilege(info *ConInfo) bool
SyncUsers(info *ConInfo) error
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -69,7 +69,7 @@ func main() {
},
URL: "https://q.trap.jp/api/v3",
}
repo := &production.Repository{
repo := &repository.Repository{
GormRepo: gormRepo,
TraQRepo: traqRepo,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion usecase/production/errors.go → repository/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion usecase/production/event.go → repository/event.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"github.com/gofrs/uuid"
Expand Down
23 changes: 22 additions & 1 deletion usecase/production/group.go → repository/group.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"errors"
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"github.com/traPtitech/knoQ/infra/db"
Expand Down
2 changes: 1 addition & 1 deletion usecase/production/room.go → repository/room.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion usecase/production/tag.go → repository/tag.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"github.com/gofrs/uuid"
Expand Down
2 changes: 1 addition & 1 deletion usecase/production/user.go → repository/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package production
package repository

import (
"errors"
Expand Down
22 changes: 7 additions & 15 deletions router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
7 changes: 1 addition & 6 deletions router/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion usecase/common/common.go

This file was deleted.