Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2단계 - 주문 기능 구현] 도기(김동호) 미션 제출합니다. #82

Merged
merged 143 commits into from
Jun 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
3a182f5
chore(WebMvcConfig): CORS 설정
kdkdhoho May 23, 2023
9a02b42
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
7a1e8b9
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
bd0b2e8
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
634a7f8
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
3f6e91a
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
2313449
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
fae75b4
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
cde324b
feat(ControllerExceptionHandler): Exception 에러 처리 기능 구현
kdkdhoho May 24, 2023
d881288
test
kdkdhoho May 24, 2023
cc836c7
test
kdkdhoho May 24, 2023
a794aa4
test
kdkdhoho May 24, 2023
754ac05
test
kdkdhoho May 24, 2023
b0a6d60
test
kdkdhoho May 24, 2023
ba5c49b
test
kdkdhoho May 24, 2023
8abcb3b
test
kdkdhoho May 24, 2023
50938bd
test
kdkdhoho May 24, 2023
be2f444
test
kdkdhoho May 24, 2023
4182206
test
kdkdhoho May 24, 2023
720afbb
fix(WebMvcConfig): exposeHeader 추가
kdkdhoho May 25, 2023
69a947b
chore(logback-spring): 애플리케이션 로그 레벨을 TRACE로 변경
kdkdhoho May 25, 2023
a84968e
chore(logback-spring): 애플리케이션 로그 레벨을 INFO로 변경
kdkdhoho May 25, 2023
6d347b6
feat(ControllerExceptionHandler): 에러 처리
kdkdhoho May 25, 2023
66e07c0
chore: github action workflow 작성
kdkdhoho May 25, 2023
1de201e
test
kdkdhoho May 25, 2023
6ce19d4
test
kdkdhoho May 25, 2023
e49b790
test3
kdkdhoho May 25, 2023
2904f47
test3
kdkdhoho May 25, 2023
e1c365c
test3
kdkdhoho May 25, 2023
880be6f
test3
kdkdhoho May 25, 2023
5e29894
fix: 데이터 및 html 페이지 복구
kdkdhoho May 25, 2023
56590a7
chore: mysql 의존성 추가
kdkdhoho May 30, 2023
6d1a6d4
chore: mysql 의존성 추가
kdkdhoho May 30, 2023
4e74150
chore: logback 설정 삭제
kdkdhoho May 30, 2023
3ed9109
chore(gitignore): 배포 환경 DB 연결 설정파일 추가
kdkdhoho May 30, 2023
2e97969
chore: 배포 환경 DB 연결
kdkdhoho May 30, 2023
e20a1ef
chore: 테이블 수정 및 더미 데이터 추가
kdkdhoho May 30, 2023
4cb3d5d
docs(README): API 명세서, 테이블 설계 추가
kdkdhoho May 30, 2023
18020e1
chore: README gitignore 해제
kdkdhoho May 30, 2023
c07fb5d
chore: lombok 추가
kdkdhoho May 30, 2023
bab56c1
chore(schema): 테이블 설계 수정
kdkdhoho May 30, 2023
7602ae1
refactor(Member): 필드 추가 및 보일러 플레이트 코드 제거
kdkdhoho May 30, 2023
357094e
test(DaoTest): DaoTest 부모 클래스 생성
kdkdhoho May 30, 2023
9ce08f1
refactor(MemberDao): 테이블 변경에 따른 수정 및 코드 품질 개선
kdkdhoho May 30, 2023
c568c5b
refactor(Member): equals&hashcode 재정의
kdkdhoho May 30, 2023
4fef1bb
refactor(Product): 필드 추가 및 코드 개선, Equals&HashCode 재정의
kdkdhoho May 30, 2023
0255a19
refactor(ProductDao): 테이블 변경에 따른 전체 코드 수정 및 테스트 코드 작성
kdkdhoho May 30, 2023
336b003
refactor(CartItem): 코드 개선 및 테스트 코드 작성
kdkdhoho May 31, 2023
c873586
remove(CartItemException): 뼈대 코드에 제공된 예외 삭제
kdkdhoho May 31, 2023
40707fd
feat(IllegalAccessCartException): 다른 회원의 장바구니에 접속할 때 발생하는 커스텀 예외 추가
kdkdhoho May 31, 2023
9c3e6b6
feat(CartItemEntity): CartItem 엔티티 객체 구현
kdkdhoho May 31, 2023
ad52153
refactor(CartItemDao): 단순히 테이블에 접근만 하도록 수정 및 테스트 코드 작성
kdkdhoho May 31, 2023
c43bc62
refactor(CartItem): 필드 순서 변경
kdkdhoho May 31, 2023
fb74140
feat(CartItemRepository): CartItem을 영속하고 id로 조회하는 기능 구현
kdkdhoho May 31, 2023
0212ec3
feat: 존재하지 않는 데이터를 조회할 경우 발생하는 커스텀 예외 추가
kdkdhoho May 31, 2023
0dbceb5
refactor(ProductResponse): 필드 추가 및 코드 개선
kdkdhoho May 31, 2023
94c4d69
refactor(ProductApiController): 코드 개선
kdkdhoho May 31, 2023
e2bdcd7
test(ProductIntegrationTest): 테스트 코드 추가 및 수정
kdkdhoho May 31, 2023
b985fc5
chore: 테스트 DB 연결 설정 추가
kdkdhoho May 31, 2023
91a1446
test(IntegrationTest): 불필요한 어노테이션 제거 및 Sql 어노테이션 추가
kdkdhoho May 31, 2023
3dfe287
refactor(ProductRequest): 필드 추가 및 보일러 플레이트 코드 제거
kdkdhoho May 31, 2023
f812021
refactor: 메소드 네이밍 변경
kdkdhoho May 31, 2023
84c4507
refactor(CartItemEntity): 필드 순서 변경
kdkdhoho May 31, 2023
0c53409
feat(CartItemDao): 회원 ID로 데이터를 조회하는 기능 구현
kdkdhoho May 31, 2023
b48da62
feat(CartItemRepository): 회원 ID로 객체를 조회하는 기능 구현
kdkdhoho May 31, 2023
b6e2a5b
refactor(CartItemRepository): add() 이후 id를 반환하도록 수정
kdkdhoho May 31, 2023
678397e
feat(CartItemRepository): 삭제 및 수정 기능 구현
kdkdhoho May 31, 2023
a68b735
feat: 장바구니 기능 구현
kdkdhoho May 31, 2023
68e4190
refactor(CartItemEntity): 파라미터명 수정
kdkdhoho May 31, 2023
9677698
refactor(PageController): 롬복 애노테이션 추가 및 개행
kdkdhoho May 31, 2023
00e8073
feat(ControllerExceptionHandler): 예외 핸들러 기능 구현
kdkdhoho May 31, 2023
57b143b
feat(Quantity): 물품의 수량 역할을 갖는 객체 구현
kdkdhoho May 31, 2023
27a2d74
feat(AuthenticationException): 인증 정보가 잘못 된 경우 발생하는 예외 추가
kdkdhoho Jun 1, 2023
5c7cecb
rename(CartItemApiController): 디렉터리를 ui에서 presentation으로 변경
kdkdhoho Jun 1, 2023
6a6c7a1
refactor: Quantity 객체 추가로 인한 코드 수정
kdkdhoho Jun 1, 2023
a3426d1
rename(WebMvcConfig): config 디렉터리로 이동
kdkdhoho Jun 1, 2023
5dd28ae
refactor(CartItemApiController): 코드 리팩터링
kdkdhoho Jun 1, 2023
97663f8
feat(Point): 포인트의 역할을 가지는 객체 추가
kdkdhoho Jun 1, 2023
dc3e44e
feat(MemberEntity): MemberEntity 객체 추가
kdkdhoho Jun 1, 2023
e6dd607
feat(MemberRepository): Member 도메인 객체를 영속하는 Repository 추가
kdkdhoho Jun 1, 2023
3b83abe
refactor(Member): Point 객체 이용에 따른 코드 수정, 추가 생성자 작성
kdkdhoho Jun 1, 2023
9ef6b65
refactor: MemberEntity 추가에 따른 변경사항 적용
kdkdhoho Jun 1, 2023
31d4567
refactor(CartItem): 변수명 수정
kdkdhoho Jun 1, 2023
a7f093d
test: Repository 테스트 추가
kdkdhoho Jun 1, 2023
2aedb28
test: 테스트 리팩터링
kdkdhoho Jun 1, 2023
183e17c
feat(ControllerExceptionHandler): 예상치 못한 예외를 처리하는 핸들러 메서드 추가
kdkdhoho Jun 1, 2023
bfb4f05
refactor(CartItemService): 메서드 네이밍 변경에 의한 리팩터링
kdkdhoho Jun 1, 2023
fa598de
test: 공통으로 사용되는 필드를 부모 객체로 이동
kdkdhoho Jun 1, 2023
2572273
feat: 포인트 조회 API 구현
kdkdhoho Jun 1, 2023
5bd4f74
rename(CartItemAddRequest): 장바구니에 상품을 추가할 때 사용되는 요청에 적절하게 객체명 수정
kdkdhoho Jun 1, 2023
6f75447
rename(ProductAddRequest): 상품을 추가할 때 사용되는 요청에 적절하게 객체명 수정
kdkdhoho Jun 1, 2023
52a86d1
feat(OrderEntity): OrderEntity 추가
kdkdhoho Jun 2, 2023
8e24520
feat(OrderDao): 테이블에 주문 데이터를 CRUD하는 DAO 객체 구현
kdkdhoho Jun 2, 2023
8b21c3d
feat(CurrentTimeUtil): 현재 시각을 반환하는 util 클래스 구현
kdkdhoho Jun 2, 2023
12a5d06
refactor(OrderEntity): 주문 시각 타입 변경
kdkdhoho Jun 2, 2023
76f193b
feat(ProductDao): ID로 상품의 수량만 수정하는 기능 구현
kdkdhoho Jun 2, 2023
aedf0c5
chore: 테이블 설계 수정
kdkdhoho Jun 2, 2023
6d2c743
refactor(OrderDao): 스키마 변경에 따른 리팩터링
kdkdhoho Jun 2, 2023
5ee1efe
refactor(OrderEntity): 스키마 변경에 따른 리팩터링
kdkdhoho Jun 2, 2023
3bc55c2
feat(OrderItemEntity): OrderItemEntity 구현
kdkdhoho Jun 2, 2023
ce66e44
chore: schema sql문 수정
kdkdhoho Jun 2, 2023
f510192
feat(OrderItemDao): OrderItemDao 구현
kdkdhoho Jun 2, 2023
b60c95f
chore: 테이블 구조 변경
kdkdhoho Jun 2, 2023
2130f63
refactor: 테이블 구조 변경에 따른 OrderItem에 해당하는 Entity와 Dao 코드 수정
kdkdhoho Jun 2, 2023
5f5e9a0
feat: 주문하기 기능 구현
kdkdhoho Jun 2, 2023
f8ccd9a
feat: 주문하기 도중 발생할 수 있는 예외 처리 구현
kdkdhoho Jun 2, 2023
0558ee2
feat(OrderItemDao): 주문ID로 상위 2개 데이터만 가져오는 기능 구현
kdkdhoho Jun 2, 2023
3251651
feat: 전체 주문 목록 조회 기능 구현
kdkdhoho Jun 2, 2023
a4d7d58
feat: 주문 상세 조회 기능 구현
kdkdhoho Jun 2, 2023
b7df45d
refactor: API 명세서에 맞도록 변수명 및 순서 수정
kdkdhoho Jun 2, 2023
1cad985
refactor(ControllerExceptionHandler): 예상치 못한 예외 발생 시 에러 메시지도 출력하도록 수정
kdkdhoho Jun 2, 2023
6979464
refactor: 모든 주문 상품을 조회하는 기능에서 회원 ID로 주문 상품을 조회하는 기능으로 변경
kdkdhoho Jun 2, 2023
279f43a
chore: 변수명 수정으로 인한 html 파일 수정
kdkdhoho Jun 2, 2023
2deec27
chore: 변수명 수정으로 인한 html 파일 수정
kdkdhoho Jun 2, 2023
57b0ba5
refactor(MemberArgumentResolver): 인증 정보가 유효하지 않으면 예외를 발생하도록 수정
kdkdhoho Jun 2, 2023
e2546dd
chore: 로컬 환경 DB 연결
kdkdhoho Jun 2, 2023
0592f8a
fix(OrderService): 포인트를 사용하면 예외가 발생하는 오류 수정
kdkdhoho Jun 4, 2023
66c235e
rename: 커스텀 예외 네이밍 변경
kdkdhoho Jun 4, 2023
72f90f3
rename(GlobalExceptionHandler): 패키지 이동
kdkdhoho Jun 4, 2023
62cfb85
refactor(MemberArgumentResolver): 함수 분리
kdkdhoho Jun 4, 2023
05d5a26
feat(Point): 사용한 포인트가 사용할 수 있는 포인트인지 검증하는 기능 구현
kdkdhoho Jun 4, 2023
3d5610f
feat(Point): 총 상품 가격으로 포인트를 계산하는 기능, 포인트를 합하는 기능 구현
kdkdhoho Jun 4, 2023
c7afcad
feat(Member): 총 상품 가격에 따른 포인트를 추가 적립하는 기능 구현
kdkdhoho Jun 4, 2023
d7484e1
refactor(ProductDao): 상품 수정 메서드의 파라미터 변경
kdkdhoho Jun 4, 2023
7d92838
feat(Product): 주문 수량에 맞게 남은 재고를 수정하는 기능 구현
kdkdhoho Jun 4, 2023
5b868d8
feat: Response 객체 정적 팩터리 메서드 작성
kdkdhoho Jun 4, 2023
3f3528b
refactor(OrderService): 전반적인 코드 개선
kdkdhoho Jun 4, 2023
d877c4b
rename: 요청 객체와 응답 객체 패키지 분리
kdkdhoho Jun 4, 2023
27ec5c8
fix: 포인트 사용 시, 사용한 포인트 차감 로직이 빠진 부분 수정
kdkdhoho Jun 5, 2023
a8ef3fc
refactor: 롬복 제거
kdkdhoho Jun 7, 2023
a04ff42
feat(AuthValidateInterceptor): 인증에 대한 기본적인 검증을 수행하는 Interceptor 추가
kdkdhoho Jun 7, 2023
18bf876
refactor: 커스텀 예외 추상화
kdkdhoho Jun 7, 2023
a7a6266
test: 커스텀 예외 추상화에 따른 리팩터링 및 import문 자동 정렬
kdkdhoho Jun 7, 2023
edd7a3e
refactor: Point와 Product의 price를 정교한 값을 위해 타입을 BigDecimal로 변경
kdkdhoho Jun 7, 2023
ce46627
test: BigDecimal 사용으로 인한 코드 수정
kdkdhoho Jun 7, 2023
0321c46
feat(Price): 가격을 값으로 가지는 객체 추가
kdkdhoho Jun 7, 2023
9b0b523
feat(CartItems): CartItem 일급 컬렉션 객체 구현
kdkdhoho Jun 7, 2023
f362e07
feat(CartItem): 상품의 가격과 수량으로 총 상품 금액을 계산해주는 로직 추가
kdkdhoho Jun 7, 2023
e34834b
test: 프로덕트 코드 변경으로 인한 테스트 코드 수정
kdkdhoho Jun 7, 2023
16ac14a
refactor(PointService): 불필요한 로직 제거
kdkdhoho Jun 7, 2023
e8affde
refactor: service 계층이 Response 객체를 반환하지 않도록 리팩터링
kdkdhoho Jun 7, 2023
f54dfa5
refactor(CartItemEntity): 파라미터로 도메인 객체를 받아 값을 꺼내는 생성자 추가
kdkdhoho Jun 7, 2023
7b7d9c3
refactor(OrderService): 주문하기 기능의 메서드 네이밍 변경
kdkdhoho Jun 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: service 계층이 Response 객체를 반환하지 않도록 리팩터링
kdkdhoho committed Jun 7, 2023
commit e8affdedc23da045d39f6c9c0b9428c816755df7
6 changes: 4 additions & 2 deletions src/main/java/cart/dto/response/PointResponse.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cart.dto.response;

