[JITERA] Implement ToDo API
Created by: chi-jitera
Overview
This pull request implements a complete ToDo API, including the controller, service, routes, and integration into the main application. The API allows for creating, retrieving, updating, patching, and deleting ToDo items.
Changes Made
-
Controller (
controllers/todoController.js):- Created a controller to handle incoming requests related to ToDo items.
- Implemented methods for creating, retrieving all, retrieving by ID, updating, patching, and deleting ToDo items.
- Each method handles errors appropriately and returns a consistent response format.
-
Service (
services/todoService.js):- Created a service layer to encapsulate the business logic for ToDo items.
- Implemented validation for ToDo data to ensure that the title is a non-empty string and that the due date, if provided, is a valid date.
- Methods for creating, retrieving, updating, patching, and deleting ToDo items are defined, with error handling for not found scenarios.
-
Routes (
routes/todoRoutes.js):- Defined routes for the ToDo API, mapping HTTP methods to the corresponding controller methods.
- Routes include endpoints for creating, retrieving all, retrieving by ID, updating, patching, and deleting ToDo items.
-
App Integration (
app.js):- Updated the main application file to include the ToDo API routes by importing
todoRoutesand using it with the Express app. - Ensured that the app can handle JSON requests.
- Updated the main application file to include the ToDo API routes by importing
This implementation follows best practices for structuring an API and provides a solid foundation for further enhancements or modifications.