diff --git a/src/main/java/wowmarket/wow_server/domain/DemandDetail.java b/src/main/java/wowmarket/wow_server/domain/DemandDetail.java index e12a7f3..856f4cd 100644 --- a/src/main/java/wowmarket/wow_server/domain/DemandDetail.java +++ b/src/main/java/wowmarket/wow_server/domain/DemandDetail.java @@ -21,9 +21,13 @@ public class DemandDetail extends BaseEntity{ @JoinColumn(name = "demand_item_id", referencedColumnName = "demand_item_id") private DemandItem demandItem; +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "buyer_id", referencedColumnName = "user_id") +// private User user; + @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "buyer_id", referencedColumnName = "user_id") - private User user; + @JoinColumn(name = "demand_order_id", referencedColumnName = "demand_order_id") + private DemandOrder demandOrder; @ColumnDefault("0") private int count; diff --git a/src/main/java/wowmarket/wow_server/domain/DemandOrder.java b/src/main/java/wowmarket/wow_server/domain/DemandOrder.java new file mode 100644 index 0000000..21d666f --- /dev/null +++ b/src/main/java/wowmarket/wow_server/domain/DemandOrder.java @@ -0,0 +1,31 @@ +package wowmarket.wow_server.domain; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; + +@Entity +@Getter +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "demand_orders") +@AttributeOverride(name = "created_time", column = @Column(name = "order_time")) +public class DemandOrder extends BaseEntity{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "demand_order_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "buyer_id", referencedColumnName = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "demand_project_id", referencedColumnName = "demand_project_id") + private DemandProject demandProject; + + @ColumnDefault("0") + @Setter + private int isDel; +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/demand/controller/MyDemandOrderController.java b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/controller/MyDemandOrderController.java index ce43d76..dda1f60 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myorder/demand/controller/MyDemandOrderController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/controller/MyDemandOrderController.java @@ -1,10 +1,12 @@ package wowmarket.wow_server.mypage.myorder.demand.controller; +import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/myorder-demand") +@RequiredArgsConstructor public class MyDemandOrderController { } diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormDto.java b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormDto.java new file mode 100644 index 0000000..79ac346 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormDto.java @@ -0,0 +1,28 @@ +package wowmarket.wow_server.mypage.myorder.demand.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import wowmarket.wow_server.domain.DemandOrder; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +public class MyDemandOrderFormDto { + private Long demand_order_id; + private String name; + private LocalDateTime createdtime; + private int is_del; + private String description; + private String thumbnail; + + public MyDemandOrderFormDto(DemandOrder order){ + this.demand_order_id = order.getId(); + this.name = order.getDemandProject().getProjectName(); + this.createdtime = order.getCreated_time(); + this.is_del = order.getIsDel(); + this.description = order.getDemandProject().getDescription(); + this.thumbnail = order.getDemandProject().getThumbnail(); + + } +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormListResponseDto.java b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormListResponseDto.java new file mode 100644 index 0000000..1f23583 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/dto/MyDemandOrderFormListResponseDto.java @@ -0,0 +1,21 @@ +package wowmarket.wow_server.mypage.myorder.demand.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class MyDemandOrderFormListResponseDto { + //나의 수요조사 주문폼 전체보기 리스트 dto + private List demand_order_list; + private int total_page; + private int current_page; + + public MyDemandOrderFormListResponseDto(List demand_order_list, int total_page, int current_page){ + this.demand_order_list = demand_order_list; + this.total_page = total_page; + this.current_page = current_page; + } +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/demand/service/MyOrderDemandService.java b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/service/MyOrderDemandService.java new file mode 100644 index 0000000..6a9dd76 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/demand/service/MyOrderDemandService.java @@ -0,0 +1,34 @@ +package wowmarket.wow_server.mypage.myorder.demand.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; +import wowmarket.wow_server.domain.DemandOrder; +import wowmarket.wow_server.domain.User; +import wowmarket.wow_server.mypage.myorder.demand.dto.MyDemandOrderFormDto; +import wowmarket.wow_server.mypage.myorder.demand.dto.MyDemandOrderFormListResponseDto; +import wowmarket.wow_server.repository.DemandDetailRepository; +import wowmarket.wow_server.repository.DemandOrderRepository; + +@Service +@RequiredArgsConstructor +public class MyOrderDemandService { + private final DemandOrderRepository demandOrderRepository; + private final DemandDetailRepository demandDetailRepository; + + @Transactional(readOnly = true) + public MyDemandOrderFormListResponseDto findMyAllDemandOrderForm(Pageable pageable, User user){ + if (user == null) + throw new ResponseStatusException(HttpStatus.BAD_REQUEST); + Page demandOrders = demandOrderRepository.findByUser_Id(user.getId(), pageable); + Page demandOrderFormDtos = demandOrders.map(MyDemandOrderFormDto::new); + MyDemandOrderFormListResponseDto responseDto = new MyDemandOrderFormListResponseDto(demandOrderFormDtos.getContent(), + demandOrderFormDtos.getTotalPages(), demandOrderFormDtos.getNumber()); + return responseDto; + } + +} diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderController.java b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java similarity index 93% rename from src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderController.java rename to src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java index 68db4b1..14fa408 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderController.java +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/controller/MyOrderSalesController.java @@ -9,14 +9,14 @@ import wowmarket.wow_server.domain.User; import wowmarket.wow_server.mypage.myorder.sales.dto.MyOrderFormDetailResponseDto; import wowmarket.wow_server.mypage.myorder.sales.dto.MyOrderFormListResponseDto; -import wowmarket.wow_server.mypage.myorder.sales.service.MyOrderService; +import wowmarket.wow_server.mypage.myorder.sales.service.MyOrderSalesService; @RestController @RequestMapping("/myorder-sales") @RequiredArgsConstructor -public class MyOrderController { +public class MyOrderSalesController { - private final MyOrderService myOrderService; + private final MyOrderSalesService myOrderService; //나의 판매 주문폼 목록 불러오기 @GetMapping() diff --git a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderService.java b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java similarity index 97% rename from src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderService.java rename to src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java index 3053b33..ae36df1 100644 --- a/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderService.java +++ b/src/main/java/wowmarket/wow_server/mypage/myorder/sales/service/MyOrderSalesService.java @@ -24,10 +24,9 @@ @Service @RequiredArgsConstructor -public class MyOrderService { +public class MyOrderSalesService { private final OrderRepository orderRepository; private final OrderDetailRepository orderDetailRepository; - private final UserRepository userRepository; @Transactional(readOnly = true) public MyOrderFormListResponseDto findAllMyOrderForm(Pageable pageable, User user){ diff --git a/src/main/java/wowmarket/wow_server/repository/DemandOrderRepository.java b/src/main/java/wowmarket/wow_server/repository/DemandOrderRepository.java new file mode 100644 index 0000000..11fe83f --- /dev/null +++ b/src/main/java/wowmarket/wow_server/repository/DemandOrderRepository.java @@ -0,0 +1,11 @@ +package wowmarket.wow_server.repository; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import wowmarket.wow_server.domain.DemandOrder; + +public interface DemandOrderRepository extends JpaRepository { + + Page findByUser_Id(Long buyer_id, Pageable pageable); +}