Skip to content

Commit

Permalink
feature: getProductOrderList api
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunihs committed Sep 14, 2024
1 parent 72ff097 commit fc88ca9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public SuccessResponse<Boolean> validateOrder(@RequestBody PostPayment postPayme
return SuccessResponse.createSuccess(productOrderService.validatePayment(postPayment));
}

@Operation(summary = "์ฃผ๋ฌธ ๋‚ด์—ญ ๋ฆฌ์ŠคํŠธ")
@GetMapping
public SuccessResponse<PageResponse<List<GetProductOrderForUser>>> getProductOrdersForUser(@ParameterObject PageCondition pageCondition) {
return SuccessResponse.success(productOrderService.getProductOrdersForUser(pageCondition));
}


@Operation(summary = "์ƒํ’ˆ ๊ตฌ๋งค ํ™•์ •",
description = """
๊ตฌ๋งค๋ฅผ ํ™•์ •ํ•ฉ๋‹ˆ๋‹ค.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.repick.domain.product.dto.productOrder;

import com.example.repick.domain.product.entity.Product;
import com.example.repick.domain.product.entity.ProductOrder;
import io.swagger.v3.oas.annotations.media.Schema;

public record GetProductOrderForUser(
@Schema(description = "์ฃผ๋ฌธ ์•„์ด๋””") long productOrderId,
@Schema(description = "๋ธŒ๋žœ๋“œ ์ด๋ฆ„") String brandName,
@Schema(description = "์ƒํ’ˆ ์ด๋ฆ„") String productName,
@Schema(description = "์ƒํ’ˆ ์ด๋ฏธ์ง€ URL") String productImageUrl,
@Schema(description = "๊ตฌ๋งคํ™•์ • ์—ฌ๋ถ€") Boolean isConfirmed
) {
public static GetProductOrderForUser from(ProductOrder productOrder, Product product) {
return new GetProductOrderForUser(
productOrder.getId(),
product.getBrandName(),
product.getProductName(),
product.getThumbnailImageUrl(),
productOrder.isConfirmed()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface ProductOrderRepository extends JpaRepository<ProductOrder, Long
List<ProductOrder> findByIsConfirmed(boolean isConfirmed);

List<ProductOrder> findByUserId(Long userId);
Page<ProductOrder> findByUserId(Long userId, Pageable pageable);

Page<ProductOrder> findByProductOrderStateIn(List<ProductOrderState> productOrderStates, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ private void cancelPayment(Payment payment) {
paymentRepository.save(payment);
}

public PageResponse<List<GetProductOrderForUser>> getProductOrdersForUser(PageCondition pageCondition) {
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
Pageable pageable = pageCondition.toPageable();
Page<ProductOrder> productOrderPage = productOrderRepository.findByUserId(user.getId(), pageable);
List<GetProductOrderForUser> getProductOrders = productOrderPage.stream()
.map(productOrder -> {
Product product = productRepository.findById(productOrder.getProductId())
.orElseThrow(() -> new CustomException(INVALID_PRODUCT_ID));
return GetProductOrderForUser.from(productOrder, product);
}).toList();
Page<GetProductOrderForUser> page = new PageImpl<>(getProductOrders, pageable, productOrderPage.getTotalElements());
return new PageResponse<>(page.getContent(), page.getTotalPages(), page.getTotalElements());
}

@Transactional
public Boolean confirmProductOrder(Long productOrderId){
ProductOrder productOrder = productOrderRepository.findById(productOrderId)
Expand Down

0 comments on commit fc88ca9

Please sign in to comment.