From 179594cd3e6a73cce13a65c67cd4da79cd16e3f6 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 05:50:14 +0000 Subject: [PATCH] feat: Implement element CRUD API endpoints with RBAC --- backend/src/routes/elements.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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); }