feat(platform): summarize realtime in vehicle detail
This commit is contained in:
@@ -56,7 +56,7 @@ func TestHandlerVehicleDetail(t *testing.T) {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
for _, want := range []string{"identity", "realtime", "history", "raw", "mileage", "quality", "sources", "sourceStatus", "VIN_MISSING"} {
|
||||
for _, want := range []string{"identity", "realtimeSummary", "realtime", "history", "raw", "mileage", "quality", "sources", "sourceStatus", "VIN_MISSING"} {
|
||||
if !strings.Contains(rec.Body.String(), want) {
|
||||
t.Fatalf("response missing %q: %s", want, rec.Body.String())
|
||||
}
|
||||
|
||||
@@ -55,15 +55,16 @@ type VehicleCoverageRow struct {
|
||||
}
|
||||
|
||||
type VehicleDetail struct {
|
||||
VIN string `json:"vin"`
|
||||
Identity *VehicleRow `json:"identity,omitempty"`
|
||||
Sources []string `json:"sources"`
|
||||
SourceStatus []VehicleSourceStatus `json:"sourceStatus"`
|
||||
Realtime []RealtimeLocationRow `json:"realtime"`
|
||||
History Page[HistoryLocationRow] `json:"history"`
|
||||
Raw Page[RawFrameRow] `json:"raw"`
|
||||
Mileage Page[DailyMileageRow] `json:"mileage"`
|
||||
Quality Page[QualityIssueRow] `json:"quality"`
|
||||
VIN string `json:"vin"`
|
||||
Identity *VehicleRow `json:"identity,omitempty"`
|
||||
RealtimeSummary *VehicleRealtimeRow `json:"realtimeSummary,omitempty"`
|
||||
Sources []string `json:"sources"`
|
||||
SourceStatus []VehicleSourceStatus `json:"sourceStatus"`
|
||||
Realtime []RealtimeLocationRow `json:"realtime"`
|
||||
History Page[HistoryLocationRow] `json:"history"`
|
||||
Raw Page[RawFrameRow] `json:"raw"`
|
||||
Mileage Page[DailyMileageRow] `json:"mileage"`
|
||||
Quality Page[QualityIssueRow] `json:"quality"`
|
||||
}
|
||||
|
||||
type VehicleSourceStatus struct {
|
||||
|
||||
@@ -81,6 +81,14 @@ func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string
|
||||
rawQuery.Protocol = protocol
|
||||
qualityQuery.Set("protocol", protocol)
|
||||
}
|
||||
realtimeSummary, err := s.store.VehicleRealtime(ctx, url.Values{"vin": {resolvedVIN}, "limit": {"1"}})
|
||||
if err != nil {
|
||||
return VehicleDetail{}, err
|
||||
}
|
||||
var summary *VehicleRealtimeRow
|
||||
if len(realtimeSummary.Items) > 0 {
|
||||
summary = &realtimeSummary.Items[0]
|
||||
}
|
||||
realtime, err := s.store.RealtimeLocations(ctx, realtimeQuery)
|
||||
if err != nil {
|
||||
return VehicleDetail{}, err
|
||||
@@ -104,15 +112,16 @@ func (s *Service) VehicleDetail(ctx context.Context, vin string, protocol string
|
||||
sourceStatus := vehicleSourceStatus(vehicles.Items, realtime.Items, history.Items, raw.Items, mileage.Items)
|
||||
sourceStatus = s.enrichVehicleSourceStatus(ctx, resolvedVIN, sourceStatus)
|
||||
return VehicleDetail{
|
||||
VIN: resolvedVIN,
|
||||
Identity: identity,
|
||||
Sources: sourceNames(sourceStatus),
|
||||
SourceStatus: sourceStatus,
|
||||
Realtime: realtime.Items,
|
||||
History: history,
|
||||
Raw: raw,
|
||||
Mileage: mileage,
|
||||
Quality: quality,
|
||||
VIN: resolvedVIN,
|
||||
Identity: identity,
|
||||
RealtimeSummary: summary,
|
||||
Sources: sourceNames(sourceStatus),
|
||||
SourceStatus: sourceStatus,
|
||||
Realtime: realtime.Items,
|
||||
History: history,
|
||||
Raw: raw,
|
||||
Mileage: mileage,
|
||||
Quality: quality,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user