Skip to content

Commit

Permalink
Merge pull request #146 from UMC-WOWMARKET/feat/MyOrderManage-137
Browse files Browse the repository at this point in the history
[Feat] 수요조사 주문 테이블 생성
  • Loading branch information
yunji118 authored Jan 2, 2024
2 parents d178c88 + 9b55aba commit 1660652
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 30 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;
}
1 change: 0 additions & 1 deletion src/main/java/wowmarket/wow_server/domain/OrderDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import wowmarket.wow_server.mypage.myorder.dto.MyOrderFormItemListRequestDto;

@Entity
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.authorizeRequests() // 요청에 대한 접근 권한을 설정하는 메서드
.requestMatchers("/mypage/**").authenticated()
.requestMatchers("/myorder-sales/**").authenticated()
.requestMatchers("/register/**").authenticated()
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // Preflight Request 허용해주기
.anyRequest().permitAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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
@@ -1,32 +1,31 @@
package wowmarket.wow_server.mypage.myorder.controller;
package wowmarket.wow_server.mypage.myorder.sales.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.mypage.myorder.dto.MyOrderFormDetailResponseDto;
import wowmarket.wow_server.mypage.myorder.dto.MyOrderFormListResponseDto;
import wowmarket.wow_server.mypage.myorder.service.MyOrderService;
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.MyOrderSalesService;

@RestController
@RequestMapping("/mypage/myorder")
@RequestMapping("/myorder-sales")
@RequiredArgsConstructor
public class MyOrderController {
public class MyOrderSalesController {

private final MyOrderService myOrderService;
private final MyOrderSalesService myOrderService;

//나의 주문폼 목록 불러오기
//나의 판매 주문폼 목록 불러오기
@GetMapping()
public MyOrderFormListResponseDto getMyOrderList(@RequestParam(value = "page", defaultValue = "1", required = false)int page, @AuthenticationPrincipal User user){
Pageable pageable = PageRequest.of(page - 1, 10);
return myOrderService.findAllMyOrderForm(pageable, user);
}

//나의 주문폼 상세 보기
//나의 판매 주문폼 상세 보기
@GetMapping("/detail/{order_id}")
public MyOrderFormDetailResponseDto getMyDetailOrder(@PathVariable Long order_id){
return myOrderService.findMyOrderFormDetail(order_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wowmarket.wow_server.mypage.myorder.dto;
package wowmarket.wow_server.mypage.myorder.sales.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package wowmarket.wow_server.mypage.myorder.dto;
package wowmarket.wow_server.mypage.myorder.sales.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.Orders;
import wowmarket.wow_server.domain.Project;

import java.time.LocalDateTime;
import java.util.List;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wowmarket.wow_server.mypage.myorder.dto;
package wowmarket.wow_server.mypage.myorder.sales.dto;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package wowmarket.wow_server.mypage.myorder.dto;
package wowmarket.wow_server.mypage.myorder.sales.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wowmarket.wow_server.mypage.myorder.dto;
package wowmarket.wow_server.mypage.myorder.sales.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wowmarket.wow_server.mypage.myorder.service;
package wowmarket.wow_server.mypage.myorder.sales.service;

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -11,8 +11,10 @@
import wowmarket.wow_server.domain.OrderDetail;
import wowmarket.wow_server.domain.Orders;
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.global.jwt.SecurityUtil;
import wowmarket.wow_server.mypage.myorder.dto.*;
import wowmarket.wow_server.mypage.myorder.sales.dto.MyOrderFormDetailDto;
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.dto.MyOrderFormResponseDto;
import wowmarket.wow_server.repository.OrderDetailRepository;
import wowmarket.wow_server.repository.OrderRepository;
import wowmarket.wow_server.repository.UserRepository;
Expand All @@ -22,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
Expand Up @@ -13,7 +13,7 @@
import wowmarket.wow_server.mypage.myproject.MyDemandProject.service.MyDemandProjectService;

@RestController
@RequestMapping("/mypage/myproject/demand")
@RequestMapping("/myproject/demand")
@RequiredArgsConstructor
public class MyDemandProjectController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import wowmarket.wow_server.mypage.myproject.MySalesOrder.service.MySalesOrderService;

@RestController
@RequestMapping("/mypage/myproject/order")
@RequestMapping("/myproject/order")
@RequiredArgsConstructor
public class MySalesOrderController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import wowmarket.wow_server.mypage.myproject.MySalesProject.service.MySalesProjectService;

@RestController
@RequestMapping("/mypage/myproject")
@RequestMapping("/myproject")
@RequiredArgsConstructor
public class MySalesProjectController {
private final MySalesProjectService mySalesProjectService;
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 1660652

Please sign in to comment.