import cart.domain.Point;

public class PointResponse {

private final int userPoint;
private final int minUsagePoint;

public PointResponse(int userPoint, int minUsagePoint) {
public PointResponse(int userPoint) {
this.userPoint = userPoint;
this.minUsagePoint = minUsagePoint;
this.minUsagePoint = Point.MIN_USAGE_VALUE;
}

public int getUserPoint() {
20 changes: 18 additions & 2 deletions src/main/java/cart/presentation/CartItemApiController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package cart.presentation;

import cart.domain.CartItem;
import cart.domain.Member;
import cart.dto.request.CartItemAddRequest;
import cart.dto.request.CartItemQuantityUpdateRequest;
import cart.dto.response.CartItemResponse;
import cart.service.CartItemService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 java.net.URI;
import java.util.List;

import static java.util.stream.Collectors.toList;

@RestController
@RequestMapping("/cart-items")
public class CartItemApiController {
@@ -30,7 +40,13 @@ public ResponseEntity<Void> addCartItems(final Member member, final @RequestBody

@GetMapping
public ResponseEntity<List<CartItemResponse>> showCartItems(final Member member) {
return ResponseEntity.ok(cartItemService.findByMember(member));
List<CartItem> cartItems = cartItemService.findByMember(member);

List<CartItemResponse> response = cartItems.stream()
.map(CartItemResponse::from)
.collect(toList());

return ResponseEntity.ok(response);
}

@PatchMapping("/{cartItemId}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

특정 필드만 수정하는거라면
/cartItemId/quantity 가 좀더 적절할것 같네요

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분은 뼈대 코드로 제공된 코드입니다.

하지만, �일부 필드만을 수정하는 PATCH 메서드의 경우에 다른 필드를 수정하는 API가 존재할 수 있으니 말씀해주신 대로 URI에 필드를 명시하는 것이 적절하다고 판단되네요.

현재는 팀 API 명세로 약속되어 있는 부분이기에 변경은 어려울 것 같습니다.
앞으로 개발함에 있어서 참고하도록 하겠습니다 !

62 changes: 56 additions & 6 deletions src/main/java/cart/presentation/OrderApiController.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
package cart.presentation;

import cart.domain.Member;
import cart.domain.OrderEntity;
import cart.domain.OrderItemEntity;
import cart.domain.Product;
import cart.dto.request.OrderRequest;
import cart.dto.response.OrderItemResponse;
import cart.dto.response.OrderResponse;
import cart.service.OrderService;
import cart.service.ProductService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 java.net.URI;
import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.toList;

@RestController
@RequestMapping("/orders")
public class OrderApiController {

private static final int SHOW_ORDER_ITEM_COUNT = 2;

private final OrderService orderService;
private final ProductService productService;

public OrderApiController(OrderService orderService) {
public OrderApiController(OrderService orderService, ProductService productService) {
this.orderService = orderService;
this.productService = productService;
}

@PostMapping
@@ -29,15 +46,48 @@ public ResponseEntity<Void> order(final Member member, final @RequestBody OrderR

@GetMapping
public ResponseEntity<List<OrderResponse>> getAllOrders(final Member member) {
List<OrderResponse> orderResponses = orderService.getAllOrderBy(member.getId());
List<OrderResponse> response = new ArrayList<>();

for (final OrderEntity orderEntity : orderService.getAllOrderBy(member)) {
List<OrderItemResponse> orderItemResponses = toSpecificCountOrderItemResponses(orderEntity);

response.add(OrderResponse.of(orderEntity, orderItemResponses));
}

return ResponseEntity.ok(orderResponses);
return ResponseEntity.ok(response);
}

private List<OrderItemResponse> toSpecificCountOrderItemResponses(final OrderEntity orderEntity) {
List<OrderItemEntity> orderItemEntities = orderService.getSpecificCountOrderItemBy(orderEntity, SHOW_ORDER_ITEM_COUNT);

return createOrderItemResponses(orderItemEntities);
}

private List<OrderItemResponse> createOrderItemResponses(final List<OrderItemEntity> orderItemEntities) {
List<OrderItemResponse> result = new ArrayList<>();

List<Product> products = orderItemEntities.stream()
.map(orderItemEntity -> productService.getProductById(orderItemEntity.getProductId()))
.collect(toList());

for (int index = 0; index < orderItemEntities.size(); index++) {
result.add(OrderItemResponse.of(orderItemEntities.get(index), products.get(index)));
}
return result;
}

@GetMapping("/{orderId}")
public ResponseEntity<OrderResponse> getOrder(final @PathVariable Long orderId) {
OrderResponse orderResponse = orderService.findOrderBy(orderId);
OrderEntity orderEntity = orderService.findByOrderId(orderId);

List<OrderItemResponse> orderItemResponses = toAllOrderItemResponses(orderEntity);

return ResponseEntity.ok(OrderResponse.of(orderEntity, orderItemResponses));
}

private List<OrderItemResponse> toAllOrderItemResponses(final OrderEntity orderEntity) {
List<OrderItemEntity> orderItemEntities = orderService.getAllOrderItemBy(orderEntity);

return ResponseEntity.ok(orderResponse);
return createOrderItemResponses(orderItemEntities);
}
}
5 changes: 3 additions & 2 deletions src/main/java/cart/presentation/PointApiController.java
Original file line number Diff line number Diff line change
@@ -20,8 +20,9 @@ public PointApiController(PointService pointService) {

@GetMapping
public ResponseEntity<PointResponse> getUserPoint(final Member member) {
PointResponse pointResponse = pointService.getUserPoint(member);
int userPoint = pointService.getUserPoint(member);
PointResponse response = new PointResponse(userPoint);

return ResponseEntity.ok(pointResponse);
return ResponseEntity.ok(response);
}
}
24 changes: 21 additions & 3 deletions src/main/java/cart/presentation/ProductApiController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package cart.presentation;

import cart.domain.Product;
import cart.dto.request.ProductAddRequest;
import cart.dto.response.ProductResponse;
import cart.service.ProductService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.List;

import static java.util.stream.Collectors.toList;

@RestController
@RequestMapping("/products")
public class ProductApiController {
@@ -22,12 +32,20 @@ public ProductApiController(ProductService productService) {

@GetMapping
public ResponseEntity<List<ProductResponse>> getAllProducts() {
return ResponseEntity.ok(productService.getAllProducts());
List<Product> products = productService.getAllProducts();
List<ProductResponse> response = products.stream()
.map(ProductResponse::from)
.collect(toList());

return ResponseEntity.ok(response);
}

@GetMapping("/{productId}")
public ResponseEntity<ProductResponse> getProductById(@PathVariable Long productId) {
return ResponseEntity.ok(productService.getProductById(productId));
Product product = productService.getProductById(productId);
ProductResponse response = ProductResponse.from(product);

return ResponseEntity.ok(response);
}

@PostMapping
6 changes: 2 additions & 4 deletions src/main/java/cart/service/CartItemService.java
Original file line number Diff line number Diff line change
@@ -33,16 +33,14 @@ public Long add(final Member member, final CartItemAddRequest cartItemAddRequest
return cartItemRepository.save(cartItem);
}

public List<CartItemResponse> findByMember(final Member member) {
public List<CartItem> findByMember(final Member member) {
List<CartItem> cartItems = cartItemRepository.findByMemberId(member.getId());

for (final CartItem cartItem : cartItems) {
cartItem.validateOwner(member);
}

return cartItems.stream()
.map(CartItemResponse::from)
.collect(Collectors.toList());
return cartItems;
}

public void updateQuantity(final Member member, final Long id, final CartItemQuantityUpdateRequest request) {
31 changes: 12 additions & 19 deletions src/main/java/cart/service/OrderService.java
Original file line number Diff line number Diff line change
@@ -141,30 +141,23 @@ private OrderItemEntity toOrderItemEntity(final long orderId, final ProductInfoR
);
}

public List<OrderResponse> getAllOrderBy(final Long memberId) {
List<OrderResponse> result = new ArrayList<>();

for (final OrderEntity orderEntity : orderDao.findAllByMemberId(memberId)) {
List<OrderItemEntity> twoOrderItemEntities = orderItemDao.findTwoByOrderId(orderEntity.getId());

List<OrderItemResponse> orderItemResponses = twoOrderItemEntities.stream()
.map(orderItemEntity -> OrderItemResponse.of(orderItemEntity, productDao.findById(orderItemEntity.getProductId())))
.collect(toList());

result.add(OrderResponse.of(orderEntity, orderItemResponses));
}
public List<OrderEntity> getAllOrderBy(final Member member) {
return orderDao.findAllByMemberId(member.getId());
}

return result;
public List<OrderItemEntity> getAllOrderItemBy(final OrderEntity orderEntity) {
return orderItemDao.findByOrderId(orderEntity.getId());
}

public OrderResponse findOrderBy(final Long orderId) {
OrderEntity orderEntity = orderDao.findById(orderId);
List<OrderItemEntity> orderItemEntities = orderItemDao.findByOrderId(orderEntity.getId());
public List<OrderItemEntity> getSpecificCountOrderItemBy(final OrderEntity orderEntity, final int count) {
List<OrderItemEntity> orderItemEntities = getAllOrderItemBy(orderEntity);

List<OrderItemResponse> orderItemResponses = orderItemEntities.stream()
.map(orderItemEntity -> OrderItemResponse.of(orderItemEntity, productDao.findById(orderItemEntity.getProductId())))
return orderItemEntities.stream()
.limit(count)
.collect(toList());
}

return OrderResponse.of(orderEntity, orderItemResponses);
public OrderEntity findByOrderId(final Long orderId) {
return orderDao.findById(orderId);
}
}
4 changes: 2 additions & 2 deletions src/main/java/cart/service/PointService.java
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
@Service
public class PointService {

public PointResponse getUserPoint(final Member member) {
return new PointResponse(member.getPointValue(), Point.MIN_USAGE_VALUE);
public int getUserPoint(final Member member) {
return member.getPointValue();
}
}
14 changes: 4 additions & 10 deletions src/main/java/cart/service/ProductService.java
Original file line number Diff line number Diff line change
@@ -4,11 +4,9 @@
import cart.domain.Price;
import cart.domain.Product;
import cart.dto.request.ProductAddRequest;
import cart.dto.response.ProductResponse;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ProductService {
@@ -19,16 +17,12 @@ public ProductService(ProductDao productDao) {
this.productDao = productDao;
}

public List<ProductResponse> getAllProducts() {
List<Product> products = productDao.findAll();

return products.stream().map(ProductResponse::from).collect(Collectors.toList());
public List<Product> getAllProducts() {
return productDao.findAll();
}

public ProductResponse getProductById(Long productId) {
Product product = productDao.findById(productId);

return ProductResponse.from(product);
public Product getProductById(Long productId) {
return productDao.findById(productId);
}

public Long createProduct(ProductAddRequest productAddRequest) {