CakeStation, a popular bakery that bakes various cakes, has asked you to set up an online order management system for them.
The details of items on the menu are as follows.
Item | Price |
---|---|
Butter Cake | 15 |
Chocolate Cake | 20 |
Tres Leches | 25 |
The following is expected to be possible.
pending
, in progress
, or completed
).pending
.pending
.Retrieve the Menu
GET
/menu
application/json
{
"Butter Cake": 15,
"Chocolate Cake": 20,
"Tres Leches": 25
}
Place an Order
Method - POST
Path - /order
Request
username
- username of the user (string
)order_items
- an array of JSON objects representing the order items. Each JSON object will contain exactly two fields: a string item
field indicating the name of the item and an integer quantity
field indicating the order quantity for the particular item.{
"type": "object",
"properties": {
"username": {
"type": "string"
},
"order_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"item": {
"type": "string"
},
"quantity": {
"type": "integer"
}
},
"required": [
"item",
"quantity"
]
}
}
},
"required": [
"username",
"order_items"
]
}
Response
username
is empty ororder_items
array is empty ororder_items
array contains more than one JSON object for a particular type of cake ororder_items
array has an item
field with a type of cake that is not on the menu ororder_items
array has a quantity
field that has a value less than 1application/json
order_id
containing the randomly generated order ID string. This should be the string representation of a valid numeric value.total
field containing the total value (integer) of the order (i.e., sum of price x quantity for each kind of cake){
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"total": {
"type": "integer"
}
},
"required": [
"order_id",
"total"
]
}
Retrieve the Status of an Order
GET
/order/{orderId}
orderId
content-type - application/json
a JSON object with two string fields order_id
and status
, representing the order ID and the status (one of pending
, in progress
, or completed
) respectively
{
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"status": {
"type": "string"
}
},
"required": [
"order_id",
"status"
]
}
Update an Order. Only allowed if the status is still pending
.
Method - PUT
Path - /order/{orderId}
Request
the request payload will be a JSON object with a single field order_items
.
order_items
- an array of JSON objects representing the order items. Each JSON object will contain exactly two fields: a string item
field indicating the name of the item and an integer quantity
field indicating the order quantity for the particular item.{
"type": "object",
"properties": {
"order_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"item": {
"type": "string"
},
"quantity": {
"type": "integer"
}
},
"required": [
"item",
"quantity"
]
}
}
},
"required": [
"order_items"
]
}
Response
orderId
pending
(i.e., in progress
or completed
)order_items
array doesn't meet the same requirements as that for placing the order (2)content-type - application/json
a JSON object with two fields
order_id
containing the same order ID string as the original ordertotal
field containing the total value of the order (i.e. the sum of price x quantity for each kind of cake){
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"total": {
"type": "integer"
}
},
"required": [
"order_id",
"total"
]
}
Note: if an update attempt fails, no changes should be done to the existing order.
Delete an Order. Only allowed if the status is still pending
.
DELETE
/order/{orderId}
orderId
pending
(i.e., in progress
or completed
)The generated order ID should be unique, should be a string, and should be a string representation of a valid number (e.g., "1"
, "1234"
).
configurable
variable port
with the default value of 8080
to specify the port the service listens on.orderStatus
map to maintain the status of the orders, in which the value is either "pending"
, "in progress"
, or "completed"
against the randomly generated order ID string.
"pending"
, "in progress"
, or "completed"
)orderStatus
map with the value "pending"
for each new order.Retrieving the menu.
$ curl -v http://localhost:8080/menu
< HTTP/1.1 200 OK
< content-type: application/json
{"Butter Cake":15, "Chocolate Cake":20, "Tres Leches":25}
Attempting to place the order with a valid payload.
$ curl -v http://localhost:8080/order -d '{"username": "mary", "order_items": [{"item": "Tres Leches", "quantity": 1}, {"item": "Chocolate Cake", "quantity": 2}]}' -H 'Content-Type: application/json'
< HTTP/1.1 201 Created
< content-type: application/json
{"order_id":"7", "total":65}
Note: "order_id" should/will be a randomly generated unique string.
Attempting to place the order with payload does not match the expected format.
$ curl -v http://localhost:8080/order -d '{"username": "mary", "order_items": [{"Tres Leches": 1}, {"Chocolate Cake": 2}]}' -H 'Content-Type: application/json'
< HTTP/1.1 400 Bad Request
'order
) can be used to use order
(which is a keyword) as the path.Sign up to Exercism to learn and master Ballerina with 58 exercises, and real human mentoring, all for free.