-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_dmmy_all.go
49 lines (39 loc) · 1.26 KB
/
get_dmmy_all.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
//nolint:tagliatelle
package queries
import (
"context"
"github.com/DIMO-Network/device-definitions-api/internal/core/mediator"
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/db/repositories"
"github.com/DIMO-Network/device-definitions-api/pkg/grpc"
)
type GetDevicesMMYQuery struct {
}
func (*GetDevicesMMYQuery) Key() string { return "GetDevicesMMYQuery" }
type GetDevicesMMYQueryHandler struct {
Repository repositories.DeviceDefinitionRepository
}
type GetDevicesMMYQueryResult struct {
Make string `json:"make_slug"`
Model string `json:"model_slug"`
Year int32 `json:"year"`
}
func NewGetDevicesMMYQueryHandler(repository repositories.DeviceDefinitionRepository) GetDevicesMMYQueryHandler {
return GetDevicesMMYQueryHandler{
Repository: repository,
}
}
func (ch GetDevicesMMYQueryHandler) Handle(ctx context.Context, _ mediator.Message) (interface{}, error) {
all, err := ch.Repository.GetDevicesMMY(ctx)
if err != nil {
return nil, err
}
result := &grpc.GetDevicesMMYResponse{}
for _, v := range all {
result.Device = append(result.Device, &grpc.GetDevicesMMYItemResponse{
Make: v.DeviceMakes.NameSlug,
Model: v.DeviceDefinitions.ModelSlug,
Year: int32(v.DeviceDefinitions.Year),
})
}
return result, nil
}