Product aggregator microservice BE

This app was created based on requirements from company Applifting. Main goal was to create a REST API JSON Python microservice which allows users to browse a product catalog and which automatically updates prices from the offer service (provided by Applifting).

Stack

  • Python 3.10
  • FastAPI
  • SQLModel
  • PostgreSQL

Deployment

Application was deployed in form of Docker image to Heroku. App is accessible on this link

https://applifting-product-aggregator.herokuapp.com/docs

How to run locally

  1. Clone the repository
  2. Run following command to build and run containers of app and postgres db
docker-compose up --build
  1. Go to your browser and type following
localhost:8080/docs
  1. You should see SwaggerUI with all application endpoints ready to be tested Main screen

Product aggregator API

Endpoints HTTP method Description
/login POST Login admin
/products POST Create new product
/products GET Get all products
/products/{id} GET Get selected product
/products/{id} PATCH Update product description
/products/{id} DELETE Delete selected product

User workflow

Application divides between two user roles:

  • Admin: After successful authentication, JWT token is generated. Token can be used to gain authorization for creation/update/deletion of products in database.
    • default username: admin
    • default password: admin
    • default token expiration time: 5 mins JWT Token
  • General customer: Can get list of products and specific product with its actual offers.

Requirements

  • Provide an API to create, update and delete a product
  • Periodically query the provided microservice for offers/shops with products
  • Provide an API to get product offers
  • Data models:
    • Product - id, name, description
    • Offer - id, price, items_in_stock
  • Use an SQL database as an internal database
  • Request an access token from the offers microservice
  • Provide this token for all calls to the Offers microservice.
  • Once a new Product is created, call the Offers microservice to register it
  • Create a background (job) service which periodically calls the Offers
  • Create a read-only API for product offers
  • Base URL for the Offers MS should be configurable via an environment variable
  • Write basic tests with pytest
  • Push your code into a public repo on GitHub
  • Add a README with information on how to start and use your service
  • JSON REST API simple authentication (eq.: access-token)
  • Consider adding some reasonable error handling to the API layer
  • Provide a working Dockerfile and docker-compose.yml for your application for easy testing
  • Use reasonable dependency management
  • Deploy your application to Heroku