-
Notifications
You must be signed in to change notification settings - Fork 0
/
injector.go
63 lines (54 loc) · 1.8 KB
/
injector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"github.com/traPtitech/traPortfolio/internal/handler"
"github.com/traPtitech/traPortfolio/internal/infrastructure/external"
"github.com/traPtitech/traPortfolio/internal/infrastructure/external/mock_external_e2e"
"github.com/traPtitech/traPortfolio/internal/infrastructure/repository"
"github.com/traPtitech/traPortfolio/internal/pkgs/config"
"gorm.io/gorm"
)
func injectIntoAPIServer(c *config.Config, db *gorm.DB) (handler.API, error) {
// external API
var (
portalAPI external.PortalAPI
traQAPI external.TraQAPI
knoqAPI external.KnoqAPI
)
// TODO: 初期リリースではPortalとknoQとは連携しない
if c.IsProduction {
var err error
// portalAPI, err = external.NewPortalAPI(c.Portal)
// if err != nil {
// return handler.API{}, err
// }
portalAPI = external.NewNopPortalAPI()
traQAPI, err = external.NewTraQAPI(c.Traq)
if err != nil {
return handler.API{}, err
}
knoqAPI, err = external.NewKnoqAPI(c.Knoq)
if err != nil {
return handler.API{}, err
}
} else {
portalAPI = mock_external_e2e.NewMockPortalAPI()
traQAPI = mock_external_e2e.NewMockTraQAPI()
knoqAPI = mock_external_e2e.NewMockKnoqAPI()
}
// repository
userRepo := repository.NewUserRepository(db, portalAPI, traQAPI)
projectRepo := repository.NewProjectRepository(db, portalAPI)
eventRepo := repository.NewEventRepository(db, knoqAPI)
contestRepo := repository.NewContestRepository(db, portalAPI)
groupRepo := repository.NewGroupRepository(db)
// service, handler, API
api := handler.NewAPI(
handler.NewPingHandler(),
handler.NewUserHandler(userRepo, eventRepo),
handler.NewProjectHandler(projectRepo),
handler.NewEventHandler(eventRepo, userRepo),
handler.NewContestHandler(contestRepo),
handler.NewGroupHandler(groupRepo, userRepo),
)
return api, nil
}