In LalaFood, we are receiving order of delivery day and night. As a software engineer in LalaFood, you have to provide a reliable backend system to clients. Your task here is to implement three endpoints to list/place/take orders.
- We value a clean, simple working solution.
- The application must be run in Docker, candidate must provide
docker-compose.yml
, which should setup all relevant services/applications. - Solution must be written in Java/Kotlin with Spring Boot.
- Candidates must submit the project as a private git repository (bitbucket or github).
- Unit tests would be a strong bonus.
- As we run automated tests on your project, you must comply to the API requirement as stipulated below. You can assume Docker is already installed in the test machine.
- The solution must be production ready.
-
Must be a RESTful HTTP API listening to port
8080
(or you can use another port instead and describe in the README) -
The API must implement 3 endpoints with path, method, request and response body as specified
-
One endpoint to create an order (see sample)
- To create an order, the API client must provide an origin and a destination (see sample)
- The API responds an object containing the distance and the order ID (see sample)
-
One endpoint to take an order (see sample)
- An order can only be taken once.
- An error response should be returned if a client tries to take an order that is already taken.
-
One endpoint to list orders (see sample)
-
-
The request input should be validated before processing. The server should return proper error response in case validation fails.
-
You must use following API to get the distance for the order:
- Google Maps API (https://cloud.google.com/maps-platform/routes/)
- NOTE: You don't have to provide actual Google Maps API key to us, just describe in the README how to use a custom key with your solution.
- A Database must be used (SQL or NoSQL, at LalaFood we use mostly MySQL). The DB installation & initialisation must be done in
start.sh
. - All responses must be in json format no matter in success or failure situations.
You are expected to follow the API specification as follows. Your implementation should not have any deviations on the method, URI path, request and response body. Such alterations may cause our automated tests to fail.
-
Method:
POST
-
URL path:
/orders
-
Request body:
{ "origin": { "latitude": 14.397439, "longitude": 102.913436 }, "destination": { "latitude": 14.397439, "longitude": 102.913436 }
} ```
-
Response:
Header:
HTTP 200
Body:{ "id": <order_id>, "distance": <total_distance>, "status": "UNASSIGNED" }
or
Header:
HTTP <HTTP_CODE>
Body:{ "error": "ERROR_DESCRIPTION" }
-
Requirements:
- The latitude and longitude value of coordinates must be correctly validated.
- Order id in response should be unique. It can be an auto-incremental integer or uuid string
- Distance in response should be integer in meters
-
Method:
PATCH
-
URL path:
/orders/:id
-
Request body:
{ "status": "TAKEN" }
-
Response: Header:
HTTP 200
Body:{ "status": "SUCCESS" }
or
Header:
HTTP <HTTP_CODE>
Body:{ "error": "ERROR_DESCRIPTION" }
-
Requirements:
- Since an order can only be taken once, you must be mindful of race condition.
- When there are concurrent requests to take a same order, we expect only one can take the order while the other will fail.
-
Method:
GET
-
Url path:
/orders?page=:page&size=:size
-
Response: Header:
HTTP 200
Body:{ content: [{ "id": < order_id > , "distance": < total_distance > , "status": < ORDER_STATUS > }, ... }
or
Header:
HTTP <HTTP_CODE>
Body:{ "error": "ERROR_DESCRIPTION" }
-
Requirements:
- Use standard string pagination
Questions? We love to answer: [email protected], [email protected]