- clone the repository
git clone --recursive https://github.com/NAB-TAG/nortbook-api2.git
- It is required to have docker desktop installed and started
- open a terminal
- Navigate to the project directory
cd route/to/project
- Crea y levanta los contenedores
docker-compose up -d
- once finished install the dependencies using laravel
docker-compose exec myapp composer install
- now copy the .env.example and copy and paste it into a new file called .env
- now create an api key
docker-compose exec myapp php artisan key:generate
- make the migrations and plant the seeds
docker-compose exec app php artisan migrate:refresh docker-compose exec app php artisan db:seed
- everything is ready to use!!!
This project is a Laravel and MySQL-based backend application for managing a digital library. It includes user authentication, CRUD operations for books and reviews, search functionality, and optional features such as Dockerization. The system adheres to best practices for code clarity, maintainability, security, and error handling.
- users:
- id (unique)
- name (string, max: 100)
- pseudonym (string, max: 100)
- email (unique, email)
- password (password, max: 200)
-
books:
- id (unique)
- title (string, max: 100)
- author (string)
- publication_year (int)
-
reviews:
- id (unique)
- user_id (int)
- book_id (int)
- review_text (string, max: 625)
- rating (int)
Note: For methods PUT, DELETE, and POST, the response format will be an array of strings with three elements: [ "type", "title", "message" ]. This is designed particularly for handling response messages with SweetAlert2
- Endpoint: '/api/register'
- Method: POST
- Description: Registers a new user.
- Parameters:
- name (string)
- pseudonym (string)
- email (email)
- password (string)
- confirmation_password (string)
- Responses
- 201: Successful registration.
- 422: I do not spend a validation.
- 500: Error on the server.
- Endpoint: '/api/login'
- Method: POST
- Description: Login a user. Copy the token generated and paste it in the BearerToken in all request to simulate a connected user
- Parameters:
- email (email)
- password (string)
- Responses
- 201: Log in successful.
- 401: You do not have permissions for this action
- 422: I do not spend a validation.
- Endpoint: '/api/logout'
- Method: GET
- Description: Close the session by deleting the cookies used by the front en developer.
- Parameters:
- none
- Responses
- 200: Log out successful.
- Endpoint: '/api/user_profile'
- Method: GET
- Description: Shows you the connected user
- Parameters:
- none
- Responses
- 200:
{ "id": 1, "name": "Nando Agustin Bravo", "email": "[email protected]", "email_verified_at": null, "created_at": "2024-01-16T17:46:34.000000Z", "updated_at": "2024-01-16T17:46:34.000000Z" }
- 401: incorrect password and/or email
- 200:
- Endpoint: '/api/decrypt'
- Method: GET
- Description: Decrypt the cookie used by the front-end developer for later use
- Parameters:
- none
- Responses
- 200:
['3|PgfmOAy9K5shxAIVzWcQA4nHPHavD9xBApFAvUQj75b1b8aa']
- 200:
- Endpoint: '/api/book/create'
- Method: POST
- Description: Create a book
- Parameters:
- title (string)
- publication_year (integer)
- Responses
- 201: successful book creation.
- 403: There is no user logged in
- 422: I do not spend a validation.
- 500: Error on the server.
- Endpoint: '/api/book/edit/{id}'
- Method: PUT
- Description: Update a specific book
- Parameters:
- title (string)
- publication_year (integer)
- Responses
- 201: successful book creation.
- 403: There is no user logged in
- 422: I do not spend a validation.
- 500: Error on the server.
- Endpoint: '/api/books'
- Method: GET
- Description: show all books in a laravel page
- Parameters:
- none
- Responses
- 200:
{ "current_page": 1, "data": [ { "id": 1, "title": "Harry Potter", "author": "Nando Agustin Bravo", "publication_year": 2000, "created_at": "2024-01-18T13:40:21.000000Z", "updated_at": "2024-01-18T13:40:21.000000Z" } ], "first_page_url": "http://localhost:8000/api/books?page=1", "from": 1, "last_page": 1, "last_page_url": "http://localhost:8000/api/books?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://localhost:8000/api/books?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://localhost:8000/api/books", "per_page": 12, "prev_page_url": null, "to": 1, "total": 1
- 200:
- Endpoint: '/api/books/{search}'
- Method: GET
- Description: show all books that match the search (author, title, publication_year) on a Laravel page
- Parameters:
- none
- Responses
- 200:
{ "current_page": 1, "data": [ { "id": 1, "title": "Harry Potter", "author": "Nando Agustin Bravo", "publication_year": 2000, "created_at": "2024-01-18T13:40:21.000000Z", "updated_at": "2024-01-18T13:40:21.000000Z" } ], "first_page_url": "http://localhost:8000/api/books?page=1", "from": 1, "last_page": 1, "last_page_url": "http://localhost:8000/api/books?page=1", "links": [ { "url": null, "label": "« Previous", "active": false }, { "url": "http://localhost:8000/api/books?page=1", "label": "1", "active": true }, { "url": null, "label": "Next »", "active": false } ], "next_page_url": null, "path": "http://localhost:8000/api/books", "per_page": 12, "prev_page_url": null, "to": 1, "total": 1
- 200:
- Endpoint: '/api/book/delete/{id}'
- Method: DELETE
- Description: Delete a specific book
- Parameters:
- none
- Responses
- 201: deleted successful book.
- 403: There is no user logged in
- 500: Error on the server.
- Endpoint: '/api/reviews/book/{id_book}'
- Method: GET
- Description: Show reviews of a certain book
- Parameters:
- none
- Responses
- 200:
[ { "id": 1, "user_id": 1, "book_id": 1, "review_text": "Muy bueno", "rating": 3, "created_at": "2024-01-18T14:07:42.000000Z", "updated_at": "2024-01-18T14:07:42.000000Z" } ]
- Endpoint: '/api/reviews/create/{id_book}'
- Method: POST
- Description: create a review for a specific book
- Parameters:
- review_text (string)
- rating (int)
- Responses
- 201: successful review creation.
- 403: There is no user logged in
- 422: I do not spend a validation.
- 500: Error on the server.
- Endpoint: '/api/reviews/edit/{id_book}'
- Method: PUT
- Description: Update a review for a specific book
- Parameters:
- review_text (string)
- rating (int)
- Responses
- 201: successful review update.
- 403: There is no user logged in
- 422: I do not spend a validation.
- 500: Error on the server.
- 505: You did not publish this review
- Endpoint: '/api/reviews/delete/{id_book}'
- Method: DELETE
- Description: Delete a review for a specific book
- Parameters:
- none
- Responses
- 201: successful review update.
- 403: There is no user logged in
- 422: I do not spend a validation.
- 500: Error on the server.
- 505: You did not publish this review