Skip to content

Commit

Permalink
Merge branch 'deploy' of https://github.com/Orange-Co/DDANZI_Server i…
Browse files Browse the repository at this point in the history
…nto feature/order
  • Loading branch information
Kang1221 committed Aug 20, 2024
2 parents 45258ef + 8775765 commit 8a4cd12
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ ApiResponse<?> getMyPage(){
return myPageService.getMyPage();
}

@GetMapping("order")
ApiResponse<?> getMyOrder(){
return myPageService.getMyOrder();
}


@GetMapping("/interest")
ApiResponse<?> getInterest(){
return myPageService.getInterest();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/mypage/MyOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package co.orange.ddanzi.dto.mypage;

import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class MyOrder {
private String productId;
private String orderId;
private String productName;
private String imgUrl;
private Integer originPrice;
private Integer salePrice;
private LocalDateTime paidAt;
}
13 changes: 13 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/mypage/MyOrderResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.orange.ddanzi.dto.mypage;

import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class MyOrderResponseDto {
private Integer totalCount;
private List<MyOrder> orderProductList;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package co.orange.ddanzi.repository;

import co.orange.ddanzi.domain.order.Order;
import co.orange.ddanzi.domain.user.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface OrderRepository extends JpaRepository<Order, String> {

List<Order> findByBuyer(User user);
}
41 changes: 41 additions & 0 deletions src/main/java/co/orange/ddanzi/service/MyPageService.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package co.orange.ddanzi.service;

import co.orange.ddanzi.domain.order.Order;
import co.orange.ddanzi.domain.order.Payment;
import co.orange.ddanzi.domain.product.Discount;
import co.orange.ddanzi.domain.product.Product;
import co.orange.ddanzi.domain.user.User;
import co.orange.ddanzi.dto.ProductInfo;
import co.orange.ddanzi.dto.mypage.MyOrder;
import co.orange.ddanzi.dto.mypage.MyOrderResponseDto;
import co.orange.ddanzi.dto.mypage.MyPageInterestResponseDto;
import co.orange.ddanzi.common.response.ApiResponse;
import co.orange.ddanzi.common.response.Success;
import co.orange.ddanzi.global.jwt.AuthUtils;
import co.orange.ddanzi.repository.DiscountRepository;
import co.orange.ddanzi.repository.InterestProductRepository;
import co.orange.ddanzi.repository.OrderRepository;
import co.orange.ddanzi.repository.PaymentRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -23,6 +32,9 @@
public class MyPageService {
private final AuthUtils authUtils;
private final HomeService homeService;
private final DiscountRepository discountRepository;
private final OrderRepository orderRepository;
private final PaymentRepository paymentRepository;
private final InterestProductRepository interestProductRepository;

@Transactional
Expand All @@ -34,6 +46,35 @@ public ApiResponse<?> getMyPage(){
return ApiResponse.onSuccess(Success.GET_MY_PAGE_INFO_SUCCESS, response);
}

@Transactional
public ApiResponse<?> getMyOrder(){
User user = authUtils.getUser();
List<Order> orderList = orderRepository.findByBuyer(user);

List<MyOrder> orderProductList = new ArrayList<>();

for (Order order : orderList) {
Product product = order.getItem().getProduct();
Discount discount = discountRepository.findById(product.getId()).orElse(null);
Payment payment = paymentRepository.findByBuyerAndItem(user, order.getItem());
MyOrder myOrder = MyOrder.builder()
.productId(product.getId())
.orderId(order.getId())
.productName(product.getName())
.imgUrl(product.getImgUrl())
.originPrice(product.getOriginPrice())
.salePrice(product.getOriginPrice()-discount.getDiscountPrice())
.paidAt(payment.getEndedAt())
.build();

orderProductList.add(myOrder);
}
return ApiResponse.onSuccess(Success.GET_MY_ORDER_LIST_SUCCESS, MyOrderResponseDto.builder()
.totalCount(orderList.size())
.orderProductList(orderProductList)
.build());
}

@Transactional
public ApiResponse<?> getInterest(){
User user = authUtils.getUser();
Expand Down

0 comments on commit 8a4cd12

Please sign in to comment.