-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Region Management Routes #8
Copy link
Copy link
Open
Labels
Description
We need to implement a set of API routes to manage regions in our application. Each region will have the following details:
name: The name of the region.description: A brief description of the region.createdBy: The user who created the region.polygon: A list of location points that represent a polygon on the map.
Routes to be Implemented
| Route | Method | Endpoint | Input | Response |
|---|---|---|---|---|
| Get All | GET | /api/region/ |
None | Array of available regions |
| Get By ID | GET | /api/region/:id |
id as path parameter |
Single region details |
| Create | POST | /api/region/ |
name, description, polygon |
Message |
| Update By ID | PUT | /api/region/:id |
Fields to be updated | Message |
| Delete By ID | DELETE | /api/region/:id |
None | Message |
Middleware for Authentication
- All the above requests should only be allowed if a superadmin is logged in.
- Create a middleware to check if the logged-in user is a superadmin.
Tasks
-
Define Region Model: Update or create the Region model to include
name,description,createdBy, andpolygon. -
Implement Middleware: Create a middleware function to check if the logged-in user is a superadmin.
-
Implement Routes:
getAll: Fetch and return an array of available regions.getById: Fetch and return details of a single region by its ID.create: Add a new region with the given details.updateById: Update the details of an existing region by its ID.deleteById: Delete a region by its ID.
-
Add Routes to API Testing Tool: Add the new routes to the Bruno API testing tool for easy testing and verification.
-
Testing: Write tests for each route to ensure they are working correctly and are properly secured with the middleware.
Reactions are currently unavailable