Backend technical task

Jack runs a motorbike taxi company and wants to create a mobile app so his customers can conveniently book rides in advance and know the fare before getting on the bike. He types "build mobile app" into Google and discovers he needs to build an "API" to manage the business logic and data persistence for his app.

The first API endpoint he will need is a "quotation" endpoint. This will take the pickup and drop-off location from the user and return a price estimate for the journey.

Jack realises that he can only service a small area of his city (Bangkok, Thailand) as he only has drivers in some suburbs. He takes out a map of Bangkok and draws a rectangle around the area he believes his riders can accept jobs from.

If the user tries to specify a pickup or drop-off location outside of this rectangle, Jack's riders cannot service it, so the API will return an error state.

As an experienced former motorbike taxi himself, Jack knows the fare charged will depend on the distance. He decides for simplicity he'll just use the straightline distance between the pickup and drop-off location, and calculate the price based on a set per-kilometre fee.

The task

For the purpose of this exercise, you should build the "quotation" endpoint. Your API will need to be configurable with the following settings:

The quotation endpoint should accept a payload of the format:

POST api/quotation
{
  "from": {"lat": 13.735161, "lng": 100.582225},
  "to": {"lat": 13.726939, "lng": 100.575302}
}

If either the "from" or "to" location are outside of the service area, the API should return an error state with some message explaining the failure. If the "from" and "to" location are both within the service area, the API should respond as follows:

200 OK
{
  "from": {"lat": 13.735161, "lng": 100.582225},
  "to": {"lat": 13.726939, "lng": 100.575302}
  "distance": 1.2,
  "cost": "8.00"
}

In the example above, the "flag fall" is set to $5 and the per kilometre cost is $2.50 and the calculated distance is 1.2 km, so:

5 + (2.5 * 1.2) = 8

Note that the cost should be rounded to 2 decimal places of accuracy.

< Back