diff --git a/backend/src/routes/elements.ts b/backend/src/routes/elements.ts index a8873d2..c7e9c1e 100644 --- a/backend/src/routes/elements.ts +++ b/backend/src/routes/elements.ts @@ -1,5 +1,31 @@ import { FastifyInstance } from 'fastify'; +import { authenticate, authorizeProjectMember, authorizePlannerPlus } from '../middleware/auth'; +import { getElements, createElement, updateElement, deleteElement, batchElements } from '../controllers/elementController'; +import { validateElementCreation, validateElementUpdate, validateBatchElements } from '../validators/elementValidator'; export default async function elementsRoutes(fastify: FastifyInstance) { - // Placeholder for elements routes + // GET /projects/:projectId/elements - List elements (filtered by layer, type, bbox query params) + fastify.get('/', { + preHandler: [authenticate, authorizeProjectMember] + }, getElements); + + // POST /projects/:projectId/elements/ - Create element (Planner+) + fastify.post('/', { + preHandler: [authenticate, authorizeProjectMember, authorizePlannerPlus] + }, createElement); + + // PUT /projects/:projectId/elements/:elementId - Update element (Planner+) + fastify.put('/:elementId', { + preHandler: [authenticate, authorizeProjectMember, authorizePlannerPlus] + }, updateElement); + + // DELETE /projects/:projectId/elements/:elementId - Delete element (Planner+) + fastify.delete('/:elementId', { + preHandler: [authenticate, authorizeProjectMember, authorizePlannerPlus] + }, deleteElement); + + // POST /projects/:projectId/elements/batch - Batch operations (create/update/delete multiple, Planner+) + fastify.post('/batch', { + preHandler: [authenticate, authorizeProjectMember, authorizePlannerPlus] + }, batchElements); }