Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
/ discounterland Public archive

RESTful web service for generating discount codes

Notifications You must be signed in to change notification settings

91nunocosta/discounterland

Repository files navigation

Discounterland

RESTful web service for generating discount codes.

pre-commit Code style: black Code Coverage

Installation

From source

  1. Install the required tools:

    1. Install docker.

    2. Install docker-compose.

  2. Clone the repository.

    git clone git@github.com:91nunocosta/discounterland.git
  3. Open the project directory.

    cd discounterland
  4. Start docker containers with MongoDB and the web server:

    docker-compose up -d
  5. Stop the dockers once you are done.

    docker-compose down

Usage

You can find the full Open API documentation here.

It can also be viewed in a nice format in Swagger Hub.

Examples

The following sections exemplify how you can interact with the API using the curl.

You can execute the examples by running the script examples.sh. If you prefer to use Postman, you can import postman_collection and try the requests there.

Before executing the following examples, set the environment variable TOKEN with:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5MW51bm9jb3N0YUBnbWFpbC5jb20iLCJpYXQiOjE2MTY2MTY5NjN9.tMQoy_6ROA_sxWR1exWVeRZZZFR4qvMbO2Szos_XIMI

Get available resources

Get the available endpoints (the format is not Open API).

curl "http://0.0.0.0:5000/"

Create promotion

A brand's manager creates a promotion with 10 discount codes available.

curl --location
     --request POST \
     'http://0.0.0.0:5000/brands/61a22c8f43cf71b9933afdd7/promotions' \
     --header "Authorization: Bearer ${TOKEN}" \
     --header 'Content-Type: application/json' \
     --data-raw '{
        "expiration_date": "2022-11-25T16:51:02.003Z",
        "product": {
          "name": "Nutella",
          "images": [
            "https://images.jumpseller.com/store/hercules-it-llc/10188702/Nutella.jpg?1623999446"
          ]
        },
        "discounts_quantity": 10
      }'

Create discount

A consumer generates a new discout code for himself/herself for the promotion created above.

curl --location \
     --request POST \
     'http://0.0.0.0:5000/consumers/61a2d3be596808c5d69dd11b/discounts' \
     --header "Authorization: Bearer ${TOKEN}" \
     --header 'Content-Type: application/json' \
     --data-raw '{
       "promotion_id": "61a2d5606ac07b74c824f1a9"
     }'

Contributing

How to prepare the development environment

  1. Install the required tools:

    1. Install poetry package and dependency manager. Follow the poetry installation guide. Chose the method that is more convenient to you, for example:

      curl -sSL\
           https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py \
         | python -
    2. Install docker.

    3. Install docker-compose.

  2. Clone the repository.

    git clone git@github.com:91nunocosta/discounterland.git
  3. Open the project directory.

    cd discounterland
  4. Create a new virtual environment (managed by poetry) with the project dependencies.

    poetry install
  5. Enter the virtual environment.

    poetry shell
  6. Start docker containers with MongoDB:

    docker-compose -f ./docker-compose-dev.yaml up -d
  7. Stop the docker once you are done.

    docker-compose -f ./docker-compose-dev.yaml down

How to check code quality

  1. Prepare the development environment, as described in How to prepare the development environment.

  2. Lint and test code

    pre-commit run --all-files

How to run the functional tests

You can run all tests against a real server instance.

  1. Run the script functional_tests
./funtional_test.sh

About

RESTful web service for generating discount codes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published