
- Added filtering and pagination for todo listings - Fixed Alembic migration setup - Enhanced CRUD operations - Updated documentation with comprehensive README - Linted code with Ruff
146 lines
3.4 KiB
Markdown
146 lines
3.4 KiB
Markdown
# TodoApp API - FastAPI Backend
|
|
|
|
A robust, RESTful API for managing todos, built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- 🔐 JWT Authentication
|
|
- 📝 Todo CRUD operations
|
|
- 👤 User management
|
|
- 🔍 Advanced todo filtering and pagination
|
|
- 📄 API documentation (via Swagger UI and ReDoc)
|
|
- 🔄 Database migrations (Alembic)
|
|
|
|
## Requirements
|
|
|
|
- Python 3.8+
|
|
- FastAPI
|
|
- SQLAlchemy
|
|
- Alembic
|
|
- Pydantic
|
|
- SQLite
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
Start the server with:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000.
|
|
|
|
- API Documentation: http://localhost:8000/docs
|
|
- Alternative Documentation: http://localhost:8000/redoc
|
|
- OpenAPI Schema: http://localhost:8000/openapi.json
|
|
- Health Check: http://localhost:8000/health
|
|
|
|
## Environment Variables
|
|
|
|
The application can be configured using the following environment variables:
|
|
|
|
| Variable | Description | Default |
|
|
|----------|-------------|---------|
|
|
| SECRET_KEY | Secret key for JWT encoding | Auto-generated |
|
|
| ACCESS_TOKEN_EXPIRE_MINUTES | JWT token expiration time (minutes) | 11520 (8 days) |
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
|
|
- `POST /api/v1/auth/register` - Register a new user
|
|
- `POST /api/v1/auth/login` - Login and get access token
|
|
|
|
### Users
|
|
|
|
- `GET /api/v1/users/` - List all users
|
|
- `GET /api/v1/users/me` - Get current user details
|
|
- `PUT /api/v1/users/me` - Update current user
|
|
- `GET /api/v1/users/{user_id}` - Get user by ID
|
|
|
|
### Todos
|
|
|
|
- `GET /api/v1/todos/` - List todos (with filtering and pagination)
|
|
- `POST /api/v1/todos/` - Create a new todo
|
|
- `GET /api/v1/todos/{id}` - Get todo by ID
|
|
- `PUT /api/v1/todos/{id}` - Update a todo
|
|
- `DELETE /api/v1/todos/{id}` - Delete a todo
|
|
|
|
#### Todo Filtering
|
|
|
|
The `GET /api/v1/todos/` endpoint supports the following query parameters:
|
|
|
|
- `skip`: Number of records to skip (default: 0)
|
|
- `limit`: Maximum number of records to return (default: 100)
|
|
- `title`: Filter by title (contains search)
|
|
- `is_completed`: Filter by completion status (true/false)
|
|
|
|
## Database Schema
|
|
|
|
### User Model
|
|
|
|
```
|
|
id: Integer (Primary Key)
|
|
email: String (Unique, Indexed)
|
|
hashed_password: String
|
|
is_active: Boolean (Default: True)
|
|
```
|
|
|
|
### Todo Model
|
|
|
|
```
|
|
id: Integer (Primary Key)
|
|
title: String (Indexed)
|
|
description: Text (Optional)
|
|
is_completed: Boolean (Default: False)
|
|
owner_id: Integer (Foreign Key to User)
|
|
```
|
|
|
|
## Development
|
|
|
|
### Code Structure
|
|
|
|
- `app/`: Main application package
|
|
- `api/`: API routes and dependencies
|
|
- `core/`: Core functionality (config, security)
|
|
- `crud/`: CRUD operations
|
|
- `db/`: Database setup and session management
|
|
- `models/`: SQLAlchemy models
|
|
- `schemas/`: Pydantic schemas
|
|
- `storage/`: Storage for database and other files
|
|
- `migrations/`: Alembic migrations
|
|
- `main.py`: Application entry point
|
|
|
|
### Adding New Models
|
|
|
|
1. Create a new model in `app/models/`
|
|
2. Import the model in `app/db/base_class.py`
|
|
3. Create corresponding Pydantic schemas in `app/schemas/`
|
|
4. Create CRUD operations in `app/crud/`
|
|
5. Create API endpoints in `app/api/v1/endpoints/`
|
|
6. Generate a new migration:
|
|
```bash
|
|
alembic revision -m "description"
|
|
```
|
|
7. Edit the migration file manually
|
|
8. Apply the migration:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
## License
|
|
|
|
MIT License |