다양한 케이크를 굽는 인기 제과점 CakeStation이 온라인 주문 관리 시스템을 구축해 달라고 부탁했어요.
메뉴에 있는 품목의 상세 정보는 다음과 같아요.
| 품목 | 가격 |
|---|---|
| Butter Cake | 15 |
| Chocolate Cake | 20 |
| Tres Leches | 25 |
다음과 같은 일이 가능해야 해요.
pending, in progress, completed 중 하나)를 조회해요.pending일 때만 가능해요.pending일 때만 가능해요.메뉴 조회
GET
/menu
application/json
{
"Butter Cake": 15,
"Chocolate Cake": 20,
"Tres Leches": 25
}
주문 넣기
메서드 - POST
경로 - /order
요청
username - 사용자의 사용자 이름 (string)order_items - 주문 품목을 나타내는 JSON 객체의 배열이에요. 각 JSON 객체는 정확히 두 개의 필드를 가져요. 품목의 이름을 나타내는 문자열 item 필드와, 해당 품목의 주문 수량을 나타내는 정수 quantity 필드예요.{
"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"
]
}
응답
username이 비어 있거나order_items 배열이 비어 있거나order_items 배열에 특정 종류의 케이크에 대한 JSON 객체가 두 개 이상 있거나order_items 배열의 원소가 메뉴에 없는 종류의 케이크를 item 필드에 가지고 있거나order_items 배열의 원소의 quantity 필드 값이 1보다 작거나application/json
order_id예요. 이 값은 유효한 숫자의 문자열 표현이어야 해요.total 필드예요. (즉, 각 케이크 종류별 가격 x 수량의 합){
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"total": {
"type": "integer"
}
},
"required": [
"order_id",
"total"
]
}
주문 상태 조회
GET
/order/{orderId}
orderId를 가진 주문이 없으면 404 Not Foundcontent-type - application/json
주문 ID와 상태(pending, in progress, completed 중 하나)를 각각 나타내는 두 개의 문자열 필드 order_id와 status를 가진 JSON 객체
{
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"status": {
"type": "string"
}
},
"required": [
"order_id",
"status"
]
}
주문 수정. 상태가 아직 pending일 때만 가능해요.
메서드 - PUT
경로 - /order/{orderId}
요청
요청 페이로드는 order_items 필드 하나를 가진 JSON 객체예요.
order_items - 주문 품목을 나타내는 JSON 객체의 배열이에요. 각 JSON 객체는 정확히 두 개의 필드를 가져요. 품목의 이름을 나타내는 문자열 item 필드와, 해당 품목의 주문 수량을 나타내는 정수 quantity 필드예요.{
"type": "object",
"properties": {
"order_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"item": {
"type": "string"
},
"quantity": {
"type": "integer"
}
},
"required": [
"item",
"quantity"
]
}
}
},
"required": [
"order_items"
]
}
응답
orderId를 가진 주문이 없으면 404 Not Foundpending이 아니면(즉, in progress 또는 completed) 403 Forbiddenorder_items 배열이 주문을 넣을 때(2번)와 같은 요구 사항을 충족하지 않으면 400 Bad Requestcontent-type - application/json
두 개의 필드를 가진 JSON 객체
order_id
total 필드 (즉, 각 케이크 종류별 가격 x 수량의 합){
"type": "object",
"properties": {
"order_id": {
"type": "string"
},
"total": {
"type": "integer"
}
},
"required": [
"order_id",
"total"
]
}
참고: 수정 시도가 실패하면 기존 주문에 어떤 변경도 가해서는 안 돼요.
주문 삭제. 상태가 아직 pending일 때만 가능해요.
DELETE
/order/{orderId}
orderId를 가진 주문이 없으면 404 Not Foundpending이 아니면(즉, in progress 또는 completed) 403 Forbidden생성된 주문 ID는 고유해야 하고, 문자열이어야 하며, 유효한 숫자의 문자열 표현이어야 해요 (예: "1", "1234").
8080인 configurable 변수 port를 사용해요.orderStatus 맵을 사용해요. 이 맵에서는 무작위로 생성된 주문 ID 문자열에 대해 값이 "pending", "in progress", "completed" 중 하나예요.
"pending", "in progress", "completed")orderStatus 맵을 "pending" 값으로 갱신해요.메뉴를 조회해요.
$ curl -v http://localhost:8080/menu
< HTTP/1.1 200 OK
< content-type: application/json
{"Butter Cake":15, "Chocolate Cake":20, "Tres Leches":25}
유효한 페이로드로 주문을 넣으려고 시도해요.
$ 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}
참고: "order_id"는 무작위로 생성된 고유한 문자열이어야 하며, 실제로 그렇게 돼요.
예상 형식과 일치하지 않는 페이로드로 주문을 넣으려고 시도해요.
$ 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(키워드예요)를 경로로 사용하려면 인용 식별자 ('order)를 사용할 수 있어요.