Skip to content

clesiosmatos/todo-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo Backend - Java Spring Boot

A RESTful API for managing todos built with Spring Boot, PostgreSQL, and Docker.

Features

  • ✅ Create, Read, Update, Delete (CRUD) operations for todos
  • ✅ Toggle todo completion status
  • ✅ Filter todos by completion status
  • ✅ PostgreSQL database
  • ✅ Docker and Docker Compose support
  • ✅ Validation with Bean Validation
  • ✅ Lombok for cleaner code

Tech Stack

  • Java 17
  • Spring Boot 3.2.3
  • Spring Data JPA
  • PostgreSQL 16
  • Lombok
  • Maven
  • Docker & Docker Compose

Prerequisites

  • Docker and Docker Compose installed

Getting Started

Running with Docker Compose

  1. Clone the repository and navigate to the project directory:
cd todo-java
  1. Build and start the containers:
docker-compose up --build

The application will be available at http://localhost:8080

  1. To stop the containers:
docker-compose down

API Endpoints

Get All Todos

GET /api/todos

Get Todos by Status

GET /api/todos?completed=true
GET /api/todos?completed=false

Get Todo by ID

GET /api/todos/{id}

Create Todo

POST /api/todos
Content-Type: application/json

{
  "title": "My Todo",
  "description": "Description here",
  "completed": false
}

Update Todo

PUT /api/todos/{id}
Content-Type: application/json

{
  "title": "Updated Todo",
  "description": "Updated description",
  "completed": true
}

Toggle Todo Status

PATCH /api/todos/{id}/toggle

Delete Todo

DELETE /api/todos/{id}

Example Usage

Create a new todo:

curl -X POST http://localhost:8080/api/todos \
  -H "Content-Type: application/json" \
  -d '{"title": "Learn Spring Boot", "description": "Complete the tutorial"}'

Get all todos:

curl http://localhost:8080/api/todos

Toggle todo status:

curl -X PATCH http://localhost:8080/api/todos/1/toggle

Database

The application uses PostgreSQL with the following default configuration:

  • Database: tododb
  • User: todouser
  • Password: todopass
  • Port: 5432

Project Structure

todo-java/
├── src/
│   └── main/
│       ├── java/
│       │   └── com/
│       │       └── example/
│       │           └── todo/
│       │               ├── TodoApplication.java
│       │               ├── controller/
│       │               │   └── TodoController.java
│       │               ├── service/
│       │               │   └── TodoService.java
│       │               ├── repository/
│       │               │   └── TodoRepository.java
│       │               ├── model/
│       │               │   └── Todo.java
│       │               └── dto/
│       │                   ├── TodoRequest.java
│       │                   └── TodoResponse.java
│       └── resources/
│           └── application.properties
├── Dockerfile
├── docker-compose.yml
└── pom.xml

Development

To run the application locally without Docker, you need:

  1. Java 17 or higher
  2. Maven 3.6+
  3. PostgreSQL running locally

Update application.properties with your local database configuration and run:

mvn spring-boot:run

About

A java project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors