Skip to content

Commit

Permalink
Merge pull request #157 from UMC-WOWMARKET/feat/newproject
Browse files Browse the repository at this point in the history
[feat] 주문폼 - 추가질문 Read & 추가질문 답변 Create
  • Loading branch information
minji1289 authored Jan 11, 2024
2 parents c556043 + c387d88 commit 32f8570
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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; //답변 내용
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public class OrderFormRequestDto {

//상품명 & 판매가 리스트
List<OrderRequestDto> orderRequestDtoList;

//추가질문 답변 리스트
List<OrderAnswerDto> orderAnswerDtoList;
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ public class OrderResponseDto {
private String account_holder_name; //예금주

private List<ItemResponseDto> itemResponseDtoList;
private List<OrderQuestionResponseDto> orderQuestionResponseDtoList;

public OrderResponseDto(Project project, List<ItemResponseDto> itemResponseDtoList) {
public OrderResponseDto(Project project, List<ItemResponseDto> itemResponseDtoList, List<OrderQuestionResponseDto> orderQuestionResponseDtoList) {
this.receive_type=project.getReceive_type().toString();
this.receive_address=project.getReceive_address();
this.delivery_fee=project.getDelivery_fee();
this.bank=project.getBank();
this.account=project.getAccount();
this.account_holder_name = project.getAccount_holder_name();
this.itemResponseDtoList = itemResponseDtoList;
this.orderQuestionResponseDtoList = orderQuestionResponseDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ItemResponseDto> getItemInfo(Long project_id){
Expand All @@ -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<OrderQuestion> orderQuestions = orderQuestionRepository.findByProject_Id(project_id);
List<OrderQuestionResponseDto> orderQuestionResponseDtoList =
orderQuestions.stream()
.map(OrderQuestionResponseDto::new)
.toList();
return new OrderResponseDto(project, itemResponseDtoList, orderQuestionResponseDtoList);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrderQuestion, Long> {
List<OrderQuestion> findByProject_Id(Long project_id);

@Query(nativeQuery = true, value = "select * from order_question where order_question_id =?")
OrderQuestion findByQuestion_Id(Long questionId);
}

0 comments on commit 32f8570

Please sign in to comment.