This is a backend application built with Spring Boot and Maven that provides API endpoints for managing a to-do list.
Make sure you have the following installed on your system:
- Java Development Kit (JDK) - version 17
- Apache Maven - version 3 or higher
- Clone the repository:
git clone https://github.com/VhugoJc/To-Do-Backend- Change to the project directory:
cd To-Do-BackendRun the application:
mvn soring-boot:runTest the application:
mvn testThe application will start running on http://localhost:9090.
CORS are enable by method from http://localhost:8080. If change the origin is needed, you can edit the CLIENT_URL variable in the controller class.
The following API endpoints are available:
- Endpoint:
GET /api/todos - Description: Retrieves a list of all to-do items based on the parameters and filters sent.
- Parameters:
name(Optional): name or part of the name required (string).status(optional): The status of the to-do items. Possible values:done,undone.priority(optional): The priority of the to-do items. Possible values:low,medium,high.page(optional): The page requerided (int). The page size is 10 items.sortByDate(optional): Sorts To Do's by the due date assigned. Possible values:ascend,descend.sortByPriority(optional): Sorts To Do's by priority assigned. Possible values:ascend,descend.
- Example Request 1:
/api/todos - Example Response 1:
{
"totalPages": 1,
"currentPage": 1,
"toDos": [
{
"id": 1,
"name": "task 1",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": null,
"createdDate": "2023-05-19T20:13:38.16397",
"priotity": "medium",
"done": false
},
{
"id": 2,
"name": "task 2",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": "2023-05-19T20:14:14.568808",
"createdDate": "2023-05-19T20:13:45.314997",
"priotity": "low",
"done": true
},
{
"id": 3,
"name": "task 3",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": null,
"createdDate": "2023-05-19T20:13:55.548158",
"priotity": "high",
"done": false
}
]
}- Example Request 2:
/api/todos?status=done&priority=low&name=task&page=1 - Example Response 2:
{
"totalPages": 1,
"currentPage": 1,
"toDos": [
{
"id": 2,
"name": "task 2",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": "2023-05-19T20:19:36.987177",
"createdDate": "2023-05-19T20:19:21.804428",
"priotity": "low",
"done": true
}
]
}In this example, the endpoint /api/todo accepts optional query parameters status, priority, name and page to filter the to-do items. The API will return a list of to-do items that match the provided filters.
- Endpoint:
POST /api/todos - Description: Creates a new to-do item.
- Example Request:
{
"name":"task 1",
"dueDate":"2023-05-18T10:08:47.316615",
"priotity":"medium"
}- Example Response:
{
"id": 1,
"name": "task 1",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": null,
"createdDate": "2023-05-19T20:31:50.728214",
"priotity": "medium",
"done": false
}- Endpoint:
PUT /api/todos/{id} - Description: Updates an existing to-do item.
- Example Request:
/api/todos/1
{
"name":"New Task",
"dueDate":"2023-05-18T10:08:47.316615",
"priotity":"low"
}- Example Response:
{
"id": 1,
"name": "New Task",
"dueDate": "2023-05-18T10:08:47.316615",
"doneDate": null,
"createdDate": "2023-05-19T21:44:28.285446",
"priotity": "low",
"done": false
}- Endpoint:
POST /api/todos/{id}/done - Description: Changes
doneas true and assigns a date todueDateby its ID.
- Endpoint:
PUT /api/todos/{id}/undone - Description: Changes
doneas false and assigns null todueDateby its ID.
- Endpoint:
GET /api/metrics - Description: Retrieves time average of task with priority
low,mediumandhigh. - Example Request:
/api/metrics - Example Response:
{
"highPriorityMinutes": 25.5,
"lowPriorityMinutes": 25.5,
"mediumPriorityMinutes": 25.5
}- Endpoint:
DELETE /api/todo/{id} - Description: Deletes a specific to-do item by its ID.
The application uses the following dependencies:
- spring boot starter web
- spring boot devtools
- spring boot starter validation
- spring boot starter test
The application's configuration can be found in the application.properties file located in the src/main/resources directory. You can modify this file to change the server port.
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a pull request with your improvements or suggestions.