diff --git a/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java b/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java index 3075a83..0d8a8ae 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java +++ b/src/main/java/wowmarket/wow_server/detail/project/controller/ProjectController.java @@ -40,13 +40,13 @@ public ProjectImgResponseDto getProjectImg(@PathVariable Long project_id) { // return itemService.getItemInfo(project_id); // } - //주문폼: 우측 폼 정보 불러오기 + //주문폼: 우측 폼 정보 불러오기 *수정 필요* @GetMapping("/{project_id}/item") //path 수정해야함 public OrderResponseDto getItemInfo(@PathVariable Long project_id){ return itemService.getItemInfo(project_id); } - //주문폼: 폼 등록 + //주문폼: 폼 등록 *수정 필요* @PostMapping("/{project_id}") public ResponseEntity createDemandForm(@PathVariable Long project_id, @RequestBody OrderFormRequestDto requestDto){ return orderService.createOrderForm(project_id, requestDto); diff --git a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderAnswerDto.java b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderAnswerDto.java new file mode 100644 index 0000000..faefd67 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderAnswerDto.java @@ -0,0 +1,9 @@ +package wowmarket.wow_server.detail.project.dto; + +import lombok.Getter; + +@Getter +public class OrderAnswerDto { + private Long questionId; //추가질문 id + private String answer; //답변 내용 +} \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderFormRequestDto.java b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderFormRequestDto.java index 60c39fb..a35a20e 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderFormRequestDto.java +++ b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderFormRequestDto.java @@ -28,4 +28,7 @@ public class OrderFormRequestDto { //상품명 & 판매가 리스트 List orderRequestDtoList; + + //추가질문 답변 리스트 + List orderAnswerDtoList; } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderQuestionResponseDto.java b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderQuestionResponseDto.java new file mode 100644 index 0000000..35a3b4f --- /dev/null +++ b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderQuestionResponseDto.java @@ -0,0 +1,19 @@ +package wowmarket.wow_server.detail.project.dto; + +import lombok.Getter; +import wowmarket.wow_server.domain.OrderQuestion; + +//주문폼 추가질문 정보 불러오는 Dto + +@Getter +public class OrderQuestionResponseDto { + private Long id; + private String question; //질문 내용 + private boolean essential; //필수 여부 + + public OrderQuestionResponseDto(OrderQuestion orderQuestion) { + this.id = orderQuestion.getId(); + this.question = orderQuestion.getQuestion(); + this.essential = orderQuestion.isEssential(); + } +} \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderResponseDto.java b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderResponseDto.java index 78440e4..e52362b 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/dto/OrderResponseDto.java +++ b/src/main/java/wowmarket/wow_server/detail/project/dto/OrderResponseDto.java @@ -21,8 +21,9 @@ public class OrderResponseDto { private String account_holder_name; //예금주 private List itemResponseDtoList; + private List orderQuestionResponseDtoList; - public OrderResponseDto(Project project, List itemResponseDtoList) { + public OrderResponseDto(Project project, List itemResponseDtoList, List orderQuestionResponseDtoList) { this.receive_type=project.getReceive_type().toString(); this.receive_address=project.getReceive_address(); this.delivery_fee=project.getDelivery_fee(); @@ -30,5 +31,6 @@ public OrderResponseDto(Project project, List itemResponseDtoLi this.account=project.getAccount(); this.account_holder_name = project.getAccount_holder_name(); this.itemResponseDtoList = itemResponseDtoList; + this.orderQuestionResponseDtoList = orderQuestionResponseDtoList; } } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/project/service/ItemService.java b/src/main/java/wowmarket/wow_server/detail/project/service/ItemService.java index 2366868..5de2910 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/service/ItemService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/service/ItemService.java @@ -4,10 +4,13 @@ import jakarta.persistence.criteria.Order; import org.springframework.stereotype.Service; import wowmarket.wow_server.detail.project.dto.ItemResponseDto; +import wowmarket.wow_server.detail.project.dto.OrderQuestionResponseDto; import wowmarket.wow_server.detail.project.dto.OrderResponseDto; import wowmarket.wow_server.domain.Item; +import wowmarket.wow_server.domain.OrderQuestion; import wowmarket.wow_server.domain.Project; import wowmarket.wow_server.repository.ItemRepository; +import wowmarket.wow_server.repository.OrderQuestionRepository; import wowmarket.wow_server.repository.ProjectRepository; import java.util.List; @@ -16,11 +19,13 @@ public class ItemService { private final ItemRepository itemRepository; private final ProjectRepository projectRepository; + private final OrderQuestionRepository orderQuestionRepository; - public ItemService(ProjectRepository projectRepository, ItemRepository itemRepository) { + public ItemService(ProjectRepository projectRepository, ItemRepository itemRepository, OrderQuestionRepository orderQuestionRepository) { this.itemRepository = itemRepository; this.projectRepository = projectRepository; + this.orderQuestionRepository = orderQuestionRepository; } // public List getItemInfo(Long project_id){ @@ -37,7 +42,12 @@ public OrderResponseDto getItemInfo(Long project_id){ itemList.stream() // DB 에서 조회한 List -> stream 으로 변환 .map(ItemResponseDto::new) // stream 처리를 통해, Board 객체 -> BoardResponseDto 로 변환 .toList(); - return new OrderResponseDto(project, itemResponseDtoList); + List orderQuestions = orderQuestionRepository.findByProject_Id(project_id); + List orderQuestionResponseDtoList = + orderQuestions.stream() + .map(OrderQuestionResponseDto::new) + .toList(); + return new OrderResponseDto(project, itemResponseDtoList, orderQuestionResponseDtoList); } diff --git a/src/main/java/wowmarket/wow_server/detail/project/service/OrderService.java b/src/main/java/wowmarket/wow_server/detail/project/service/OrderService.java index 96938d9..4ab3866 100644 --- a/src/main/java/wowmarket/wow_server/detail/project/service/OrderService.java +++ b/src/main/java/wowmarket/wow_server/detail/project/service/OrderService.java @@ -22,14 +22,18 @@ public class OrderService { private final OrderRepository orderRepository; private final ProjectRepository projectRepository; private final OrderDetailRepository orderDetailRepository; + private final OrderQuestionRepository orderQuestionRepository; + private final OrderAnswerRepository orderAnswerRepository; - public OrderService(ProjectRepository projectRepository, OrderRepository orderRepository, OrderDetailRepository orderDetailRepository, ItemRepository itemRepository, UserRepository userRepository) { + public OrderService(ProjectRepository projectRepository, OrderRepository orderRepository, OrderDetailRepository orderDetailRepository, ItemRepository itemRepository, UserRepository userRepository, OrderQuestionRepository orderQuestionRepository, OrderAnswerRepository orderAnswerRepository) { this.projectRepository = projectRepository; this.orderRepository = orderRepository; this.orderDetailRepository = orderDetailRepository; this.itemRepository = itemRepository; this.userRepository = userRepository; + this.orderQuestionRepository = orderQuestionRepository; + this.orderAnswerRepository = orderAnswerRepository; } @@ -62,6 +66,7 @@ public ResponseEntity createOrderForm(Long project_id, OrderFormRequestDto reque .build(); orderRepository.save(order); + //상품 수량 입력받는 부분 for (int i = 0; i < requestDto.getOrderRequestDtoList().size(); i++) { Item item = itemRepository.findItemById(requestDto.getOrderRequestDtoList().get(i).getItemId()); int count = requestDto.getOrderRequestDtoList().get(i).getCount(); @@ -73,6 +78,18 @@ public ResponseEntity createOrderForm(Long project_id, OrderFormRequestDto reque orderDetailRepository.save(orderDetail); } + //추가질문 답변 입력받는 부분 + for (int i = 0; i < requestDto.getOrderAnswerDtoList().size(); i++) { + OrderQuestion orderQuestion = orderQuestionRepository.findByQuestion_Id(requestDto.getOrderAnswerDtoList().get(i).getQuestionId()); + String answer = requestDto.getOrderAnswerDtoList().get(i).getAnswer(); + OrderAnswer orderAnswer = OrderAnswer.builder() + .orders(order) + .orderQuestion(orderQuestion) + .answer(answer) + .build(); + orderAnswerRepository.save(orderAnswer); + } + //참여인원 업데이트 projectRepository.updateParticipantNumber(project_id); diff --git a/src/main/java/wowmarket/wow_server/repository/OrderQuestionRepository.java b/src/main/java/wowmarket/wow_server/repository/OrderQuestionRepository.java index 1cf596f..16bfdf8 100644 --- a/src/main/java/wowmarket/wow_server/repository/OrderQuestionRepository.java +++ b/src/main/java/wowmarket/wow_server/repository/OrderQuestionRepository.java @@ -1,7 +1,16 @@ package wowmarket.wow_server.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import wowmarket.wow_server.domain.Item; import wowmarket.wow_server.domain.OrderQuestion; +import wowmarket.wow_server.domain.Question; + +import java.util.List; public interface OrderQuestionRepository extends JpaRepository { + List findByProject_Id(Long project_id); + + @Query(nativeQuery = true, value = "select * from order_question where order_question_id =?") + OrderQuestion findByQuestion_Id(Long questionId); }