Skip to content

Gthalles/tasks-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo List API

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.

Features

  • 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.

Tech Stack

  • Java 17
  • Spring Boot 3.3.5 (Web, Data JPA, Validation)
  • MySQL 8.4 (default), H2 (tests)
  • Maven Wrapper

Requirements

  • JDK 17+
  • Maven 3.9+ (or use the provided ./mvnw)
  • Docker (optional, for local MySQL)

Quick Start (MySQL default)

  1. Start MySQL (Docker): docker compose up -d mysql
  2. Check credentials in src/main/resources/application.yaml.
  3. Run the app: ./mvnw spring-boot:run
  4. API base URL: http://localhost:8080
  5. Swagger UI: http://localhost:8080/swagger-ui.html (spec at /v3/api-docs)

Running with H2 (tests or local without MySQL)

Configuration

Key settings (default application.yaml):

  • spring.datasource.url: jdbc:mysql://localhost:3306/todo_db
  • spring.datasource.username: todo_user
  • spring.datasource.password: todo_pass
  • spring.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

API

Endpoints use JSON.

  • GET /tasks – list all tasks.
  • GET /tasks/{id} – get a single task.
  • POST /tasks – create. Body: {"description":"Write docs","finished":false} (only description is 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}'

Tests

  • Unit, controller, service and integration suites: ./mvnw test
  • Tests run with profile test against H2; database is created and dropped automatically.

Project Layout

Logging & Debug

  • SQL logging is enabled (org.hibernate.SQL=DEBUG). Uncomment org.hibernate.orm.jdbc.bind in application.yaml to inspect parameter binding when needed.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages