GithubHelp home page GithubHelp logo

coupon-app's Introduction

Coupon management example application

Notes

A company offers various paid services to its customers and occasionally they want to issue coupons. This is a super-simple coupon management application that solves this using FastAPI and an SQL backend.

There are (at least) two types of coupons:

  • fixed sum,
  • percentage-based.

Q: Does fixed sum coupons need a currency? A: Probably not, we can convert on the UI if needed, although in that case we could end up with ugly, fractional numbers.

The application should provide a REST API for:

  • creating coupons,
  • checking coupon validity,
  • activting/using coupon,
  • disabling coupons.

A coupon could belong to a single customer, or it can be used by anyone who has the coupone code.

Schema

Customer:

  • id (primary key)
  • name (str)
  • created_at (date, auto)

Coupon:

  • id (primary key)
  • created_at (date, auto)
  • code (unique str)
  • description (str)
  • discount (float)
  • discount_type (enum)
  • customer (optional, foreign key)
  • valid_from (date)
  • valid_until (date)

Note: having customer in Coupon means a coupon can be used either by a single customer or by anyone. Supporting "group" coupon would require an additional link table (and the removal of the customer attribute).

Configuration

Configuration requires python-dotenv and is done with pydantic.Settings.

PostreSQL

Database driver: psycopg2-binary

After a local PostgreSQL install, you will need to create a database user or alter the default postgres user for example like this (from the psql console that can be started with sudo -u postgres psql):

ALTER USER postgres PASSWORD '<your-password>';

You will also need to create a database, for example with this command:

SELECT 'CREATE DATABASE <databasename>'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'databasename')\gexec

CLI

Built with typer.

Execute with python -m app_cli.main.

Run demo fixture: python -m app_cli.main demo.

Testing

TODO

Development

Dependencies: fastapi[all] sqlmodel typer[all].

Linting and formatting: black mypy ruff.

Testing: pytest.

Dependency management

Currently pipenv, probably moving to poetry in the future.

coupon-app's People

Contributors

volfpeter 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.