Marketplace created with FastAPI, GraphQL, Docker and PostgreSQL as database
Table of Contents
This project is based on a real technical interview. There is a second branch, with a REST aproach. The exercise was the following:
As a marketplace we need to have an effective search engine to be able to offer our products.
Our ads are classified according to their material and composition (metals, plastics, ...).
In this test we want you to implement a textual search engine that allows us to search both in the materials and in the name of the ad, as long as it is available.
The main task is to implement the service for search and the ad detail.
The search will have as parameters the term entered by the user and the pagination (records per page and page number).
You can use REST, GraphQL, GRPC at your choice.
The quality of the code will be a major consideration in the exercise.
File ad.csv:
- id : UUID
- name: String
- amount: Integer
- price: Integer (Note: the price is multiplied by 100 to avoid decimals. ej : 150 -> 1,5 )
- material: String
SEARCH SERVICE
Parms:
- term : Search term , String
- perPage: Elements per page , Integer
- nPage: Page to show, Integer
Response body:
{
"ads":[
{
"id":"uuid-ad",
"name":"Test Ad",
"amount":15,
"price": 7,85
},...
],
"total":"n-total-ad",
"current": "current-page",
"nextPage": "next-page"
}
DETAIL SERVICE
Parms:
- id: add-uid
Response Body
{
"id":"uuid-ad",
"name":"Test Ad",
"amount":15,
"price": 7,85
"relatedAds":[{adModel...}] (same material)
}
As you have probably observed the data is a bit denormalised, as an bonus task we propose you to normalise the data in an Entity-Relationship model and implement the services with it. You can use any database you want for this purpose.
The technologies used for this project are as follows:
- FastAPI: light API framwork. It was selected because it's has great performance, authentication and autogenerated documentation.
- SQLAlchemy: use Postgres as an ORM. The main features are version controling and database syncronization.
- Alembic:: use Postgres as an ORM, using to code to interact with the database.
- PostrgeSQL: booming database, with help for its quick creation and maintenance
- Docker: to containerize PostgreSQL and PGAdmin4. TO-DO: containerize FastAPI
Check if you have Python installed. For this project, Python version 3.7 has been used.
- python
python --version # Windows python3 --version # UNIX
Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services.
- Clone the repository
git clone https://github.com/iakigarci/TechnicalInterview1.git
- Create Python virtual environmet
python vevn .venv # Windows python3 venv .venv # Unix
- Activate the virtual environment
source .venv/Scripts/activate
- Install project dependencies from
requirements.txt
filepip install -r requirements.txt
- Start Docker containers
docker compose up docker ps # List containers, there must be 2
Follow these steps after performing the installation steps:
- Check that PostgreSQL is running. Go to localhost:5050
- Start the server with uvicorn
cd src uvicorn main:app --reload
- Go to localhost:8000/graphql
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Iñaki García : [email protected]
Project Link: https://github.com/iakigarci/FastAPI-GraphQL-Postgres