FastAPI. Article Guide here
- User Registration: Users can create an account.
- User Login: Users can log in to their accounts.
- Role-based Authentication: Three roles with different permission levels - regular user, user manager, admin.
- CRUD Operations: Users can create, read, update, and delete their owned records.
- User Manager: User managers can CRUD users.
- Admin: Admins can CRUD all records and users.
- Entry Information: Each entry has a date, time, text, and number of calories.
- Calories API Integration: If calories are not provided, the API connects to a Calories API provider to fetch the number of calories for the entered meal.
- User Setting: Users can set their expected number of calories per day.
- Calorie Comparison: Each entry has a boolean field indicating if the total calories for the day are less than the expected number of calories.
- JSON API: Data is returned in JSON format.
- Filtering and Pagination: Endpoints provide filter capabilities and support pagination.
- Unit and E2E Tests: Includes unit tests and end-to-end tests.
- Python Web Framework: Uses any Python web framework.
- SQLite Database: Uses SQLite as the database.
git clone https://github.com/dxphilo/octo.git
Create a file named .env in the root directory of your project.
cp .env.example .env
pip install -r requirements.txt
python create_db.py
Application will be exposed to port 8000 on http://localhost:8000/
python main.py
Running tests.
will run all test suites
pytest
You can run specific test file, i,e
To run entry specific tests
pytest -k test_entry_api.py
To run user specific tests
pytest -k test_user_api.py
To run utility specific tests
pytest -k test_helpers.py
Open the API documentation in your browser by visiting http://localhost:8000/docs.
The following endpoints are available in the API:
Send token in the form:
Authorization: Bearer <your-token-here>
- Endpoint:
/signup/
- Method:
POST
- Request Body:
fullname
(string): Full name of the user (required)email
(string): Email of the user (required)password
(string): Password of the user (required)role
(string): Role of the user (required)
- Response:
id
(integer): ID of the created userfullname
(string): Full name of the created useremail
(string): Email of the created userrole
(string): Role of the created userdate
(string): Current datetime
(string): Current time
- Endpoint:
/login/
- Method:
POST
- Request Body:
email
(string): Email of the user (required)password
(string): Password of the user (required)
- Response:
access_token
(string): JWT access token for authentication
- Endpoint:
/users/
- Method:
GET
- Headers:
Authorization
(string): JWT access token (required)
- Response:
- List of user objects:
id
(integer): ID of the userfullname
(string): Full name of the useremail
(string): Email of the userrole
(string): Role of the userdate
(string): Current datetime
(string): Current time
- List of user objects:
- Endpoint:
/users/{user_id}/
- Method:
PUT
- Path Parameters:
user_id
(integer): ID of the user to update (required)
- Request Body:
fullname
(string): New full name of the user (required)email
(string): New email of the user (required)password
(string): New password of the user (required)role
(string): New role of the user (required)
- Headers:
Authorization
(string): JWT access token (required)
- Response:
id
(integer): ID of the updated userfullname
(string): New full name of the useremail
(string): New email of the userrole
(string): New role of the userdate
(string): Current datetime
(string): Current time
- Endpoint:
/users/{user_id}/
- Method:
DELETE
- Path Parameters:
user_id
(integer): ID of the user to delete (required)
- Headers:
Authorization
(string): JWT access token (required)
- Response:
message
(string): Deletion success message
- Endpoint:
/user/entries/
- Method:
POST
- Request Body:
text
(string): Entry text (required)tags
(list): List of entry tags
- Headers:
Authorization
(string): JWT access token (required)
- Response:
id
(integer): ID of the created entrytext
(string): Entry texttags
(list): List of entry tagsdate
(string): Current datetime
(string): Current time
- Endpoint:
/user/entries/
- Method:
GET
- Headers:
Authorization
(string): JWT access token (required)
- Response:
- List of entry objects:
id
(integer): ID of the entrytext
(string): Entry texttags
(list): List of entry tagsdate
(string): Current datetime
(string): Current time
- List of entry objects:
- Endpoint:
/user/entries/{entry_id}/
- Method:
GET
- Path Parameters:
entry_id
(integer): ID of the entry to retrieve (required)
- Headers:
Authorization
(string): JWT access token (required)
- Response:
id
(integer): ID of the entrytext
(string): Entry texttags
(list): List of entry tagsdate
(string): Current datetime
(string): Current time
- Endpoint:
/user/entries/{entry_id}/
- Method:
PUT
- Path Parameters:
entry_id
(integer): ID of the entry to update (required)
- Request Body:
text
(string): New entry text (required)tags
(list): New list of entry tags
- Headers:
Authorization
(string): JWT access token (required)
- Response:
id
(integer): ID of the updated entrytext
(string): New entry texttags
(list): New list of entry tagsdate
(string): Current datetime
(string): Current time
- Endpoint:
/user/entries/{entry_id}/
- Method:
DELETE
- Path Parameters:
entry_id
(integer): ID of the entry to delete (required)
- Headers:
Authorization
(string): JWT access token (required)
- Response:
message
(string): Deletion success message
Contributions are welcome! If you encounter any issues or have suggestions for improvement, please create an issue or submit a pull request.
This project is licensed under the MIT License.