Skip to content

Commit

Permalink
Merge pull request #7 from MARKETFUBY/feat/search
Browse files Browse the repository at this point in the history
feat: 마이페이지 주문내역 확인 API
  • Loading branch information
choiyounji authored Nov 14, 2023
2 parents ce54ae0 + a78f23c commit 72e6e36
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/main/java/MARKETFUBY/Order/controller/OrderController.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
8 changes: 8 additions & 0 deletions src/main/java/MARKETFUBY/Order/domain/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -12,6 +13,7 @@
import java.util.Date;
import java.util.List;

@Getter
@Entity
@Table(name="orderr")
@NoArgsConstructor
Expand All @@ -30,6 +32,12 @@ public class Order {
@Column
private String status;

@Column
private String paymentType;

@Column
private Long totalPrice;

@OneToMany(mappedBy = "order")
private List<OrderProduct> orderList = new ArrayList<>();

Expand Down
43 changes: 43 additions & 0 deletions src/main/java/MARKETFUBY/Order/dto/OrderDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
51 changes: 51 additions & 0 deletions src/main/java/MARKETFUBY/Order/dto/OrderResponseDto.java
Original file line number Diff line number Diff line change
@@ -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<OrderDto> orderList;
}
12 changes: 12 additions & 0 deletions src/main/java/MARKETFUBY/Order/repository/OrderRepository.java
Original file line number Diff line number Diff line change
@@ -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<Order, Long> {
List<Order> findAllByOrderer(Member member);
}
62 changes: 62 additions & 0 deletions src/main/java/MARKETFUBY/Order/service/OrderService.java
Original file line number Diff line number Diff line change
@@ -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<OrderDto> 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<Order> orderList=orderRepository.findAllByOrderer(member);
for(Order order:orderList){
List<OrderProduct> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrderProduct, Long> {
List<OrderProduct> findAllByOrder(Order order);
Optional<OrderProduct> findTop1ByOrder(Order order);
}
8 changes: 6 additions & 2 deletions src/main/java/MARKETFUBY/Product/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down Expand Up @@ -189,16 +191,18 @@ public SearchDto getSearchList(String sword, Integer sort, Long filters){
newProductsDto.setProductList(productDtoList);
List<CategoryDto> categoryList=new ArrayList<>();
List<BigCategory> 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());
categoryDto.setBigCategoryId(category.getBigcategoryId());
categoryList.add(categoryDto);
}
}

newProductsDto.setCategoryList(categoryList);
newProductsDto.setTotal(productDtoList.size());

Expand Down

0 comments on commit 72e6e36

Please sign in to comment.