From ea295967be47073c4fc436661b1a3bf177dd6910 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Tue, 14 Nov 2023 23:23:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=EC=A0=9C=ED=92=88=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20GET=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/MARKETFUBY/Product/service/ProductService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/MARKETFUBY/Product/service/ProductService.java b/src/main/java/MARKETFUBY/Product/service/ProductService.java index ea4e394..8576d2c 100644 --- a/src/main/java/MARKETFUBY/Product/service/ProductService.java +++ b/src/main/java/MARKETFUBY/Product/service/ProductService.java @@ -138,12 +138,14 @@ public ProductsListDto getProductList(Integer sort, Long filters, Long eventId){ CategoryDto categoryDto=new CategoryDto(); categoryDto.setCount(count); categoryDto.setName(category.getName()); + categoryDto.setBigCategoryId(category.getBigcategoryId()); categoryList.add(categoryDto); } } newProductsDto.setCategoryList(categoryList); newProductsDto.setTotal(productDtoList.size()); + return newProductsDto; } @@ -189,9 +191,10 @@ public SearchDto getSearchList(String sword, Integer sort, Long filters){ newProductsDto.setProductList(productDtoList); List categoryList=new ArrayList<>(); List bigCategoryList=categoryRepository.findAll(); + for(BigCategory category:bigCategoryList){ - if(productRepository.existsByBigCategory(category)){ - int count= productRepository.countByTitleContainingAndBigCategory(sword, category); + int count= productRepository.countByTitleContainingAndBigCategory(sword, category); + if(count!=0){ CategoryDto categoryDto=new CategoryDto(); categoryDto.setCount(count); categoryDto.setName(category.getName()); @@ -199,6 +202,7 @@ public SearchDto getSearchList(String sword, Integer sort, Long filters){ categoryList.add(categoryDto); } } + newProductsDto.setCategoryList(categoryList); newProductsDto.setTotal(productDtoList.size()); From a78f23c5362b3d712cd0897d54af43c6fed5badf Mon Sep 17 00:00:00 2001 From: choiyounji Date: Tue, 14 Nov 2023 23:52:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A3=BC=EB=AC=B8=EB=82=B4=EC=97=AD=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/controller/OrderController.java | 26 ++++++++ .../java/MARKETFUBY/Order/domain/Order.java | 8 +++ .../java/MARKETFUBY/Order/dto/OrderDto.java | 43 +++++++++++++ .../Order/dto/OrderResponseDto.java | 51 +++++++++++++++ .../Order/repository/OrderRepository.java | 12 ++++ .../Order/service/OrderService.java | 62 +++++++++++++++++++ .../OrderProduct/domain/OrderProduct.java | 2 + .../repository/OrderProductRepository.java | 14 +++++ 8 files changed, 218 insertions(+) create mode 100644 src/main/java/MARKETFUBY/Order/controller/OrderController.java create mode 100644 src/main/java/MARKETFUBY/Order/dto/OrderDto.java create mode 100644 src/main/java/MARKETFUBY/Order/dto/OrderResponseDto.java create mode 100644 src/main/java/MARKETFUBY/Order/repository/OrderRepository.java create mode 100644 src/main/java/MARKETFUBY/Order/service/OrderService.java create mode 100644 src/main/java/MARKETFUBY/OrderProduct/repository/OrderProductRepository.java diff --git a/src/main/java/MARKETFUBY/Order/controller/OrderController.java b/src/main/java/MARKETFUBY/Order/controller/OrderController.java new file mode 100644 index 0000000..8e75a2f --- /dev/null +++ b/src/main/java/MARKETFUBY/Order/controller/OrderController.java @@ -0,0 +1,26 @@ +package MARKETFUBY.Order.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import MARKETFUBY.Order.dto.OrderResponseDto; +import MARKETFUBY.Order.repository.OrderRepository; +import MARKETFUBY.Order.service.OrderService; +import MARKETFUBY.Product.dto.MainDto; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping(value="mypage/order") +@RequiredArgsConstructor +public class OrderController { + private final OrderService orderService; + + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public OrderResponseDto getOrderList() { + return orderService.getOrderList(); + } +} diff --git a/src/main/java/MARKETFUBY/Order/domain/Order.java b/src/main/java/MARKETFUBY/Order/domain/Order.java index d977645..e8b4102 100644 --- a/src/main/java/MARKETFUBY/Order/domain/Order.java +++ b/src/main/java/MARKETFUBY/Order/domain/Order.java @@ -3,6 +3,7 @@ import MARKETFUBY.Member.domain.Member; import MARKETFUBY.OrderProduct.domain.OrderProduct; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; @@ -12,6 +13,7 @@ import java.util.Date; import java.util.List; +@Getter @Entity @Table(name="orderr") @NoArgsConstructor @@ -30,6 +32,12 @@ public class Order { @Column private String status; + @Column + private String paymentType; + + @Column + private Long totalPrice; + @OneToMany(mappedBy = "order") private List orderList = new ArrayList<>(); diff --git a/src/main/java/MARKETFUBY/Order/dto/OrderDto.java b/src/main/java/MARKETFUBY/Order/dto/OrderDto.java new file mode 100644 index 0000000..dc152e1 --- /dev/null +++ b/src/main/java/MARKETFUBY/Order/dto/OrderDto.java @@ -0,0 +1,43 @@ +package MARKETFUBY.Order.dto; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import MARKETFUBY.OrderProduct.domain.OrderProduct; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/* +*"image":"image3.jpg", + "datetime":"2023.09.14(15시18분)", + "title":"이유식 재료 친환경 양배추 1/4통 외 7건", + "orderId":32351, + "paymentType":"네이버페이", + "price":40272, + "deliveryStatus":"배송완료" +* */ +@Getter +@Setter +@NoArgsConstructor +public class OrderDto { + private String imageUrl; + private LocalDate date; + private String title; + private Long orderId; + private String paymentType; + private Long price; + private String deliveryStatus; + + @Builder + public OrderDto(String imageUrl, LocalDate date, String title, Long orderId, String paymentType, Long price, String deliveryStatus){ + this.imageUrl=imageUrl; + this.date=date; + this.title=title; + this.orderId=orderId; + this.paymentType=paymentType; + this.price=price; + this.deliveryStatus=deliveryStatus; + } +} diff --git a/src/main/java/MARKETFUBY/Order/dto/OrderResponseDto.java b/src/main/java/MARKETFUBY/Order/dto/OrderResponseDto.java new file mode 100644 index 0000000..bb7434c --- /dev/null +++ b/src/main/java/MARKETFUBY/Order/dto/OrderResponseDto.java @@ -0,0 +1,51 @@ +package MARKETFUBY.Order.dto; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/* +* { + "name":"최윤지", + "level":"화이트", + "orderList":[ + { + "image":"image1.jpg", + "datetime":"2023.09.14(15시18분)", + "title":"이유식 재료 친환경 양배추 1/4통 외 7건", + "orderId":32351, + "paymentType":"네이버페이", + "price":40272, + "deliveryStatus":"배송완료" + }, + { + "image":"image2.jpg", + "datetime":"2023.09.14(15시18분)", + "title":"이유식 재료 친환경 양배추 1/4통 외 7건", + "orderId":32351, + "paymentType":"네이버페이", + "price":40272, + "deliveryStatus":"배송완료" + }, + { + "image":"image3.jpg", + "datetime":"2023.09.14(15시18분)", + "title":"이유식 재료 친환경 양배추 1/4통 외 7건", + "orderId":32351, + "paymentType":"네이버페이", + "price":40272, + "deliveryStatus":"배송완료" + } + ] +} +* */ +@Getter +@Setter +@NoArgsConstructor +public class OrderResponseDto { + private String name; + private String level; + private List orderList; +} diff --git a/src/main/java/MARKETFUBY/Order/repository/OrderRepository.java b/src/main/java/MARKETFUBY/Order/repository/OrderRepository.java new file mode 100644 index 0000000..d32bc90 --- /dev/null +++ b/src/main/java/MARKETFUBY/Order/repository/OrderRepository.java @@ -0,0 +1,12 @@ +package MARKETFUBY.Order.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import MARKETFUBY.Member.domain.Member; +import MARKETFUBY.Order.domain.Order; + +public interface OrderRepository extends JpaRepository { + List findAllByOrderer(Member member); +} diff --git a/src/main/java/MARKETFUBY/Order/service/OrderService.java b/src/main/java/MARKETFUBY/Order/service/OrderService.java new file mode 100644 index 0000000..2386638 --- /dev/null +++ b/src/main/java/MARKETFUBY/Order/service/OrderService.java @@ -0,0 +1,62 @@ +package MARKETFUBY.Order.service; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.stereotype.Service; + +import MARKETFUBY.Member.domain.Member; +import MARKETFUBY.Member.repository.MemberRepository; +import MARKETFUBY.Order.domain.Order; +import MARKETFUBY.Order.dto.OrderDto; +import MARKETFUBY.Order.dto.OrderResponseDto; +import MARKETFUBY.Order.repository.OrderRepository; +import MARKETFUBY.OrderProduct.domain.OrderProduct; +import MARKETFUBY.OrderProduct.repository.OrderProductRepository; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class OrderService { + private final OrderRepository orderRepository; + private final MemberRepository memberRepository; + private final OrderProductRepository orderProductRepository; + + public OrderResponseDto getOrderList(){ + + OrderResponseDto orderResponseDto =new OrderResponseDto(); + List orderDtoList=new ArrayList<>(); + //현재 로그인 중인 사용자 불러오는 단계 필요 + Long memberId=1L; + Member member=memberRepository.findById(memberId).orElseThrow(()->new IllegalArgumentException("존재하지 않는 회원입니다.")); + orderResponseDto.setName(member.getName()); + orderResponseDto.setLevel(member.getLevel()); + + //orderId로 orderproduct하나 찾고, orderproduct 개수 찾고 + List orderList=orderRepository.findAllByOrderer(member); + for(Order order:orderList){ + List orderProduct=orderProductRepository.findAllByOrder(order); + int count = orderProduct.size(); + OrderProduct TopOrderProduct=orderProductRepository.findTop1ByOrder(order).orElseThrow(()->new IllegalArgumentException("존재하지 않는 주문내역제품입니다.")); + String title=""; + if(count!=1){ + title=TopOrderProduct.getProduct().getTitle()+"외 "+(count-1)+"종"; + } + else{ + title=TopOrderProduct.getProduct().getTitle(); + } + OrderDto orderDto=OrderDto.builder() + .imageUrl(TopOrderProduct.getProduct().getImage()) + .date(order.getDate()) + .title(title) + .orderId(order.getOrderId()) + .paymentType(order.getPaymentType()) + .price(order.getTotalPrice()) + .deliveryStatus(order.getStatus()) + .build(); + orderDtoList.add(orderDto); + } + orderResponseDto.setOrderList(orderDtoList); + + return orderResponseDto; + } +} diff --git a/src/main/java/MARKETFUBY/OrderProduct/domain/OrderProduct.java b/src/main/java/MARKETFUBY/OrderProduct/domain/OrderProduct.java index 01cc9cb..c186a6c 100644 --- a/src/main/java/MARKETFUBY/OrderProduct/domain/OrderProduct.java +++ b/src/main/java/MARKETFUBY/OrderProduct/domain/OrderProduct.java @@ -3,10 +3,12 @@ import MARKETFUBY.Order.domain.Order; import MARKETFUBY.Product.domain.Product; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import javax.persistence.*; +@Getter @Entity @Table(name = "orderproduct") @NoArgsConstructor diff --git a/src/main/java/MARKETFUBY/OrderProduct/repository/OrderProductRepository.java b/src/main/java/MARKETFUBY/OrderProduct/repository/OrderProductRepository.java new file mode 100644 index 0000000..1d4fc90 --- /dev/null +++ b/src/main/java/MARKETFUBY/OrderProduct/repository/OrderProductRepository.java @@ -0,0 +1,14 @@ +package MARKETFUBY.OrderProduct.repository; + +import java.util.List; +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +import MARKETFUBY.Order.domain.Order; +import MARKETFUBY.OrderProduct.domain.OrderProduct; + +public interface OrderProductRepository extends JpaRepository { + List findAllByOrder(Order order); + Optional findTop1ByOrder(Order order); +}