- Docker
- Python
- Django
- Django REST Framework
- JWT
- Swagger
- MySQL
Before running Docker, create a .env file in which you write the SECRET_KEY.
Run the project with Docker:
docker-compose up --build
Endpoints can be checked in Swagger and DRF.
-
Run docker containers
docker-compose up --build
-
Run pytest inside web container
python manage.py test
-
Create superuser
python manage.py createsuperuser
To create a superuser for Book-project application, use the following command::
- username: admin
- email: admin@admin.com
- password: admin (this easy password is intended solely for testing purposes)
- To test the APIs in Swagger, first, you need to log in to obtain an Access Token using the default user credentials: admin@admin.com as the email and admin as the password. Once you successfully log in, you will receive an "access_token." This token grants access to every API endpoint. In swagger add this acces token in JWT Bearer (not need to add prefix 'Bearer').
Go to swagger: /swagger/
- Get token from login endpoint:
- In Swagger use this endpoint:
Use default credentials email:
/login/
admin@admin.com
password:admin
(I added example data so you don't need to write anything in payload). Take token from response and add it to swagger 'Authorization JWT Bearer".
- In Swagger use this endpoint:
- Check existing permissions:
-
In Swagger use this POST endpoint:
api/user/permissions/
-
Before creating a user and putting the permissions on them, the frontend would look up permission IDs.
-
Don't forget to use "access token" in the "Authorization"
-
- Check all existing users:
- In Swagger use this POST endpoint:
The user creation with Administrator permission through this endpoint is disabled. With other roles, it is correct. Don't forget to use "access token" in the "Authorization".
/users/
- In Swagger use this POST endpoint:
- Check all existing users:
- In Swagger use this endpoint:
Don't forget to use "access token" in the "Authorization".
http://localhost:8000/api/v1/rooms/all/
- In Swagger use this endpoint:
- Create a book:
-
In Swagger use this POST endpoint:
/books/
-
Don't need to add any data to the payload because example data has already been included.
-
Don't forget to use "access token" in the "Authorization".
-
- Check all existing books:
- In Swagger use this GET endpoint:
/books/
- Don't forget to use "access token" in the "Authorization".
- In Swagger use this GET endpoint:
- Get specific book by ID:
- In Swagger use this endpoint:
/books/{id}/
- Don't forget to use "access token" in the "Authorization".
- In Swagger use this endpoint:
NOTE: Due to a lack of time, I didn't manage to do most of the tasks. So, improvements that can be made is:
- to create a fixture in which a default book and user are created. This way, before running the container for the second time, there would be no need to delete commands related to user creation.
- create logout endpoint
- to enhance the User model, I suggest making the password and other important functionalities more advanced
- depersonalizate user essential data after User is deleted
- etc.
Created by @enrika - feel free to contact me!