Simple REST API for creating, updating, listing and deleting tasks. Built with Spring Boot, JPA and MySQL; automated tests run on an in-memory H2 database.
- CRUD for tasks (
description,finished). - Validation with Jakarta Bean Validation and explicit business rules in the entity.
- Global error handling for validation errors, bad input and missing records.
- OpenAPI docs via springdoc (
/swagger-ui.html). - Test profile that runs against H2; default runtime profile uses MySQL.
- Java 17
- Spring Boot 3.3.5 (Web, Data JPA, Validation)
- MySQL 8.4 (default), H2 (tests)
- Maven Wrapper
- JDK 17+
- Maven 3.9+ (or use the provided
./mvnw) - Docker (optional, for local MySQL)
- Start MySQL (Docker):
docker compose up -d mysql - Check credentials in
src/main/resources/application.yaml. - Run the app:
./mvnw spring-boot:run - API base URL:
http://localhost:8080 - Swagger UI:
http://localhost:8080/swagger-ui.html(spec at/v3/api-docs)
- Use the
testprofile:SPRING_PROFILES_ACTIVE=test ./mvnw spring-boot:run - Profile config:
src/test/resources/application-test.yaml.
Key settings (default application.yaml):
spring.datasource.url:jdbc:mysql://localhost:3306/todo_dbspring.datasource.username:todo_userspring.datasource.password:todo_passspring.jpa.hibernate.ddl-auto:update
Docker MySQL credentials (from docker-compose.yaml):
- DB:
todo_db - User/password:
todo_user/todo_pass - Root password:
root_pass
Endpoints use JSON.
- GET
/tasks– list all tasks. - GET
/tasks/{id}– get a single task. - POST
/tasks– create. Body:{"description":"Write docs","finished":false}(onlydescriptionis required). - PATCH
/tasks/{id}– update description and/or finished flag. Body:{"description":"Reviewed docs","finished":true}. - DELETE
/tasks/{id}– delete a task.
Example (create):
curl -X POST http://localhost:8080/tasks \
-H "Content-Type: application/json" \
-d '{"description":"Write README","finished":false}'- Unit, controller, service and integration suites:
./mvnw test - Tests run with profile
testagainst H2; database is created and dropped automatically.
src/main/java/com/thallesgarbelotti/todo_list– application code (entity, repository, service, controller, exception handler).src/test/java/com/thallesgarbelotti/todo_list– unit and integration tests.docker-compose.yaml– MySQL for local dev.
- SQL logging is enabled (
org.hibernate.SQL=DEBUG). Uncommentorg.hibernate.orm.jdbc.bindinapplication.yamlto inspect parameter binding when needed.