This is a simple Task Management application built with FastAPI, allowing you to manage your tasks efficiently. You can create, view, update, and filter tasks based on various criteria.
The project is structured as follows:
Task-Management/
├── repository/
│ ├── __init__.py
│ ├── task.py
│ └── user.py
├── routers/
│ ├── __init__.py
│ ├── authentication.py
│ ├── task.py
│ └── user.py
├── __init__.py
├── .env
├── database.py
├── hashing.py
├── main.py
├── models.py
├── oauth2.py
├── requirements.txt
├── schemas.py
├── test_main.py
└── token_manager.py
-
repository/: This directory contains modules for database interactions and data models. task.py and user.py define the database models for tasks and users. -
routers/: This directory contains modules that define API endpoints and request handling logic.authentication.py,task.py, anduser.pyhandle various API endpoints and their functionality. -
.env: This file can be used to store environment variables and configuration settings. -
database.py: This module is responsible for configuring the database connection. -
hashing.py: This module provides functions for hashing and verifying passwords. -
main.py: This is the entry point of the FastAPI application where the FastAPIFastAPIinstance is created and configured. -
models.py: This module defines the data models used in the application. -
oauth2.py: This module contains OAuth2-related functions for user authentication. -
requirements.txt: This file lists the required Python packages and their versions. -
schemas.py: This module defines Pydantic schemas used for data validation and serialization. -
test_main.py: Unit test suite for the application - This file contains unit tests and is used for testing the application's functionality at the unit level. -
token_manager.py: This module manages JWT (JSON Web Token) creation and validation for authentication.
- Python 3.9
- pip (Python package manager)
- Clone the repository:
git clone https://github.com/yourusername/task-management-app.git cd task-management-app - Create and activate a virtual environment:
virtualenv venv python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install the required Python packages:
pip install -r requirements.txt
- Ensure you are in the project directory and the virtual environment is activated.
- Run the FastAPI development server:
uvicorn main:app --reload
This will start the FastAPI application on http://localhost:8000.
- Endpoint: /tasks
- Method: GET
- Parameters:
page: Page number (default is 1)per_page: Items per page (default is 10)finished: Filter by finished tasks (True/False/None for all)created_at_start: Filter tasks created after this date (YYYY-MM-DD)created_at_end: Filter tasks created before this date (YYYY-MM-DD)finished_at_start: Filter tasks finished after this date (YYYY-MM-DD)finished_at_end: finished_at_end- Response: List of tasks matching the criteria.
- Endpoint: /tasks/{id}
- Method: GET
- Parameters: id - Task ID
- Response: Details of the task with the specified ID.
- Endpoint: /tasks/{id}/finished
- Method: PUT
- Parameters: id - Task ID
- Response: Updated task status.
- Endpoint: /tasks
- Method: POST
- Request Body: Task details (title and description)
- Response: Created task details.
- Endpoint: /tasks/{id}
- Method: PUT
- Parameters: id - Task ID
- Request Body: Updated task details (title, description, and finished status)
- Response: Updated task details.
- Endpoint: /tasks/{id}
- Method: DELETE
- Parameters: id - Task ID
- Response: No content (204) upon successful deletion.
- Endpoint: /user
- Method: POST
- Request Body: User details (user_name, email, and password)
- Response: Created user details.
-
Endpoint: /login
-
Method: POST
-
Request Body: User login details (username and password)
-
Response: Access token for authentication.
Note: Authentication is required for all endpoints except User Login.
Run the following command to execute unit tests:
pytest -s
- Using FastAPI Documentation :
Just navigate to http://127.0.0.1:8000/docs# to access the FastAPI documentation.
- Using Postman :
Get Tasks filtred by creating date










