
- Add complete CRUD operations for task management - Implement task filtering by status, priority, and search - Add task statistics endpoint for summary data - Configure SQLite database with Alembic migrations - Set up FastAPI with CORS support and API documentation - Include health check endpoint and base URL information - Add comprehensive README with API usage examples - Structure project with proper separation of concerns
174 lines
4.7 KiB
Markdown
174 lines
4.7 KiB
Markdown
# Task Manager API
|
|
|
|
A comprehensive Task Manager API built with FastAPI and SQLite, providing full CRUD operations for task management with filtering, search, and statistics capabilities.
|
|
|
|
## Features
|
|
|
|
- ✅ **Task Management**: Create, read, update, and delete tasks
|
|
- 🔍 **Advanced Filtering**: Filter tasks by status, priority, and search text
|
|
- 📊 **Statistics**: Get task count summaries by status
|
|
- 🚀 **FastAPI Framework**: Modern, fast web framework with automatic API documentation
|
|
- 💾 **SQLite Database**: Lightweight, serverless database with Alembic migrations
|
|
- 📝 **Comprehensive API Documentation**: Auto-generated OpenAPI/Swagger docs
|
|
- 🌐 **CORS Support**: Cross-origin resource sharing enabled
|
|
- ⚡ **Health Checks**: Built-in health monitoring endpoint
|
|
|
|
## Task Properties
|
|
|
|
Each task includes:
|
|
- **Title**: Task name (required, max 255 characters)
|
|
- **Description**: Optional detailed description
|
|
- **Status**: `pending`, `in_progress`, or `completed`
|
|
- **Priority**: `low`, `medium`, or `high`
|
|
- **Due Date**: Optional deadline
|
|
- **Timestamps**: Auto-generated creation and update times
|
|
|
|
## API Endpoints
|
|
|
|
### Tasks
|
|
- `GET /tasks/` - List all tasks with optional filtering
|
|
- `POST /tasks/` - Create a new task
|
|
- `GET /tasks/{id}` - Get a specific task
|
|
- `PUT /tasks/{id}` - Update a task
|
|
- `DELETE /tasks/{id}` - Delete a task
|
|
- `GET /tasks/stats/summary` - Get task statistics
|
|
|
|
### System
|
|
- `GET /` - API information and links
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /docs` - Interactive API documentation (Swagger UI)
|
|
- `GET /redoc` - Alternative API documentation
|
|
- `GET /openapi.json` - OpenAPI schema
|
|
|
|
## Quick Start
|
|
|
|
1. **Install Dependencies**
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. **Run Database Migrations**
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. **Start the Server**
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
4. **Access the Application**
|
|
- API: http://localhost:8000
|
|
- Documentation: http://localhost:8000/docs
|
|
- Health Check: http://localhost:8000/health
|
|
|
|
## API Usage Examples
|
|
|
|
### Create a Task
|
|
```bash
|
|
curl -X POST "http://localhost:8000/tasks/" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"title": "Complete project documentation",
|
|
"description": "Write comprehensive README and API docs",
|
|
"priority": "high",
|
|
"status": "pending"
|
|
}'
|
|
```
|
|
|
|
### Get All Tasks
|
|
```bash
|
|
curl "http://localhost:8000/tasks/"
|
|
```
|
|
|
|
### Filter Tasks
|
|
```bash
|
|
# Get high priority tasks
|
|
curl "http://localhost:8000/tasks/?priority=high"
|
|
|
|
# Get completed tasks
|
|
curl "http://localhost:8000/tasks/?status=completed"
|
|
|
|
# Search tasks
|
|
curl "http://localhost:8000/tasks/?search=documentation"
|
|
```
|
|
|
|
### Update a Task
|
|
```bash
|
|
curl -X PUT "http://localhost:8000/tasks/1" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"status": "completed"
|
|
}'
|
|
```
|
|
|
|
### Get Task Statistics
|
|
```bash
|
|
curl "http://localhost:8000/tasks/stats/summary"
|
|
```
|
|
|
|
## Database
|
|
|
|
The application uses SQLite with the following configuration:
|
|
- **Database Location**: `/app/storage/db/db.sqlite`
|
|
- **Migration Tool**: Alembic
|
|
- **Schema Management**: Automatic table creation and migrations
|
|
|
|
## Environment Variables
|
|
|
|
Currently, no environment variables are required. The application uses SQLite with a fixed path for simplicity.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
/
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── alembic/ # Database migrations
|
|
│ ├── env.py
|
|
│ └── versions/
|
|
├── app/
|
|
│ ├── api/
|
|
│ │ └── tasks.py # Task API routes
|
|
│ ├── crud/
|
|
│ │ └── task.py # Database operations
|
|
│ ├── db/
|
|
│ │ ├── base.py # SQLAlchemy base
|
|
│ │ └── session.py # Database connection
|
|
│ ├── models/
|
|
│ │ └── task.py # Database models
|
|
│ └── schemas/
|
|
│ └── task.py # Pydantic schemas
|
|
└── storage/
|
|
└── db/ # SQLite database files
|
|
```
|
|
|
|
## Development Commands
|
|
|
|
```bash
|
|
# Install dependencies
|
|
pip install -r requirements.txt
|
|
|
|
# Run migrations
|
|
alembic upgrade head
|
|
|
|
# Start development server
|
|
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
|
|
# Run linting
|
|
python -m ruff check . --fix
|
|
```
|
|
|
|
## Technologies Used
|
|
|
|
- **FastAPI**: Modern Python web framework
|
|
- **SQLAlchemy**: SQL toolkit and ORM
|
|
- **Alembic**: Database migration tool
|
|
- **Pydantic**: Data validation using Python type hints
|
|
- **SQLite**: Lightweight database
|
|
- **Uvicorn**: ASGI server
|
|
- **Ruff**: Fast Python linter
|
|
|
|
Built with BackendIM - AI-powered backend development assistant.
|