163 lines
3.8 KiB
Markdown
163 lines
3.8 KiB
Markdown
# Task Manager API
|
|
|
|
A RESTful API for managing tasks, built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Task CRUD operations
|
|
- Task status and priority management
|
|
- Task completion tracking
|
|
- API documentation with Swagger UI and ReDoc
|
|
- Health endpoint for monitoring
|
|
|
|
## Tech Stack
|
|
|
|
- FastAPI: Modern, high-performance web framework for building APIs
|
|
- SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM)
|
|
- Alembic: Database migration tool
|
|
- SQLite: Lightweight relational database
|
|
- Pydantic: Data validation and settings management
|
|
- Uvicorn: ASGI server for FastAPI applications
|
|
|
|
## API Endpoints
|
|
|
|
### API Information
|
|
|
|
- `GET /`: Get API information and available endpoints
|
|
|
|
### Task Management
|
|
|
|
- `GET /tasks`: Get all tasks
|
|
- `POST /tasks`: Create a new task
|
|
- `GET /tasks/{task_id}`: Get a specific task
|
|
- `PUT /tasks/{task_id}`: Update a task
|
|
- `DELETE /tasks/{task_id}`: Delete a task
|
|
- `POST /tasks/{task_id}/complete`: Mark a task as completed
|
|
|
|
### Health and Diagnostic Endpoints
|
|
|
|
- `GET /health`: Application health check
|
|
- `GET /db-test`: Database connection diagnostic endpoint
|
|
|
|
## Example Curl Commands
|
|
|
|
### Create a new task
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/' \
|
|
-H 'accept: application/json' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"title": "Complete project documentation",
|
|
"description": "Write comprehensive documentation for the project",
|
|
"priority": "high",
|
|
"status": "todo",
|
|
"due_date": "2023-06-30T18:00:00.000Z",
|
|
"completed": false
|
|
}'
|
|
```
|
|
|
|
### Get all tasks
|
|
|
|
```bash
|
|
curl -X 'GET' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/' \
|
|
-H 'accept: application/json'
|
|
```
|
|
|
|
### Get a specific task
|
|
|
|
```bash
|
|
curl -X 'GET' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/1' \
|
|
-H 'accept: application/json'
|
|
```
|
|
|
|
### Update a task
|
|
|
|
```bash
|
|
curl -X 'PUT' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/1' \
|
|
-H 'accept: application/json' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"title": "Updated title",
|
|
"description": "Updated description",
|
|
"status": "in_progress"
|
|
}'
|
|
```
|
|
|
|
### Delete a task
|
|
|
|
```bash
|
|
curl -X 'DELETE' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/1' \
|
|
-H 'accept: application/json'
|
|
```
|
|
|
|
### Mark a task as completed
|
|
|
|
```bash
|
|
curl -X 'POST' \
|
|
'https://taskmanagerapi-ttkjqk.backend.im/tasks/1/complete' \
|
|
-H 'accept: application/json'
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
taskmanagerapi/
|
|
├── alembic/ # Database migrations
|
|
│ └── versions/ # Migration scripts
|
|
├── app/
|
|
│ ├── api/ # API endpoints
|
|
│ │ └── routers/ # API route definitions
|
|
│ ├── core/ # Core application code
|
|
│ ├── crud/ # CRUD operations
|
|
│ ├── db/ # Database setup and models
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ └── schemas/ # Pydantic schemas/models
|
|
├── main.py # Application entry point
|
|
└── requirements.txt # Project dependencies
|
|
```
|
|
|
|
## Database Configuration
|
|
|
|
The application is configured to use SQLite with the following database locations (in order of priority):
|
|
|
|
1. Path defined in the `DB_PATH` environment variable (if set)
|
|
2. `/app/db/db.sqlite` (production environment)
|
|
3. `./db/db.sqlite` (local development)
|
|
4. `/tmp/taskmanager/db.sqlite` (fallback)
|
|
|
|
The application automatically selects the first available and writable location from this list.
|
|
|
|
## Getting Started
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository
|
|
2. Install dependencies:
|
|
```
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
### Running Migrations
|
|
|
|
```
|
|
alembic upgrade head
|
|
```
|
|
|
|
### Starting the Application
|
|
|
|
```
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000
|
|
|
|
### API Documentation
|
|
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc |