forked from jsteenb2/mess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
51 lines (42 loc) · 1.73 KB
/
application.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
package service
import (
"context"
"os"
"cloud.google.com/go/firestore"
"github.com/sirupsen/logrus"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/metrics"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/adapters"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app/command"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/app/query"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour"
)
func NewApplication(ctx context.Context) app.Application {
firestoreClient, err := firestore.NewClient(ctx, os.Getenv("GCP_PROJECT"))
if err != nil {
panic(err)
}
factoryConfig := hour.FactoryConfig{
MaxWeeksInTheFutureToSet: 6,
MinUtcHour: 12,
MaxUtcHour: 20,
}
hourFactory, err := hour.NewFactory(factoryConfig)
if err != nil {
panic(err)
}
hourRepository := adapters.NewFirestoreHourRepository(firestoreClient, hourFactory)
logger := logrus.NewEntry(logrus.StandardLogger())
metricsClient := metrics.NoOp{}
return app.Application{
Commands: app.Commands{
CancelTraining: command.NewCancelTrainingHandler(hourRepository, logger, metricsClient),
ScheduleTraining: command.NewScheduleTrainingHandler(hourRepository, logger, metricsClient),
MakeHoursAvailable: command.NewMakeHoursAvailableHandler(hourRepository, logger, metricsClient),
MakeHoursUnavailable: command.NewMakeHoursUnavailableHandler(hourRepository, logger, metricsClient),
},
Queries: app.Queries{
HourAvailability: query.NewHourAvailabilityHandler(hourRepository, logger, metricsClient),
},
}
}