-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from MARKETFUBY/feat/search
feat: 마이페이지 주문내역 확인 API
- Loading branch information
Showing
9 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/MARKETFUBY/Order/controller/OrderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/main/java/MARKETFUBY/Order/repository/OrderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/MARKETFUBY/OrderProduct/repository/OrderProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters