From 91d6ddf6e7b921f9b73ec2eea4f05cdb7266852e Mon Sep 17 00:00:00 2001 From: code-tree Date: Tue, 27 Jun 2023 20:24:06 +0900 Subject: [PATCH] =?UTF-8?q?[#25]=20feat:=20=EC=A3=BC=EB=AC=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=9A=94=EC=B2=AD=20DTO=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kiosk/controller/OrderController.java | 28 +++++++++++++++++++ .../java/team/five/kiosk/domain/Order.java | 15 ++++++++++ .../team/five/kiosk/domain/OrderDetail.java | 25 +++++++++++++++++ .../team/five/kiosk/dto/RequestOrder.java | 20 +++++++++++++ .../five/kiosk/dto/RequestOrderProduct.java | 16 +++++++++++ .../kiosk/repository/OrderRepository.java | 7 +++++ .../team/five/kiosk/service/OrderService.java | 24 ++++++++++++++++ .../five/kiosk/service/ProductService.java | 6 ++-- .../controller/ProductControllerTest.java | 7 +++-- 9 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 be/kiosk/src/main/java/team/five/kiosk/controller/OrderController.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/domain/Order.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/domain/OrderDetail.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrder.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrderProduct.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/repository/OrderRepository.java create mode 100644 be/kiosk/src/main/java/team/five/kiosk/service/OrderService.java diff --git a/be/kiosk/src/main/java/team/five/kiosk/controller/OrderController.java b/be/kiosk/src/main/java/team/five/kiosk/controller/OrderController.java new file mode 100644 index 00000000..d7371471 --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/controller/OrderController.java @@ -0,0 +1,28 @@ +package team.five.kiosk.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import team.five.kiosk.dto.RequestOrder; +import team.five.kiosk.global.ApiResponse; +import team.five.kiosk.service.OrderService; + +@RequiredArgsConstructor +@RequestMapping("/api/v1") +@RestController +public class OrderController { + + private final OrderService orderService; + + @PostMapping("/orders") + public ResponseEntity> order(@RequestBody RequestOrder requestOrder) { + final Long orderId = orderService.order(requestOrder); + + return ResponseEntity.status(HttpStatus.CREATED) + .body(ApiResponse.success("201", orderId)); + } +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/domain/Order.java b/be/kiosk/src/main/java/team/five/kiosk/domain/Order.java new file mode 100644 index 00000000..5d0f0374 --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/domain/Order.java @@ -0,0 +1,15 @@ +package team.five.kiosk.domain; + +import java.time.LocalDateTime; + +public class Order { + private Long id; + + private Long payment_id; + + private int totalCost; + + private int inputCost; + + private LocalDateTime orderAt; +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/domain/OrderDetail.java b/be/kiosk/src/main/java/team/five/kiosk/domain/OrderDetail.java new file mode 100644 index 00000000..fcca352a --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/domain/OrderDetail.java @@ -0,0 +1,25 @@ +package team.five.kiosk.domain; + +import lombok.Getter; + +@Getter +public class OrderDetail { + private Long id; + + private Long productId; + + private Long orderId; + + private String size; + + private String temperature; + + private int count; + + public OrderDetail(Long productId, String size, String temperature, int count) { + this.productId = productId; + this.size = size; + this.temperature = temperature; + this.count = count; + } +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrder.java b/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrder.java new file mode 100644 index 00000000..08f8811a --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrder.java @@ -0,0 +1,20 @@ +package team.five.kiosk.dto; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class RequestOrder { + private String payment; + + private int totalPrice; + + @JsonIgnore(value = false) + private int inputPrice; + + private List orderProducts; +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrderProduct.java b/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrderProduct.java new file mode 100644 index 00000000..b92fd313 --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrderProduct.java @@ -0,0 +1,16 @@ +package team.five.kiosk.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class RequestOrderProduct { + private Long productId; + + private int count; + + private String size; + + private String temperature; +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/repository/OrderRepository.java b/be/kiosk/src/main/java/team/five/kiosk/repository/OrderRepository.java new file mode 100644 index 00000000..663accc9 --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/repository/OrderRepository.java @@ -0,0 +1,7 @@ +package team.five.kiosk.repository; + +import org.springframework.stereotype.Repository; + +@Repository +public class OrderRepository { +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/service/OrderService.java b/be/kiosk/src/main/java/team/five/kiosk/service/OrderService.java new file mode 100644 index 00000000..1ba2987b --- /dev/null +++ b/be/kiosk/src/main/java/team/five/kiosk/service/OrderService.java @@ -0,0 +1,24 @@ +package team.five.kiosk.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import team.five.kiosk.dto.RequestOrder; +import team.five.kiosk.repository.OrderRepository; + +@Transactional(readOnly = true) +@RequiredArgsConstructor +@Service +public class OrderService { + + private final OrderRepository orderRepository; + + @Transactional + public Long order(RequestOrder requestOrder) { + // 결제 수단(payment) 조회 + // order 저장 + // orderProducts 저장 + + return 1L; + } +} diff --git a/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java b/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java index a9ef7b20..8140be0f 100644 --- a/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java +++ b/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java @@ -20,6 +20,8 @@ public class ProductService { public List getProducts(final String category) { List products = productRepository.findProductsBy(category); - return products.stream().map(ResponseProduct::from).collect(Collectors.toList()); + return products.stream() + .map(ResponseProduct::from) + .collect(Collectors.toList()); } -} +} \ No newline at end of file diff --git a/be/kiosk/src/test/java/team/five/kiosk/controller/ProductControllerTest.java b/be/kiosk/src/test/java/team/five/kiosk/controller/ProductControllerTest.java index 2a63345f..34ec85ad 100644 --- a/be/kiosk/src/test/java/team/five/kiosk/controller/ProductControllerTest.java +++ b/be/kiosk/src/test/java/team/five/kiosk/controller/ProductControllerTest.java @@ -37,9 +37,10 @@ public void getProductsTest() throws Exception { given(productService.getProducts(anyString())).willReturn(responseProducts); //when - final ResultActions result = mockMvc.perform(get("/api/v1/products") - .queryParam("category", "coffee")) - .andExpect(status().isOk()).andDo(print()); + final ResultActions result = mockMvc + .perform(get("/api/v1/products").queryParam("category", "coffee")) + .andExpect(status().isOk()) + .andDo(print()); //then result.andExpect(jsonPath("status").isString());