RESTful web service for generating discount codes.
-
Install the required tools:
-
Install docker.
-
Install docker-compose.
-
-
Clone the repository.
git clone git@github.com:91nunocosta/discounterland.git
-
Open the project directory.
cd discounterland
-
Start docker containers with MongoDB and the web server:
docker-compose up -d
-
Stop the dockers once you are done.
docker-compose down
You can find the full Open API documentation here.
It can also be viewed in a nice format in Swagger Hub.
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 the available endpoints (the format is not Open API).
curl "http://0.0.0.0:5000/"
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
}'
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"
}'
-
Install the required tools:
-
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 -
-
Install docker.
-
Install docker-compose.
-
-
Clone the repository.
git clone git@github.com:91nunocosta/discounterland.git
-
Open the project directory.
cd discounterland
-
Create a new virtual environment (managed by poetry) with the project dependencies.
poetry install
-
Enter the virtual environment.
poetry shell
-
Start docker containers with MongoDB:
docker-compose -f ./docker-compose-dev.yaml up -d
-
Stop the docker once you are done.
docker-compose -f ./docker-compose-dev.yaml down
-
Prepare the development environment, as described in How to prepare the development environment.
-
Lint and test code
pre-commit run --all-files
You can run all tests against a real server instance.
- Run the script functional_tests
./funtional_test.sh