-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.usecase.go
49 lines (39 loc) · 937 Bytes
/
room.usecase.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
package main
import (
"context"
"time"
)
type UseCase interface {
GetRoomBySerial(ctx context.Context, serial string) (room Room, err error)
UpsertDocument(ctx context.Context, index string, room Room) (err error)
}
type useCase struct {
repo Repository
}
func NewUseCase(repo Repository) UseCase {
return &useCase{
repo: repo,
}
}
func (u *useCase) GetRoomBySerial(ctx context.Context, serial string) (room Room, err error) {
room, err = u.repo.FetchRoomBySerial(ctx, serial)
if err != nil {
return
}
tags, err := u.repo.FetchTagsByRoomSerial(ctx, serial)
if err != nil {
return
}
rateSummary, err := u.repo.FetchRatingByRoomSerial(ctx, serial)
if err != nil {
return
}
room.Tags = tags
room.Rate = rateSummary
room.UpdatedAt = time.Now()
return
}
func (u *useCase) UpsertDocument(ctx context.Context, index string, room Room) (err error) {
err = u.repo.UpsertDocument(ctx, index, room)
return
}