
- Add SQLAlchemy models for Todo with timestamps - Create Pydantic schemas for request/response validation - Implement CRUD operations for Todo management - Add REST API endpoints for todo operations (GET, POST, PUT, DELETE) - Configure SQLite database with proper connection settings - Set up Alembic migrations for database schema management - Add comprehensive API documentation and health check endpoint - Enable CORS for all origins - Include proper error handling and HTTP status codes - Update README with complete setup and usage instructions
126 lines
2.9 KiB
Markdown
126 lines
2.9 KiB
Markdown
# Todo App API
|
|
|
|
A simple Todo application API built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- ✅ Create, read, update, and delete todos
|
|
- ✅ SQLite database with SQLAlchemy ORM
|
|
- ✅ Database migrations with Alembic
|
|
- ✅ API documentation with Swagger UI
|
|
- ✅ Health check endpoint
|
|
- ✅ CORS enabled for all origins
|
|
- ✅ Input validation with Pydantic
|
|
|
|
## Quick Start
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
|
|
### Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. Start the development server:
|
|
```bash
|
|
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
|
```
|
|
|
|
Or alternatively:
|
|
```bash
|
|
python main.py
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
The API is available at `http://localhost:8000`
|
|
|
|
### Documentation
|
|
- **Swagger UI**: http://localhost:8000/docs
|
|
- **ReDoc**: http://localhost:8000/redoc
|
|
- **OpenAPI JSON**: http://localhost:8000/openapi.json
|
|
|
|
### Core Endpoints
|
|
- **GET** `/` - Root endpoint with project information
|
|
- **GET** `/health` - Health check endpoint
|
|
|
|
### Todo Endpoints
|
|
- **GET** `/api/v1/todos/` - List all todos (with pagination)
|
|
- **POST** `/api/v1/todos/` - Create a new todo
|
|
- **GET** `/api/v1/todos/{todo_id}` - Get a specific todo
|
|
- **PUT** `/api/v1/todos/{todo_id}` - Update a specific todo
|
|
- **DELETE** `/api/v1/todos/{todo_id}` - Delete a specific todo
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`.
|
|
|
|
### Schema
|
|
|
|
**todos** table:
|
|
- `id` (Integer, Primary Key)
|
|
- `title` (String, Required)
|
|
- `description` (String, Optional)
|
|
- `completed` (Boolean, Default: False)
|
|
- `created_at` (DateTime with timezone)
|
|
- `updated_at` (DateTime with timezone)
|
|
|
|
## Development
|
|
|
|
### Linting and Formatting
|
|
|
|
```bash
|
|
# Check and fix linting issues
|
|
ruff check . --fix
|
|
|
|
# Format code
|
|
ruff format .
|
|
```
|
|
|
|
### Database Migrations
|
|
|
|
```bash
|
|
# Create a new migration
|
|
alembic revision --autogenerate -m "Description of changes"
|
|
|
|
# Apply migrations
|
|
alembic upgrade head
|
|
|
|
# Downgrade
|
|
alembic downgrade -1
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── app/
|
|
│ ├── api/
|
|
│ │ └── v1/
|
|
│ │ ├── api.py # API router
|
|
│ │ └── todos.py # Todo endpoints
|
|
│ ├── core/
|
|
│ │ └── config.py # Configuration settings
|
|
│ ├── crud/
|
|
│ │ └── todo.py # CRUD operations
|
|
│ ├── db/
|
|
│ │ ├── base.py # SQLAlchemy base
|
|
│ │ ├── base_model.py # Model imports
|
|
│ │ └── session.py # Database session
|
|
│ ├── models/
|
|
│ │ └── todo.py # SQLAlchemy models
|
|
│ └── schemas/
|
|
│ └── todo.py # Pydantic schemas
|
|
├── migrations/ # Alembic migrations
|
|
├── main.py # FastAPI application
|
|
└── requirements.txt # Python dependencies
|
|
```
|