/** * @ai-summary Fastify routes for vehicles API * @ai-context Route definitions with TypeBox validation and authentication */ import { FastifyInstance, FastifyPluginOptions } from 'fastify'; import { FastifyPluginAsync } from 'fastify'; import { CreateVehicleBody, UpdateVehicleBody, VehicleParams } from '../domain/vehicles.types'; import { VehiclesController } from './vehicles.controller'; export const vehiclesRoutes: FastifyPluginAsync = async ( fastify: FastifyInstance, _opts: FastifyPluginOptions ) => { const vehiclesController = new VehiclesController(); // GET /api/vehicles - Get user's vehicles fastify.get('/vehicles', { preHandler: [fastify.authenticate], handler: vehiclesController.getUserVehicles.bind(vehiclesController) }); // POST /api/vehicles - Create new vehicle fastify.post<{ Body: CreateVehicleBody }>('/vehicles', { preHandler: [fastify.authenticate], handler: vehiclesController.createVehicle.bind(vehiclesController) }); // GET /api/vehicles/:id - Get specific vehicle fastify.get<{ Params: VehicleParams }>('/vehicles/:id', { preHandler: [fastify.authenticate], handler: vehiclesController.getVehicle.bind(vehiclesController) }); // PUT /api/vehicles/:id - Update vehicle fastify.put<{ Params: VehicleParams; Body: UpdateVehicleBody }>('/vehicles/:id', { preHandler: [fastify.authenticate], handler: vehiclesController.updateVehicle.bind(vehiclesController) }); // DELETE /api/vehicles/:id - Delete vehicle fastify.delete<{ Params: VehicleParams }>('/vehicles/:id', { preHandler: [fastify.authenticate], handler: vehiclesController.deleteVehicle.bind(vehiclesController) }); // Hierarchical Vehicle API - mirrors MVP Platform Vehicles Service structure // GET /api/vehicles/dropdown/years - Available model years fastify.get('/vehicles/dropdown/years', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownYears.bind(vehiclesController) }); // GET /api/vehicles/dropdown/makes?year=2024 - Get makes for year (Level 1) fastify.get<{ Querystring: { year: number } }>('/vehicles/dropdown/makes', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownMakes.bind(vehiclesController) }); // GET /api/vehicles/dropdown/models?year=2024&make_id=1 - Get models for year/make (Level 2) fastify.get<{ Querystring: { year: number; make_id: number } }>('/vehicles/dropdown/models', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownModels.bind(vehiclesController) }); // GET /api/vehicles/dropdown/trims?year=2024&make_id=1&model_id=1 - Get trims (Level 3) fastify.get<{ Querystring: { year: number; make_id: number; model_id: number } }>('/vehicles/dropdown/trims', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownTrims.bind(vehiclesController) }); // GET /api/vehicles/dropdown/engines?year=2024&make_id=1&model_id=1&trim_id=1 - Get engines (Level 4) fastify.get<{ Querystring: { year: number; make_id: number; model_id: number; trim_id: number } }>('/vehicles/dropdown/engines', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownEngines.bind(vehiclesController) }); // GET /api/vehicles/dropdown/transmissions?year=2024&make_id=1&model_id=1 - Get transmissions (Level 3) fastify.get<{ Querystring: { year: number; make_id: number; model_id: number } }>('/vehicles/dropdown/transmissions', { preHandler: [fastify.authenticate], handler: vehiclesController.getDropdownTransmissions.bind(vehiclesController) }); // POST /api/vehicles/decode-vin - Decode VIN and return vehicle information fastify.post<{ Body: { vin: string } }>('/vehicles/decode-vin', { preHandler: [fastify.authenticate], handler: vehiclesController.decodeVIN.bind(vehiclesController) }); }; // For backward compatibility during migration export function registerVehiclesRoutes() { throw new Error('registerVehiclesRoutes is deprecated - use vehiclesRoutes Fastify plugin instead'); }