A FastAPI-based project for managing tasks, users, and execution logs, using Tortoise ORM and PostgreSQL. This API provides CRUD operations, task state management, error logging, and more.
- Features
- Installation
- Running the Project
- API Endpoints
- Swagger UI
- Screenshots
- Database Models
- Contributing
- License
- User, Machines, Files, and Metrics Management: CRUD operations for users, machines, files, and metrics.
- Task Management: Create, update, delete tasks, and manage their states.
- State Tracking: Group and filter tasks by their state.
- Error Simulation: Simulate errors and log them with detailed messages.
- Database Integration: Uses PostgreSQL with Tortoise ORM.
- Automatic Documentation: Swagger UI and ReDoc.
- Python 3.8+
- PostgreSQL
-
Clone the Repository:
git clone https://github.com/YOUR_USERNAME/API-ULOS-DB.git cd API-ULOS-DB
-
Create and Activate a Virtual Environment:
-
Windows:
python -m venv env .\env\Scripts\activate
-
macOS/Linux:
python -m venv env source env/bin/activate
-
-
Install Dependencies:
pip install -r requirements.txt
-
Configure the Database:
Create a
.env
file in the root folder with your database credentials:DATABASE_URL=postgres://username:password@localhost/ULOS_DB
-
Generate Database Schemas (First-Time Setup):
When running the project for the first time, you'll need to create the database schema. In your
main.py
file, setgenerate_schemas=True
in the Tortoise configuration:from tortoise.contrib.fastapi import register_tortoise register_tortoise( ... generate_schemas=True # Set to True for first-time setup ... )
After running the project for the first time, set
generate_schemas
toFalse
to avoid creating duplicates in the database:register_tortoise( ... generate_schemas=False # Set to False after initial setup ... )
Start the FastAPI server:
uvicorn main:app --reload
Visit the server at http://127.0.0.1:8000.
Note: If you're running the project for the first time, ensure that
generate_schemas=True
inmain.py
. After the initial run, change it toFalse
to prevent duplicate entries.
Here's a quick overview of the main endpoints:
Method | Endpoint | Description |
---|---|---|
POST |
/tasks/ |
Create a new task |
GET |
/tasks/{task_id} |
Get a task by ID |
PUT |
/tasks/{task_id} |
Update a task |
DELETE |
/tasks/{task_id} |
Delete a task |
PATCH |
/tasks/{task_id}/parsed_status |
Update parsed status |
PATCH |
/tasks/{task_id}/executed_status |
Update executed status |
PATCH |
/tasks/{task_id}/state |
Update state |
FastAPI provides an interactive Swagger UI to test the endpoints:
- Visit http://127.0.0.1:8000/docs for Swagger UI.
- Visit http://127.0.0.1:8000/redoc for ReDoc.
Please follow these steps:
-
Fork the repository.
-
Create a new branch:
git checkout -b feature/your-feature-name
-
Commit your changes:
git commit -m "Add your feature"
-
Push to the branch:
git push origin feature/your-feature-name
-
Open a Pull Request.
Carlos German Monroy Andrade
201728260