The application is a Restful API that aims to manage information related to the operation of various libraries.
To run the application, follow these steps.
- Create your virtual environment:
python -m venv venv
- Active your venv:
# Linux:
source venv/bin/activate
# Windows (Powershell):
.\venv\Scripts\activate
# Windows (Git Bash):
source venv/Scripts/activate
- Install all requirements:
pip install -r requirements.txt
- Run the migrations:
python manage.py makemigrations
python manage.py migrate
- Run the server:
python manage.py runserver
- Access the documentation to view and test all routes
http://127.0.0.1:8000/api/docs/
-
USERNAME, USER EMAIL, USER CPF and LIBRARY CNPJ must be unique. With that, if someone tries to create a new user or library, the server will return the following message:
SERVER RETURN: Body: Format Json Status Code: 400 BAD REQUEST { "email": [ "This field must be unique." ], "cpf": [ "user with this cpf already exists." ], "username": [ "A user with that username already exists." ] }
{ "cnpj": [ "This field must be unique." ] }
-
If you are trying to create a new user or a new library and you forget a field or you typed something wrong in the field, the server will return the following message:
SERVER RETURN: Body: Format Json Status Code: 400 BAD REQUEST { "first_name": [ "This field is required." ], "cpf": [ "Ensure this field has no more than 11 characters." ] }
-
Some routes need authentication, if you try to access them and you don't have permission, the server will return this message:
SERVER RETURN: Body: Format Json Status Code: 403 Forbidden { "detail": "You do not have permission to perform this action." }
-
In routes that must be passed search parameters, they can return the following message if the parameter is not found.
SERVER RETRUN: Body: Format Json Status Code: 404 not found { "detail": "Not found." }
-
In login route, if you pass wrong USERNAME and/or wrong PASSWORD, the server is return:
SERVER RETURN: Body: Format Json Status Code: 401 Unauthorized { "detail": "No active account found with the given credentials" }
METHOD | ENDPOINTS | RESPONSIBILITY |
---|---|---|
GET | /libraries/ | List all libraries |
GET | /libraries/:id/ | List library by ID |
GET | /libraries/:id/books/ | List all library's books |
GET | /libraries/:id/loans/ | List all library's loans |
GET | /libraries/:id/employee/ | List all library's employees |
GET | /libraries/:id/users/block/ | List all library's users blocked |
POST | /libraries/create/ | Create a library |
PATCH | /libraries/:id/ | Update informations for library |
-
List all libraries
- Validation by token;
- Only general manager can list all libraries;
{ "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "name": "Library 1", "cnpj": "00000000000000", "email": "library@mail.com", "address": "Street, N, City/UF", "employees": [ { "id": 1, "first_name": "John", "last_name": "John", "email": "john@mail.com", "birth_date": "YYYY-mm-ddTHH:MM:SSZ", "cpf": "00000000000", "username": "John", "is_superuser": false, "image": "https://image.com/image.png" } ], "books": [ { "id": 1, "title": "O Poder do Hábito", "type": "saude", "author": "Charles Duhigg", "synopsis": "Charles Duhigg, repórter investigativo do New York Times, mostra que a chave para o sucesso é entender como os hábitos funcionam - e como podemos transformá-los.", "release_date": "2012-09-24", "publishing_company": "Objetiva", "add_at": "2023-07-08T13:43:51.433669Z", "quantity": 1, "copies": [ { "id": 1, "book": 1, "is_available": true } ] } ] } ] }
-
List library by ID
- Validation by Token;
- Only Admins and Employees can list them library;
{ "id": 1, "name": "Library 1", "cnpj": "00000000000000", "email": "library@mail.com", "address": "Street, N, City/UF", "employees": [ { "id": 1, "first_name": "John", "last_name": "John", "email": "john@mail.com", "birth_date": "YYYY-mm-ddTHH:MM:SSZ", "cpf": "00000000000", "username": "John", "is_superuser": false, "image": "https://image.com/image.png" } ], "books": [ { "id": 1, "title": "O Poder do Hábito", "type": "saude", "author": "Charles Duhigg", "synopsis": "Charles Duhigg, repórter investigativo do New York Times, mostra que a chave para o sucesso é entender como os hábitos funcionam - e como podemos transformá-los.", "release_date": "2012-09-24", "publishing_company": "Objetiva", "add_at": "2023-07-08T13:43:51.433669Z", "quantity": 1, "copies": [ { "id": 1, "book": 1, "is_available": true } ] } ] }
-
List all library's books
- Validation by token;
- Only authenticated users can list expecif library books;
{ "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "title": "O Poder do Hábito", "type": "saude", "author": "Charles Duhigg", "synopsis": "Charles Duhigg, repórter investigativo do New York Times, mostra que a chave para o sucesso é entender como os hábitos funcionam - e como podemos transformá-los.", "release_date": "2012-09-24", "publishing_company": "Objetiva", "add_at": "2023-07-08T13:43:51.433669Z", "quantity": 1, "copies": [ { "id": 1, "book": 1, "is_available": true } ] } ] }
-
List all library's employees
- Validation by token;
- Only authenticated users can list all library employees
{ "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "first_name": "John", "last_name": "John", "email": "john@mail.com", "birth_date": "YYYY-mm-ddTHH:MM:SSZ", "cpf": "00000000000", "username": "John", "is_superuser": false, "image": "https://image.com/image.png" } ] }
-
List all library's loans
- Validation by token;
- Only Admin and Employees can list all library loans;
- Administrators and employees can only list loans from your library;
{ "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "first_name": "John", "last_name": "John", "email": "john@mail.com", "birth_date": "YYYY-mm-ddTHH:MM:SSZ", "cpf": "00000000000", "username": "John", "is_superuser": false, "image": "https://image.com/image.png" } ] }
-
List all libraries loans
- Validation by token;
- Only Admins and Employees can list libraries blocked users;
- Administrators and employees can only list blocked users from your library;
{ "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "first_name": "John", "last_name": "John", "email": "john@mail.com", "birth_date": "YYYY-mm-ddTHH:MM:SSZ", "cpf": "00000000000", "username": "John", "is_superuser": false, "image": "https://image.com/image.png" } ] }
-
Create library
- Validation by token;
- Only general manager can create libraries;
{ "name": "Library 1", "cnpj": "00000000000000", "email": "library@mail.com", "address": "Street, N, City/UF" }
{ "id": 1, "name": "Library 1", "cnpj": "00000000000000", "email": "library@mail.com", "address": "Street, N, City/UF", "employees": [], "books": [] }
-
Update informations from library
- Validation by token;
- Only Admins can update library information;
- Admin can only update his library information;
{ "name": "Library2" }
{ "id": 1, "name": "Library 2", "cnpj": "00000000000000", "email": "library@mail.com", "address": "Street, N, City/UF", "employees": [], "books": [] }