Skip to content

Commit

Permalink
[feat]나의 수요조사 주문폼 전체보기 #137
Browse files Browse the repository at this point in the history
  • Loading branch information
yunji118 committed Jan 2, 2024
1 parent 98fff52 commit 9b55aba
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/main/java/wowmarket/wow_server/domain/DemandDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/wowmarket/wow_server/domain/DemandOrder.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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();

}
}
Original file line number Diff line number Diff line change
@@ -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<MyDemandOrderFormDto> demand_order_list;
private int total_page;
private int current_page;

public MyDemandOrderFormListResponseDto(List<MyDemandOrderFormDto> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<DemandOrder> demandOrders = demandOrderRepository.findByUser_Id(user.getId(), pageable);
Page<MyDemandOrderFormDto> demandOrderFormDtos = demandOrders.map(MyDemandOrderFormDto::new);
MyDemandOrderFormListResponseDto responseDto = new MyDemandOrderFormListResponseDto(demandOrderFormDtos.getContent(),
demandOrderFormDtos.getTotalPages(), demandOrderFormDtos.getNumber());
return responseDto;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DemandOrder, Long> {

Page<DemandOrder> findByUser_Id(Long buyer_id, Pageable pageable);
}

0 comments on commit 9b55aba

Please sign in to comment.