Skip to content

mahdi-mortada/Task-API-Python-Java-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task API - Python & Java Implementation

A RESTful backend service for task management with PostgreSQL persistence, in-memory caching, and automated tests. Implemented in both Python (FastAPI) and Java (Spring Boot).

Features

  • CRUD operations for task management
  • Status management (OPEN/DONE)
  • Pagination with configurable limit (max 200) and offset
  • Status filtering and ordering by creation date
  • Input validation with error handling
  • In-memory caching (10-second TTL with automatic invalidation)
  • PostgreSQL persistence with migration scripts
  • Comprehensive test coverage

Tech Stack

Python: FastAPI, SQLAlchemy, Pydantic, pytest, Uvicorn Java: Spring Boot 3.2.1, Spring Data JPA, Caffeine Cache, JUnit 5, Maven Infrastructure: PostgreSQL 16, Docker Compose

Prerequisites

  • Docker Desktop installed and running

Quick Start

Start all services:

docker compose up -d --build

This starts:

  • PostgreSQL on port 5432
  • Python API on port 8000
  • Java API on port 8080

Verify health:

curl http://localhost:8000/health  # Python API
curl http://localhost:8080/health  # Java API

Stop services:

docker compose down

API Endpoints

Method Endpoint Description
POST /tasks Create task (requires "title", optional "status": "OPEN")
GET /tasks List tasks (query params: status, limit, offset)
GET /tasks/{id} Get task by ID
PATCH /tasks/{id}/complete Mark task as DONE
DELETE /tasks/{id} Delete task

Note: Status values must be OPEN or DONE (case-sensitive).

Example request:

curl -X POST http://localhost:8000/tasks \
  -H "Content-Type: application/json" \
  -d '{"title": "Buy groceries", "status": "OPEN"}'

Database Schema

Field Type Description
id UUID Primary key
title VARCHAR(500) Task title (required)
status VARCHAR(20) OPEN or DONE
created_at TIMESTAMP Auto-set on creation
updated_at TIMESTAMP Auto-updated on modification
completed_at TIMESTAMP Set when marked DONE

Migration file: migrations/001_create_tasks_table.sql

Caching

  • 10-second TTL for list operations
  • Cache key includes status, limit, and offset parameters
  • Automatic invalidation on create, update, and delete operations
  • Python: Custom in-memory implementation
  • Java: Caffeine Cache with Spring annotations

Project Structure

task-api-project/
├── docker-compose.yml
├── migrations/
├── python-api/
│   ├── app/
│   ├── tests/
│   └── Dockerfile
└── java-api/
    ├── src/
    ├── pom.xml
    └── Dockerfile

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages