Skip to content

Marketplace created with FastAPI, GraphQL, Docker and PostgreSQL as database

License

Notifications You must be signed in to change notification settings

iakigarci/FastAPI-GraphQL-Postgres

Repository files navigation


FastAPI-GraphQL-Postgres

Marketplace created with FastAPI, GraphQL, Docker and PostgreSQL as database

Connect with me:

iakigarci iakigarci

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

About The Project

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.

Tasks

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.

Data Structure

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)
}

Bonus Tasks

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.

(back to top)

Built With

The technologies used for this project are as follows:

  1. FastAPI: light API framwork. It was selected because it's has great performance, authentication and autogenerated documentation.
  2. SQLAlchemy: use Postgres as an ORM. The main features are version controling and database syncronization.
  3. Alembic:: use Postgres as an ORM, using to code to interact with the database.
  4. PostrgeSQL: booming database, with help for its quick creation and maintenance
  5. Docker: to containerize PostgreSQL and PGAdmin4. TO-DO: containerize FastAPI

(back to top)

Getting Started

Prerequisites

Check if you have Python installed. For this project, Python version 3.7 has been used.

  • python
    python --version # Windows
    python3 --version # UNIX

Installation

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.

  1. Clone the repository
    git clone https://github.com/iakigarci/TechnicalInterview1.git
  2. Create Python virtual environmet
    python vevn .venv # Windows
    python3 venv .venv # Unix
  3. Activate the virtual environment
    source .venv/Scripts/activate
  4. Install project dependencies from requirements.txt file
    pip install -r requirements.txt
  5. Start Docker containers
    docker compose up
    docker ps # List containers, there must be 2

(back to top)

Usage

Follow these steps after performing the installation steps:

  1. Check that PostgreSQL is running. Go to localhost:5050 PG4Admin homepage
  2. Start the server with uvicorn
    cd src
    uvicorn main:app --reload
  3. Go to localhost:8000/graphql

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Iñaki García : [email protected]

Project Link: https://github.com/iakigarci/FastAPI-GraphQL-Postgres

(back to top)

About

Marketplace created with FastAPI, GraphQL, Docker and PostgreSQL as database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages