forked from jsteenb2/mess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hour_availability.go
60 lines (48 loc) · 1.19 KB
/
hour_availability.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
package query
import (
"context"
"time"
"github.com/sirupsen/logrus"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/decorator"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour"
)
type (
Date struct {
Date time.Time
HasFreeHours bool
Hours []Hour
}
Hour struct {
Available bool
HasTrainingScheduled bool
Hour time.Time
}
HourAvailability struct {
Hour time.Time
}
)
type HourAvailabilityHandler decorator.QueryHandler[HourAvailability, bool]
type hourAvailabilityHandler struct {
hourRepo hour.Repository
}
func NewHourAvailabilityHandler(
hourRepo hour.Repository,
logger *logrus.Entry,
metricsClient decorator.MetricsClient,
) HourAvailabilityHandler {
if hourRepo == nil {
panic("nil hourRepo")
}
return decorator.ApplyQueryDecorators[HourAvailability, bool](
hourAvailabilityHandler{hourRepo: hourRepo},
logger,
metricsClient,
)
}
func (h hourAvailabilityHandler) Handle(ctx context.Context, query HourAvailability) (bool, error) {
hour, err := h.hourRepo.GetHour(ctx, query.Hour)
if err != nil {
return false, err
}
return hour.IsAvailable(), nil
}