This commit is contained in:
2026-01-23 20:35:40 +03:00
parent cf3b0e48ec
commit 66c151653e
137 changed files with 41495 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { getManufacturers, getModelsByManufacturer, getBodyType } from "~/lib/car-dataset-management.server";
export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const action = url.searchParams.get("action");
const manufacturer = url.searchParams.get("manufacturer");
const model = url.searchParams.get("model");
try {
switch (action) {
case "manufacturers": {
const manufacturers = await getManufacturers();
return json({ success: true, data: manufacturers });
}
case "models": {
if (!manufacturer) {
return json({ success: false, error: "Manufacturer is required" }, { status: 400 });
}
const models = await getModelsByManufacturer(manufacturer);
return json({ success: true, data: models });
}
case "bodyType": {
if (!manufacturer || !model) {
return json({ success: false, error: "Manufacturer and model are required" }, { status: 400 });
}
const bodyType = await getBodyType(manufacturer, model);
return json({ success: true, data: bodyType });
}
default:
return json({ success: false, error: "Invalid action" }, { status: 400 });
}
} catch (error) {
console.error("Car dataset API error:", error);
return json(
{ success: false, error: "Internal server error" },
{ status: 500 }
);
}
}