-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc_vin_decoder_service.go
37 lines (30 loc) · 1.05 KB
/
grpc_vin_decoder_service.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
package api
import (
"context"
"github.com/DIMO-Network/device-definitions-api/internal/core/mediator"
"github.com/DIMO-Network/device-definitions-api/internal/core/queries"
p_grpc "github.com/DIMO-Network/device-definitions-api/pkg/grpc"
"github.com/rs/zerolog"
)
type GrpcVinDecoderService struct {
p_grpc.VinDecoderServiceServer
Mediator mediator.Mediator
logger *zerolog.Logger
}
func NewGrpcVinDecoderService(mediator mediator.Mediator, logger *zerolog.Logger) p_grpc.VinDecoderServiceServer {
return &GrpcVinDecoderService{Mediator: mediator, logger: logger}
}
func (s *GrpcVinDecoderService) DecodeVin(ctx context.Context, in *p_grpc.DecodeVinRequest) (*p_grpc.DecodeVinResponse, error) {
qryResult, err := s.Mediator.Send(ctx, &queries.DecodeVINQuery{
VIN: in.Vin,
KnownModel: in.KnownModel,
KnownYear: in.KnownYear,
Country: in.Country,
DeviceDefinitionID: in.DeviceDefinitionId,
})
if err != nil {
return nil, err
}
result := qryResult.(*p_grpc.DecodeVinResponse)
return result, nil
}