Automated Action bd33c253b2 Fix database migration and path issues
- Fix Python path in migrations/env.py for proper imports
- Update database path to use relative project paths instead of /app
- Update alembic.ini to use relative database path
- Update README with correct database location and migration instructions

generated with BackendIM... (backend.im)
2025-05-13 12:42:03 +00:00

123 lines
2.5 KiB
Markdown

# Simple Todo Application
A simple Todo application API built with FastAPI, SQLAlchemy, and SQLite.
## Features
- Create, read, update, and delete todo items
- Filter todos by completion status
- Pagination support
- Health check endpoint
## Project Structure
```
simpletodoapplication/
├── app/
│ ├── __init__.py
│ ├── crud.py # CRUD operations
│ ├── database.py # Database configuration
│ ├── models.py # SQLAlchemy models
│ └── schemas.py # Pydantic schemas
├── migrations/ # Alembic migrations
├── alembic.ini # Alembic configuration
├── main.py # FastAPI application
└── requirements.txt # Project dependencies
```
## Installation
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```
## Database Setup
The application uses SQLite, and the database will be created automatically at `./storage/db/db.sqlite` relative to the project root when the application starts.
### Migrations
To run database migrations:
```bash
# Set the Python path to include the project root
export PYTHONPATH=/path/to/project
# Run migrations
alembic upgrade head
```
## Running the Application
```bash
uvicorn main:app --reload
```
The API will be available at http://localhost:8000
## API Documentation
Once the application is running, you can access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## API Endpoints
### Health Check
- `GET /health` - Check if the API is running
### Todo Operations
- `GET /todos/` - List all todos (supports pagination and filtering by completion status)
- `POST /todos/` - Create a new todo
- `GET /todos/{todo_id}` - Get a specific todo
- `PUT /todos/{todo_id}` - Update a todo
- `DELETE /todos/{todo_id}` - Delete a todo
## Example Usage
### Create a Todo
```bash
curl -X 'POST' \
'http://localhost:8000/todos/' \
-H 'Content-Type: application/json' \
-d '{
"title": "Buy groceries",
"description": "Milk, bread, eggs"
}'
```
### List All Todos
```bash
curl -X 'GET' 'http://localhost:8000/todos/'
```
### Get Completed Todos
```bash
curl -X 'GET' 'http://localhost:8000/todos/?completed=true'
```
### Update a Todo
```bash
curl -X 'PUT' \
'http://localhost:8000/todos/1' \
-H 'Content-Type: application/json' \
-d '{
"completed": true
}'
```
### Delete a Todo
```bash
curl -X 'DELETE' 'http://localhost:8000/todos/1'
```