feat(platform): support vehicle keyword detail lookup

This commit is contained in:
lingniu
2026-07-03 23:57:11 +08:00
parent d4fdd7527b
commit 8af622e7f6
3 changed files with 50 additions and 20 deletions

View File

@@ -57,12 +57,13 @@ func (h *Handler) handleVehicleCoverage(w http.ResponseWriter, r *http.Request)
}
func (h *Handler) handleVehicleDetail(w http.ResponseWriter, r *http.Request) {
vin := strings.TrimSpace(r.URL.Query().Get("vin"))
if vin == "" {
httpx.WriteError(w, http.StatusBadRequest, "VIN_REQUIRED", "VIN 不能为空", "", traceID(r))
keyword := firstNonEmpty(r.URL.Query().Get("keyword"), r.URL.Query().Get("vin"))
keyword = strings.TrimSpace(keyword)
if keyword == "" {
httpx.WriteError(w, http.StatusBadRequest, "VEHICLE_KEY_REQUIRED", "车辆关键词不能为空", "", traceID(r))
return
}
data, err := h.service.VehicleDetail(r.Context(), vin, r.URL.Query().Get("protocol"))
data, err := h.service.VehicleDetail(r.Context(), keyword, r.URL.Query().Get("protocol"))
h.write(w, r, data, err)
}

View File

@@ -76,6 +76,19 @@ func TestHandlerVehicleDetailResolvesPlateToVIN(t *testing.T) {
}
}
func TestHandlerVehicleDetailAcceptsKeyword(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/vehicles/detail?keyword=粤AG18312", nil)
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body=%s", rec.Code, rec.Body.String())
}
if !strings.Contains(rec.Body.String(), `"vin":"LB9A32A24R0LS1426"`) {
t.Fatalf("response should resolve keyword to VIN: %s", rec.Body.String())
}
}
func TestHandlerRealtimeLocations(t *testing.T) {
handler := NewHandler(NewService(NewMockStore()))
rec := httptest.NewRecorder()