2025-06-12 19:05:38 +00:00

133 lines
2.9 KiB
Markdown

# Task Management Tool
A RESTful API for managing tasks, built with FastAPI and SQLite.
## Features
- User registration and authentication with JWT
- CRUD operations for tasks
- Task filtering, sorting, and pagination
- Health check endpoint
## Requirements
- Python 3.8+
- Dependencies listed in `requirements.txt`
## Environment Variables
The application uses the following environment variables:
- `SECRET_KEY` - Secret key for JWT token generation (default: a development key, must be changed in production)
- `ACCESS_TOKEN_EXPIRE_MINUTES` - Expiration time for JWT tokens in minutes (default: 30)
## Installation and Setup
1. Clone the repository
2. Create a virtual environment and activate it
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies
```bash
pip install -r requirements.txt
```
4. Run database migrations
```bash
alembic upgrade head
```
5. Start the server
```bash
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
## API Documentation
The API documentation is available at `/docs` or `/redoc` when the server is running.
### Base URL
```
http://localhost:8000/api/v1
```
### Authentication
The API uses JWT for authentication. To obtain a token, send a POST request to `/api/v1/auth/login` with your email and password.
```bash
curl -X 'POST' \
'http://localhost:8000/api/v1/auth/login' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=your@email.com&password=yourpassword'
```
### Endpoints
#### Authentication
- `POST /auth/register` - Register a new user
- `POST /auth/login` - Login and get access token
#### Users
- `GET /users/me` - Get current user information
- `PUT /users/me` - Update current user information
#### Tasks
- `GET /tasks` - List all tasks (with optional filtering and sorting)
- `POST /tasks` - Create a new task
- `GET /tasks/{task_id}` - Get a specific task
- `PUT /tasks/{task_id}` - Update a specific task
- `DELETE /tasks/{task_id}` - Delete a specific task
#### Filtering and Sorting Tasks
Tasks can be filtered and sorted using query parameters:
- `is_completed` - Filter by completion status (true/false)
- `priority` - Filter by priority (1=Low, 2=Medium, 3=High)
- `sort_by` - Sort by field (created_at, due_date, priority, title)
- `sort_order` - Sort order (asc/desc)
- `skip` - Number of items to skip (for pagination)
- `limit` - Maximum number of items to return (for pagination)
Example:
```
GET /tasks?is_completed=false&priority=3&sort_by=due_date&sort_order=asc&skip=0&limit=10
```
## Health Check
The API provides a health check endpoint at `/health`.
## Development
### Running Tests
```bash
pytest
```
### Database Migrations
Create a new migration:
```bash
alembic revision --autogenerate -m "Description of changes"
```
Apply migrations:
```bash
alembic upgrade head
```
Revert migrations:
```bash
alembic downgrade -1
```