feat(platform): add lightweight vehicle overview api
This commit is contained in:
@@ -85,6 +85,46 @@ func (s *Service) VehicleRealtime(ctx context.Context, query url.Values) (Page[V
|
||||
return s.store.VehicleRealtime(ctx, resolvedQuery)
|
||||
}
|
||||
|
||||
func (s *Service) VehicleServiceOverview(ctx context.Context, keyword string, protocol string) (VehicleServiceOverview, error) {
|
||||
keyword = strings.TrimSpace(keyword)
|
||||
protocol = strings.TrimSpace(protocol)
|
||||
vehicleQuery := url.Values{"keyword": {keyword}, "limit": {"20"}}
|
||||
if protocol != "" {
|
||||
vehicleQuery.Set("protocol", protocol)
|
||||
}
|
||||
vehicles, err := s.store.Vehicles(ctx, vehicleQuery)
|
||||
if err != nil {
|
||||
return VehicleServiceOverview{}, err
|
||||
}
|
||||
resolution := buildVehicleIdentityResolution(keyword, vehicles.Items)
|
||||
identity := resolveVehicleIdentity(keyword, vehicles.Items)
|
||||
resolvedVIN := ""
|
||||
if identity != nil && strings.TrimSpace(identity.VIN) != "" {
|
||||
resolvedVIN = identity.VIN
|
||||
} else if resolution.Resolved {
|
||||
resolvedVIN = resolution.VIN
|
||||
}
|
||||
if resolvedVIN == "" {
|
||||
return *buildVehicleServiceOverview("", keyword, &resolution, nil, nil, nil, Page[HistoryLocationRow]{}, Page[RawFrameRow]{}, Page[DailyMileageRow]{}, Page[QualityIssueRow]{}), nil
|
||||
}
|
||||
|
||||
realtimeQuery := url.Values{"vin": {resolvedVIN}, "limit": {"1"}}
|
||||
if protocol != "" {
|
||||
realtimeQuery.Set("protocol", protocol)
|
||||
}
|
||||
realtimeSummary, err := s.store.VehicleRealtime(ctx, realtimeQuery)
|
||||
if err != nil {
|
||||
return VehicleServiceOverview{}, err
|
||||
}
|
||||
var summary *VehicleRealtimeRow
|
||||
if len(realtimeSummary.Items) > 0 {
|
||||
summary = &realtimeSummary.Items[0]
|
||||
}
|
||||
sourceStatus := vehicleSourceStatus(vehicles.Items, nil, nil, nil, nil)
|
||||
overview := buildVehicleServiceOverview(resolvedVIN, keyword, &resolution, identity, summary, sourceStatus, Page[HistoryLocationRow]{}, Page[RawFrameRow]{}, Page[DailyMileageRow]{}, Page[QualityIssueRow]{})
|
||||
return *overview, nil
|
||||
}
|
||||
|
||||
func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string) (VehicleDetail, error) {
|
||||
keyword := strings.TrimSpace(vin)
|
||||
protocol = strings.TrimSpace(protocol)
|
||||
|
||||
Reference in New Issue
Block a user