An HTTP service designed for delivery fee calculation.
The service is written using FastAPI.
To calculate delivery fee send POST request to the following endpoint:
POST /delivery_fee
with the following JSON body:
{"cart_value": 790, "delivery_distance": 2235, "number_of_items": 4, "time": "2024-01-15T13:00:00Z"}| Field | Type | Description | Example value |
|---|---|---|---|
| cart_value | Integer | Value of the shopping cart in cents. | 790 (790 cents = 7.90€) |
| delivery_distance | Integer | The distance between the store and customer’s location in meters. | 2235 (2235 meters = 2.235 km) |
| number_of_items | Integer | The number of items in the customer's shopping cart. | 4 (customer has 4 items in the cart) |
| time | String | Order time in UTC in ISO format. | 2024-01-15T13:00:00Z |
Example:
{"delivery_fee": 710}| Field | Type | Description | Example value |
|---|---|---|---|
| delivery_fee | Integer | Calculated delivery fee in cents. | 710 (710 cents = 7.10€) |
Python 3.11.7
pip installed
pip install -r requirements.txt
uvicorn app.main:app
The service will be started on http://127.0.0.1:8000 by default
pytest tests/*
- Test coverage is 100%
---------- coverage: platform darwin, python 3.11.7-final-0 ----------
Name Stmts Miss Cover
-------------------------------------------
app/fee_calculator.py 54 0 100%
app/main.py 14 0 100%
-------------------------------------------
TOTAL 68 0 100%
-
No additional time zone convertions are made since date is always coming in UTC by specification
-
Rush hour is checked using the following condition:
15 <= current_hour < 19
because it is unclear whether 7PM should be included.
-
Zero values for fields cart_value, delivery_distance, number_of_items are intentionally allowed. Only negative values are considered as invalid.
-
The function rounds the delivery_fee up to integers since the result value in the response must be in type int.