This is a back-end FastAPI application that has been dockerized with PostgreSQL and pgAdmin4. This application was made for a technical test at Estante Mágica, the application can register books, texts and images and generate magic keys for the books, which can then be used for searching them via the API.
FastAPI framework, high performance, easy to learn, fast to code, ready for production
- Linux or WSL version 2
- Docker and Docker Compose
- A web browser
Clone the repository:
git clone https://github.com/NixonMSilva/DesafioEstanteMagica
cd DesafioEstanteMagica
Create a .env file from the provided .env.example file,
Edit the .env file and set the required environment variables.
Start the application:
docker-compose up -d
Run the migrations:
docker-compose run app sh -c 'alembic upgrade head'
Open a web browser and navigate to http://localhost:8000/health-check to access the FastAPI application's status, or http://localhost:5050/ to access the pgAdmin4 interface.
The FastAPI application provides a RESTful API for managing books. The API supports the following endpoints:
- POST /book/add: Creates a new book in the database.
- GET /book/list/{magic_key}: Returns a single book with the specified Magic Key.
- POST /text/add: Creates a new text in the database, the id of the book the text refers to is passed via the body.
- POST /image/add: Creates a new image in the database, the id of the book the image refers to is passed via the body.
To interact with the API, you can use a tool like curl or a REST client like Insomnia or Postman.
pgAdmin4 is a web-based interface for managing PostgreSQL databases. To access the pgAdmin4 interface, open a web browser and navigate to http://localhost:5050/. Log in with the email and password specified in the .env file.
From the pgAdmin4 interface, you can create, view, and modify database objects like tables, views, and indexes.
In order to setup pgAdmin4 for usage, you need first to run the migrations, afterwars click on "Add New Server", there you'll be prompted to fill certain fields, it's recommended to use these settings:
- General/Name: database
- Connection/Host Name: postgresql
- Connection/Port: 5432
- Connection/Maintenance Database: As defined by the environment variable POSTGRES_DB
- Connection/Username: As defined by the environment variable POSTGRES_USER
- Connection/Password: As defined by the environment variable POSTGRES_PASSWORD
A parte principal da API não foi tão difícil de se fazer, os problemas maiores foram reservados na questão do armazenamento da imagem, preferi optar por armazená-la como dados binários no banco de dados enquanto não aprendo uma forma mais eficiente de trabalhar com arquivos no servidor utilizando esse framework.
No demais, a parte da containerização e dos testes unitários foram de muito aprendizado para mim, sinto que essa é a primeira vez que trabalhei de fato com esses conceitos sem ter ninguém para segurar as minhas mãos e considero o resultado satisfatório, embora não tenha conseguido implementar um teste unitário final (está comentado)
Contributions are welcome! If you find a bug or would like to suggest a new feature, please open an issue or submit a pull request.
This project is licensed under the MIT license.