@@ -79,7 +79,7 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
7979 if len (providersToTry ) == 0 {
8080 if provider == coremodels .AllProviders {
8181 // fill in the list, future could do something country specific
82- providersToTry = append (providersToTry , coremodels .DrivlyProvider , coremodels .AutoIsoProvider , coremodels .VincarioProvider , coremodels .DATGroupProvider )
82+ providersToTry = append (providersToTry , coremodels .DrivlyProvider , coremodels .VincarioProvider , coremodels .Japan17VIN , coremodels . AutoIsoProvider , coremodels .DATGroupProvider )
8383 } else {
8484 // use the specified override
8585 providersToTry = append (providersToTry , provider )
@@ -89,7 +89,6 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
8989
9090 for _ , p := range providersToTry {
9191 // try all the options, but need to continue if get an error
92- // todo: break if decode works, continue if need to try with next
9392 switch p {
9493 case coremodels .TeslaProvider :
9594 v := vinutil .VIN (vin )
@@ -107,33 +106,41 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
107106 FuelType : "electric" ,
108107 MetaData : null .JSONFrom (bytes ),
109108 }
109+ err := validateVinDecoding (result )
110+ if err != nil {
111+ errFinal = err
112+ continue
113+ }
110114 localLog .Info ().Msgf ("decoded with tesla: %+v" , result )
111115 return result , nil
112116 case coremodels .DrivlyProvider :
117+ localLog .Info ().Msgf ("trying to decode VIN: %s with drivly" , vin )
113118 vinDrivlyInfo , err := c .drivlyAPISvc .GetVINInfo (vin )
114119 if err != nil {
115120 errFinal = errors .Wrapf (err , "unable to decode vin: %s with drivly" , vin )
116121 continue
117122 }
118- result , err = buildFromDrivly (vinDrivlyInfo )
123+ result , err = buildFromDrivly (vinDrivlyInfo ) // already does validation
119124 if err != nil {
120125 errFinal = errors .Wrapf (err , "unable to decode vin: %s with drivly" , vin )
121126 continue
122127 }
123128 return result , nil
124129 case coremodels .VincarioProvider :
130+ localLog .Info ().Msgf ("trying to decode VIN: %s with vincario" , vin )
125131 vinVincarioInfo , err := c .vincarioAPISvc .DecodeVIN (vin )
126132 if err != nil {
127133 errFinal = errors .Wrapf (err , "unable to decode vin: %s with vincario" , vin )
128134 continue
129135 }
130- result , err = buildFromVincario (vinVincarioInfo )
136+ result , err = buildFromVincario (vinVincarioInfo ) // already does validation
131137 if err != nil {
132138 errFinal = err
133139 continue
134140 }
135141 return result , nil
136142 case coremodels .Japan17VIN :
143+ localLog .Info ().Msgf ("trying to decode VIN: %s with 17vin" , vin )
137144 mmy , raw , err := c .japan17VINAPI .GetVINInfo (vin )
138145 if err != nil {
139146 errFinal = errors .Wrapf (err , "unable to decode vin: %s with japan17vin" , vin )
@@ -155,6 +162,7 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
155162 }
156163 return result , nil
157164 case coremodels .CarVXVIN :
165+ localLog .Info ().Msgf ("trying to decode VIN: %s with carvx" , vin )
158166 info , raw , err := c .carvxAPI .GetVINInfo (vin )
159167 if err != nil {
160168 errFinal = errors .Wrapf (err , "unable to decode vin: %s with carvx" , vin )
@@ -180,87 +188,35 @@ func (c vinDecodingService) GetVIN(ctx context.Context, vin string, provider cor
180188 }
181189 return result , nil
182190 case coremodels .AutoIsoProvider :
191+ localLog .Info ().Msgf ("trying to decode VIN: %s with autoiso" , vin )
183192 vinAutoIsoInfo , err := c .autoIsoAPIService .GetVIN (vin )
184193 if err != nil {
185194 errFinal = errors .Wrapf (err , "unable to decode vin: %s with autoiso" , vin )
186195 continue
187196 }
188- result , err = buildFromAutoIso (vinAutoIsoInfo )
197+ result , err = buildFromAutoIso (vinAutoIsoInfo ) // already does validation
189198 if err != nil {
190199 errFinal = err
191200 continue
192201 }
193202 return result , nil
194203 case coremodels .DATGroupProvider :
204+ localLog .Info ().Msgf ("trying to decode VIN: %s with datgroup" , vin )
195205 // todo lookup country for two letter equiv
196206 vinInfo , err := c .DATGroupAPIService .GetVINv2 (vin , country ) // try with Turkey
197207 if err != nil {
198208 errFinal = errors .Wrapf (err , "unable to decode vin: %s with DATGroup" , vin )
199209 continue
200210 }
201- result , err = buildFromDATGroup (vinInfo )
211+ result , err = buildFromDATGroup (vinInfo ) // already does validation
202212 if err != nil {
203213 errFinal = err
204214 continue
205215 }
206216 return result , nil
207217 case coremodels .AllProviders :
208- //vinDrivlyInfo, err := c.drivlyAPISvc.GetVINInfo(vin)
209- //if err != nil {
210- // localLog.Warn().Err(err).Msg("AllProviders decode - unable decode vin with drivly")
211- //} else {
212- // result, err = buildFromDrivly(vinDrivlyInfo)
213- // if err != nil {
214- // localLog.Warn().Err(err).Msg("AllProviders decode -could not decode vin with drivly")
215- // } else {
216- // metadata, err := common.BuildDeviceTypeAttributes(buildDrivlyVINInfoToUpdateAttr(vinDrivlyInfo), dt)
217- // if err != nil {
218- // localLog.Warn().Err(err).Msg("AllProviders decode - unable to build metadata attributes")
219- // }
220- // result.MetaData = metadata
221- // }
222- //}
223- //
224- //// if nothing from drivly, try autoiso
225- //if result == nil || result.Source == "" {
226- // autoIsoInfo, err := c.autoIsoAPIService.GetVIN(vin)
227- // if err != nil {
228- // localLog.Warn().Err(err).Msg("AllProviders decode -could not decode vin with autoiso")
229- // } else {
230- // result, err = buildFromAutoIso(autoIsoInfo)
231- // if err != nil {
232- // localLog.Warn().Err(err).Msg("AllProviders decode -could not build struct from autoiso data")
233- // }
234- // }
235- //}
236- //
237- //// if nothing,try vincario
238- //if result == nil || result.Source == "" {
239- // vinVincarioInfo, err := c.vincarioAPISvc.DecodeVIN(vin)
240- // if err != nil {
241- // localLog.Warn().Err(err).Msg("AllProviders decode -could not decode vin with vincario")
242- // } else {
243- // result, err = buildFromVincario(vinVincarioInfo)
244- // if err != nil {
245- // localLog.Warn().Err(err).Msg("AllProviders decode -could not build struct from vincario data")
246- // }
247- // }
248- //}
249- //
250- //// if nothing from vincario, try DATGroup
251- //if result == nil || result.Source == "" {
252- // // idea: only accept WMI's for DATgroup that they have succesfully decoded in the past
253- // datGroupInfo, err := c.DATGroupAPIService.GetVINv2(vin, country)
254- // if err != nil {
255- // localLog.Warn().Err(err).Msg("AllProviders decode -could not decode vin with DATGroup")
256- // } else {
257- // result, err = buildFromDATGroup(datGroupInfo)
258- // localLog.Info().Msgf("datgroup result: %+v", result) // temporary for debugging
259- // if err != nil {
260- // localLog.Warn().Err(err).Msg("AllProviders decode - could not build struct from DATGroup data")
261- // }
262- // }
263- //}
218+ // this should never hit
219+ errFinal = fmt .Errorf ("all providers - invalid option reached" )
264220 }
265221 }
266222
0 commit comments