Your mission is to build a simplified API to power a listing website.
The Listing
entity carries a certain number of information about the property (title, market, etc) and has a Calendar
to carry prices and availability.
A Calendar
is just a list of dates with added information about each date - for example each date can have a different price:
date=2020-01-01, price=500
date=2020-01-02, price=450
Additionally, the concept of a "Base Price". When we predict a price for a day, we think of it as a multiple of the base price. E.g. a price of $150 for a specific day is a 1.5x multiple on the base price of $100.
The challenge will work with a simplified version of the listing and the calendar.
Endpoints to implement:
(See Specifications for more details)
-
Create a listing
SeePOST /listings
endpoint -
Retrieve a listing
SeeGET /listings/:id
endpoint -
Update a listing
SeePUT /listings/:id
endpoint -
Delete a listing
SeeDELETE /listings/:id
endpoint -
Retrieve several listings
SeeGET /listings
endpoint -
Retrieve a listing's calendar
SeeGET /listings/:id/calendar
endpoint
- We've set up Flask in
app.py
. Implement the endpoints in this file. We also added an example to show how to use Flask to process the information of a request.
Your solution must use python 3.7 or greater.
Your solution must persist data into a file without using an ORM library or a DB system.
Your solution must use [open exchange rates][open-exchange-rates] to get the exchange rates. The free plan is enough to complete this task.
The response format of your API must be JSON and a proper use of HTTP status codes and error handling is expected.
-
POST /listings
endpoint-
Send JSON data in the body, for example:
{ "title": "Comfortable Room In Cozy Neighborhood", "base_price": 867, "currency": "USD", "market": "san-francisco", "host_name": "John Smith" },
All fields are required except for
host_name
. -
Return: the listing information (including its ID) in a JSON format.
-
-
GET /listings/:id
endpoint- Return: the listing information (including its ID) in a JSON format.
-
PUT /listings/:id
endpoint- Send JSON data in the body
- Update only the fields present in the request
- Return: the listing information (including its ID) in a JSON format.
-
DELETE /listings/:id
endpoint- A successful response must mean a listing was deleted.
-
GET /listings
endpoint-
Return: a list of listings in a JSON format.
-
This endpoint should allow to filter by market and base price/currency.
Those filters must be implemented as query parameters:
-
market
- optional- A single market or a list of markets separated by commas. It uses the market codes.
- E.g.:
?market=paris
or?market=paris,san-francisco
-
base_price.[e|gt|gte|lt|lte]
- optional- The comparison type is part of the query parameter.
- E.g.:
?base_price.gt=500
or?base_price.lte=300
-
currency
- optional but required when base price is specified- It uses the currency codes.
- E.g.:
?currency=usd
-
-
-
GET /listings/:id/calendar
endpoint-
This endpoint returns the listing's calendar (365 days starting from today).
-
It must allow to return the calendar in any currency. The default being the listing's currency.
This parameter must be implemented as a query parameter:
currency
- optional- It uses the currency codes.
- E.g.:
?currency=usd
-
Format for dates:
YYYY-MM-DD
-
Calendar rules:
- For the Paris and Lisbon markets: Saturday and Sunday => 1.5x of base price
- For the San Francisco market: Wednesday => 0.70x of base price
- For the rest of the markets: Friday => 1.25x of base price
-
Example of response:
[ { "date": "2019-01-01", "price": 500, "currency": "USD", }, { "date": "2019-01-02", "price": 550, "currency": "USD", }, ... ]
-