Modernization Project Complete. Updated to latest versions of frameworks.
This commit is contained in:
@@ -1,32 +1,80 @@
|
||||
/**
|
||||
* @ai-summary Express routes for vehicles API
|
||||
* @ai-context Defines REST endpoints with auth middleware
|
||||
* @ai-summary Fastify routes for vehicles API
|
||||
* @ai-context Route definitions with TypeBox validation and authentication
|
||||
*/
|
||||
|
||||
import { Router } from 'express';
|
||||
import { FastifyInstance, FastifyPluginOptions } from 'fastify';
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import {
|
||||
CreateVehicleBody,
|
||||
UpdateVehicleBody,
|
||||
VehicleParams
|
||||
} from '../domain/vehicles.types';
|
||||
import { VehiclesController } from './vehicles.controller';
|
||||
import { authMiddleware } from '../../../core/security/auth.middleware';
|
||||
|
||||
export function registerVehiclesRoutes(): Router {
|
||||
const router = Router();
|
||||
const controller = new VehiclesController();
|
||||
export const vehiclesRoutes: FastifyPluginAsync = async (
|
||||
fastify: FastifyInstance,
|
||||
_opts: FastifyPluginOptions
|
||||
) => {
|
||||
const vehiclesController = new VehiclesController();
|
||||
|
||||
// Dropdown Data Routes (no auth required for form population)
|
||||
router.get('/api/vehicles/dropdown/makes', controller.getDropdownMakes);
|
||||
router.get('/api/vehicles/dropdown/models/:make', controller.getDropdownModels);
|
||||
router.get('/api/vehicles/dropdown/transmissions', controller.getDropdownTransmissions);
|
||||
router.get('/api/vehicles/dropdown/engines', controller.getDropdownEngines);
|
||||
router.get('/api/vehicles/dropdown/trims', controller.getDropdownTrims);
|
||||
// GET /api/vehicles - Get user's vehicles
|
||||
fastify.get('/vehicles', {
|
||||
preHandler: fastify.authenticate,
|
||||
handler: vehiclesController.getUserVehicles.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// All other vehicle routes require authentication
|
||||
router.use(authMiddleware);
|
||||
// POST /api/vehicles - Create new vehicle
|
||||
fastify.post<{ Body: CreateVehicleBody }>('/vehicles', {
|
||||
preHandler: fastify.authenticate,
|
||||
handler: vehiclesController.createVehicle.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// CRUD Routes
|
||||
router.post('/api/vehicles', controller.createVehicle);
|
||||
router.get('/api/vehicles', controller.getUserVehicles);
|
||||
router.get('/api/vehicles/:id', controller.getVehicle);
|
||||
router.put('/api/vehicles/:id', controller.updateVehicle);
|
||||
router.delete('/api/vehicles/:id', controller.deleteVehicle);
|
||||
// GET /api/vehicles/:id - Get specific vehicle
|
||||
fastify.get<{ Params: VehicleParams }>('/vehicles/:id', {
|
||||
preHandler: fastify.authenticate,
|
||||
handler: vehiclesController.getVehicle.bind(vehiclesController)
|
||||
});
|
||||
|
||||
return router;
|
||||
// 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)
|
||||
});
|
||||
|
||||
// GET /api/vehicles/dropdown/makes - Get vehicle makes
|
||||
fastify.get('/vehicles/dropdown/makes', {
|
||||
handler: vehiclesController.getDropdownMakes.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// GET /api/vehicles/dropdown/models/:make - Get models for make
|
||||
fastify.get<{ Params: { make: string } }>('/vehicles/dropdown/models/:make', {
|
||||
handler: vehiclesController.getDropdownModels.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// GET /api/vehicles/dropdown/transmissions - Get transmission types
|
||||
fastify.get('/vehicles/dropdown/transmissions', {
|
||||
handler: vehiclesController.getDropdownTransmissions.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// GET /api/vehicles/dropdown/engines - Get engine configurations
|
||||
fastify.get('/vehicles/dropdown/engines', {
|
||||
handler: vehiclesController.getDropdownEngines.bind(vehiclesController)
|
||||
});
|
||||
|
||||
// GET /api/vehicles/dropdown/trims - Get trim levels
|
||||
fastify.get('/vehicles/dropdown/trims', {
|
||||
handler: vehiclesController.getDropdownTrims.bind(vehiclesController)
|
||||
});
|
||||
};
|
||||
|
||||
// For backward compatibility during migration
|
||||
export function registerVehiclesRoutes() {
|
||||
throw new Error('registerVehiclesRoutes is deprecated - use vehiclesRoutes Fastify plugin instead');
|
||||
}
|
||||
Reference in New Issue
Block a user