Git Product home page Git Product logo

discount_codes_api's Introduction

Discount Codes Api ✈️

What it does?

It is a small part of a customer loyalty app. It has 2️⃣ microservices accessible via REST API: 1) Generate Discount Coderuns 2) Fetch discount code for a user.

What it consist of?

A development web server and two microservices ✈️

Development stack?

Python 3.10, Flask 2.2 (web framework), SQLAlchemy (ORM) and Marshmallow (serialization). In this project SQLite database is used that can be replaced with other database type.

Setup Instruction

Note: these instructions are for Mac OS

  • Create a parent working folder
  • Goto that folder and clone the repository. It will create a folder discount_api_codes
  • Setup the Python 🐍 virtual environment (I have assumed that Python 3.x is already installed on your system)
    python3 -m venv discount_codes_api cd discount_codes_api source bin/activate (for Mac OS and Linux)
  • Install the libraries and setup the database
    • goto discount_codes_api 📁
    • Install the dependencies, (refer to requirement.txt 📄).
    • pip3 install Flask==2.2.2
      pip3 install Flask-SQLAlchemy==2.5.1
      pip3 install flask-marshmallow==0.14.0
      
  • Create the database, Seed the database (refer to next section)
  • Lets run the app 💻 and test the endpoints using Postman 🏤 or web browser 🌍
    flask run
    

Database Commands

SQLite database loyalty.db is used by the app. During development/testing you can create the Database, Drop it and Seed it with initial data

Action Command
Create Database flask --app db_setup db_create
Drop Database flask --app db_setup db_drop
Seed Database flask --app db_setup db_seed

Note: commands should be entered in discount_api_codes folder 📁 at command prompt

Run the App

  1. python3 app.py OR
  2. flask run

The above command will run the development web server http://localhost:5000 where you can test the API endpoints

API Endpoints

API endpoint Description
http://localhost:5000/brands Return the brands 🛍️ list defined in the DB
http://localhost:5000/codes Return all the discount codes 💸 for all the brands
http://localhost:5000/codes?brand_id=2 Return all the discount codes of brand_id=2
There are 3 brands defined in the DB having ids 1, 2 and 3
http://localhost:5000/generate_disc_codes?brand_id=1&count=20 It will generate the 20 discount codes for the brand_id=2
You can pass other values 2 or 3 for brand_id. The count is optional, by default it will generate 🔟 codes or you can pass any positive number.
This endpoint expects 2️⃣ parameters: brand_id and count (i.e. number of codes to generate.)
http://localhost:5000/fetch_discount_code?brand_id=1&user_id=2 It fetches a discount code 🎟️ for a user of a brand.
This endpoint expects 2️⃣ parameters brand_id and user_id (there are two users defined in the DB with id 1 and 2

Happy Programming! 🌛 Fawad

discount_codes_api's People

Contributors

fawad-sh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.