ToDo app with Django and django rest framework.
Project consists to allow a client applications to consume resources for a ToDo application. It is partly tested as only and was developed as showcase only.
How ToDo App Works:
- You can create a project
- one project can have many tasks also know as to-do's, shores.
- each task can have a title, description, deadline, priority, mark it as task done and can have many comments or reminders(dates)
-
- Installing Django API App
-
- Access and Interact with API Front-end app (django restframework)
- Available Endpoints
- Consuming resources example with Requests Python Library (Soon... probably never)
- Tests INFO
- Access Django Admin
- Access Database Client - Adminer
- Clone repository and go inside the repository folder "todo-app-django-rest-api"
git clone https://github.com/Fantaso/todo-app-django-rest-api.git
- Build the docker images with docker-compose package
docker-compose build
- Initialize database and create the database mapping used for persistance in the ToDo app. Docker-Compose was configured so the data created inside the container from the database service will be store in your repository's root dir. If you want the database data to be store in a docker volume, please go to the
docker-compose.yml
file and in the "Volume" section of thedb
service choose one or the other.
docker-compose run --rm api python manage.py makemigrations todo_api
- Apply the database mapping from the app to the database; migrate the database.
docker-compose run --rm api python manage.py migrate
- Create the containers from the docker images and run the services needed for the ToDo App.
docker-compose up
Once docker-compose is done downloading all images and none of the services failed after you have run the containers with docker-compose up
The api fron-end application should be running and you can access it in your web browser at http://0.0.0.0:8000/todo/ which will take you to the web app interface that will allow you interact and use the API via the web browser.
Endpoints are categorized by the database's table or models architecture. Models used for this example are:
- Project model
name
: project's nametask_ids
: Relationship back reference with Task model. a list of id's for each task that belongs to the project
- Task model
project
: Relationship with Project model. the id of the project it belongs to.title
: 'name your task'description
: Describe your task more in detail.deadline
: set a date for a deadline if you want.priority
: Set the priority level of the task. Choices available are: low, medium, high.is_done
: Used to mark the task as done. by default isFalse
.comment_ids
: Relationship back reference with Comment model. a list of id's for each comment that belongs to the task.reminder_ids
: Relationship back reference with Comment model. a list of id's for each reminder that belongs to the task.
- Comment model
comment
: add a quick comment or note to your tasktask
: Relationship with Task model. the id of the task it belongs to.
- Reminder model
date
: schedule a quick reminder to your tasktask
: Relationship with Task model. the id of the task it belongs to.
So, the database relationship between the models stays like this.
- a project can have many tasks (one-to-many)
- a task can have many comments and reminders (one-to-many)
URI Example: http://0.0.0.0:8000/todo/projects/<id>/
Available Methods | URI | |
---|---|---|
Project Endpoints | ||
1. | GET POST |
projects/ |
2. | GET PUT PATCH DELETE |
projects/<id>/ |
3. | GET POST |
projects/<id>/tasks/ |
4. | GET PUT PATCH DELETE |
projects/<id>/tasks/<id>/ |
5. | GET POST |
projects/<id>/tasks/<id>/comments/ |
6. | GET PUT PATCH DELETE |
projects/<id>/tasks/<id>/comments/<id>/ |
7. | GET POST |
projects/<id>/tasks/<id>/reminders/ |
8. | GET PUT PATCH DELETE |
projects/<id>/tasks/<id>/reminders/<id>/ |
Task Endpoints | ||
1. | GET POST |
tasks/ |
2. | GET PUT PATCH DELETE |
tasks/<id>/ |
3. | GET POST |
tasks/<id>/comments/ |
4. | GET PUT PATCH DELETE |
tasks/<id>/comments/<id>/ |
5. | GET POST |
tasks/<id>/reminders/ |
6. | GET PUT PATCH DELETE |
tasks/<id>/reminders/<id>/ |
Comment Endpoints | ||
1. | GET POST |
comments/ |
2. | GET PUT PATCH DELETE |
comments/<id>/ |
Reminder Endpoints | ||
1. | GET POST |
reminders/ |
2. | GET PUT PATCH DELETE |
reminders/<id>/ |
Each model model endpoints follows a pattern of CRUDL (Create, Retrieve, Update, Delete and List) and a http method is allow on the API for each action.
Let's take Comment endpoints as an example:
Method | URI | Description | |
---|---|---|---|
URI Example: | http://0.0.0.0:8000/todo/comments/<id>/ |
||
1. | GET |
comments/ |
Get a List of all Comments available |
2. | POST |
comments/ |
Create a comment |
3. | GET |
comments/<id>/ |
Retrieve a comment's details with the id of the comment in the uri section e.g. comments/2/ |
4. | PUT or PATCH |
comments/<id>/ |
Update a comment's details |
5. | DELETE |
comments/<id>/ |
Delete a comment |
This Pattern applied with to the Reminder endpoints shown in the previous table is also applied to all other Endpoints (Project, Task, Comment) and they are applied the same way in the nested relationships between the models. Example:
Method | URI | Description | |
---|---|---|---|
URI Example: | http://0.0.0.0:8000/todo/projects/<id>/tasks/<id> |
||
1. | GET |
projects/<id>/tasks/ |
Get a List of all Tasks available in a specific project. With project's id. e.g.: projects/2/tasks/ |
2. | POST |
projects/<id>/tasks/ |
Create a task for a specific project |
3. | GET |
projects/<id>/tasks/<id>/ |
Retrieve a task's details of a specific project |
4. | PUT or PATCH |
projects/<id>/tasks/<id>/ |
Update a task's details of a specific project |
5. | DELETE |
projects/<id>/tasks/<id>/ |
Delete a task of a specific project |
- Run the API ToDo app tests locally with:
docker-compose run --rm api python manage.py test
To find a pattern for naming the testing methods of the application and having the data necessary to test the API djangoapp a txtfile was created. This file contains two main tables:
- ENDPOINTS SUMMARY (Which is what's describe previously in USAGE -> AVAILABLE ENDPOINTS -> ENDPOINT LIST section)
- TESTS A table containing: Verbose name, Test method name, Http-methods, Reverse(name), Request(URI)
Legend | Table Column | Description |
---|---|---|
1 | Verbose name | Action of the method humanly named (not used in the app, just for better understanding of the table of endpoints) |
2 | Test method name | the test case unique name (used in the app in the tests.py file in the application)' |
3 | Http-methods | HTTP method to test' |
4 | Reverse(name) | the Django "reverse" function to get the relative URI path to be used in the request to test the endpoint (not including the base_path['http://...'])' |
5 | Request(url) | the relative path used to test URI. is the id of the object to be retrieved' |
Download the test.txt or find it in the repository's root folder with name test.txt
To access Django Admin you must create a user to login into the admin interface and manage and edit the database.
- Create the a user.
docker-compose run --rm api python manage.py createsuperuser
You will be prompted to add a username
and password
for your user.
- Visit in your web browser at http://0.0.0.0:8000/admin and enter the
username
andpassword
created in the previous step.
Access the database client at http://0.0.0.0:8080
You will be prompt to enter System, Server, Username, Password, Database which has been pre-configured within the docker-compose.yml
for the docker service named 'db'.
Login information:
- System =
PostgreSQL
- Server =
db
- Username =
todo-postgres
- Password =
todo-password
- Database =
todo-db
Technology Stack | ||
---|---|---|
Python | Back-End | |
Django | Web Framework | |
Django Rest Extension | API Django Extension | |
PostgreSQL | Database | |
Docker | Container | |
Docker-Compose | Container Manager | |
Adminer | Database Web Client |
Get in touch -–> fantaso.de