@@ -16,7 +16,6 @@ import (
1616 "github.com/prometheus/client_golang/prometheus"
1717
1818 "github.com/DIMO-Network/device-definitions-api/internal/core/common"
19- "github.com/DIMO-Network/device-definitions-api/internal/core/mediator"
2019 coremodels "github.com/DIMO-Network/device-definitions-api/internal/core/models"
2120 "github.com/DIMO-Network/device-definitions-api/internal/core/services"
2221 "github.com/DIMO-Network/device-definitions-api/internal/infrastructure/db/models"
@@ -73,16 +72,18 @@ func NewDecodeVINQueryHandler(dbs func() *db.ReaderWriter, vinDecodingService se
7372 }
7473}
7574
76- func (dc DecodeVINQueryHandler ) Handle (ctx context.Context , query mediator.Message ) (interface {}, error ) {
77- qry := query .(* DecodeVINQuery )
78- if len (qry .VIN ) < 10 || len (qry .VIN ) > 17 {
79- return nil , & exceptions.ValidationError {Err : fmt .Errorf ("invalid VIN %s" , qry .VIN )}
75+ func (dc DecodeVINQueryHandler ) Handle (ctx context.Context , query * DecodeVINQuery ) (* p_grpc.DecodeVinResponse , error ) {
76+ if query == nil {
77+ return nil , & exceptions.ValidationError {Err : errors .New ("query is nil" )}
78+ }
79+ if len (query .VIN ) < 10 || len (query .VIN ) > 17 {
80+ return nil , & exceptions.ValidationError {Err : fmt .Errorf ("invalid VIN %s" , query .VIN )}
8081 }
8182 resp := & p_grpc.DecodeVinResponse {}
82- vinObj := vin .VIN (qry .VIN )
83+ vinObj := vin .VIN (query .VIN )
8384
8485 if ! vinObj .IsValidJapanChassis () && ! vinObj .IsValidVIN () {
85- return nil , & exceptions.ValidationError {Err : fmt .Errorf ("invalid VIN %s" , qry .VIN )}
86+ return nil , & exceptions.ValidationError {Err : fmt .Errorf ("invalid VIN %s" , query .VIN )}
8687 }
8788
8889 resp .Year = int32 (vinObj .Year ())
@@ -92,9 +93,9 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query mediator.Messa
9293 Str (logfields .VIN , vinObj .String ()).
9394 Str ("handler" , query .Key ()).
9495 Str ("vinYear" , fmt .Sprintf ("%d" , resp .Year )).
95- Str ("knownModel" , qry .KnownModel ).
96- Str ("knownYear" , strconv .Itoa (int (qry .KnownYear ))).
97- Str ("country" , qry .Country ).
96+ Str ("knownModel" , query .KnownModel ).
97+ Str ("knownYear" , strconv .Itoa (int (query .KnownYear ))).
98+ Str ("country" , query .Country ).
9899 Logger ()
99100
100101 const (
@@ -140,21 +141,21 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query mediator.Messa
140141 dbWMI , err := models .Wmis (models .WmiWhere .Wmi .EQ (wmi )).One (ctx , dc .dbs ().Reader )
141142 if err == nil && dbWMI != nil {
142143 if dbWMI .ManufacturerName == "Tesla" {
143- vinInfo , err = dc .vinDecodingService .GetVIN (ctx , vinObj .String (), coremodels .TeslaProvider , qry .Country )
144+ vinInfo , err = dc .vinDecodingService .GetVIN (ctx , vinObj .String (), coremodels .TeslaProvider , query .Country )
144145 resp .Manufacturer = "Tesla"
145146 }
146147 }
147148 // not a tesla, regular decode path
148149 if vinInfo == nil || vinInfo .Model == "" {
149- vinInfo , err = dc .vinDecodingService .GetVIN (ctx , vinObj .String (), coremodels .AllProviders , qry .Country ) // this will try drivly first unless of japan
150+ vinInfo , err = dc .vinDecodingService .GetVIN (ctx , vinObj .String (), coremodels .AllProviders , query .Country ) // this will try drivly first unless of japan
150151 }
151152
152153 // if no luck decoding VIN, try buildingVinInfo from known data passed in, typically smartcar or software connections
153154 if err != nil {
154- if len (qry .KnownModel ) > 0 && qry .KnownYear > 0 {
155+ if len (query .KnownModel ) > 0 && query .KnownYear > 0 {
155156 // note if this is successful, err gets set to nil
156157 // todo: the knownModel should correspond with the Make
157- vinInfo , err = dc .vinInfoFromKnown (vinObj , qry .KnownModel , qry .KnownYear )
158+ vinInfo , err = dc .vinInfoFromKnown (vinObj , query .KnownModel , query .KnownYear )
158159 }
159160 }
160161
@@ -167,7 +168,7 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query mediator.Messa
167168 if err == nil {
168169 err = errors .New ("failed to decode, vinInfo is nil" )
169170 }
170- localLog .Err (err ).Msgf ("failed to decode vinObj from provider, country: %s" , qry .Country )
171+ localLog .Err (err ).Msgf ("failed to decode vinObj from provider, country: %s" , query .Country )
171172 // todo track failed decodes
172173 return nil , err
173174 }
0 commit comments