Skip to content

Commit

Permalink
[#25] feat: 주문 생성 요청 DTO 매핑
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdqls1200 committed Jun 27, 2023
1 parent 529b95f commit 91d6ddf
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<ApiResponse<Long>> order(@RequestBody RequestOrder requestOrder) {
final Long orderId = orderService.order(requestOrder);

return ResponseEntity.status(HttpStatus.CREATED)
.body(ApiResponse.success("201", orderId));
}
}
15 changes: 15 additions & 0 deletions be/kiosk/src/main/java/team/five/kiosk/domain/Order.java
Original file line number Diff line number Diff line change
@@ -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;
}
25 changes: 25 additions & 0 deletions be/kiosk/src/main/java/team/five/kiosk/domain/OrderDetail.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 20 additions & 0 deletions be/kiosk/src/main/java/team/five/kiosk/dto/RequestOrder.java
Original file line number Diff line number Diff line change
@@ -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<RequestOrderProduct> orderProducts;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.five.kiosk.repository;

import org.springframework.stereotype.Repository;

@Repository
public class OrderRepository {
}
24 changes: 24 additions & 0 deletions be/kiosk/src/main/java/team/five/kiosk/service/OrderService.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class ProductService {
public List<ResponseProduct> getProducts(final String category) {
List<Product> products = productRepository.findProductsBy(category);

return products.stream().map(ResponseProduct::from).collect(Collectors.toList());
return products.stream()
.map(ResponseProduct::from)
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 91d6ddf

Please sign in to comment.