Skip to content

Commit

Permalink
[feat] 참여폼 추가질문 답변 입력받기 API
Browse files Browse the repository at this point in the history
  • Loading branch information
minji1289 committed Jan 11, 2024
1 parent 951e067 commit 98dd42a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wowmarket.wow_server.detail.demandproject.dto;

import lombok.Getter;

@Getter
public class DemandAnswerDto {
private Long questionId; //추가질문 id
private String answer; //답변 내용
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import lombok.Getter;
import wowmarket.wow_server.detail.project.dto.OrderAnswerDto;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -10,4 +11,7 @@
public class DemandFormRequestDto {
//상품명 & 판매가 리스트
List<DemandDetailRequestDto> demandDetailRequestDtoList;

//추가질문 답변 리스트
List<DemandAnswerDto> demandAnswerDtoList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ public class DemandDetailService {

private final DemandItemRepository demandItemRepository;
private final DemandOrderRepository demandOrderRepository;
private final DemandQuestionRepository demandQuestionRepository;
private final DemandAnswerRepository demandAnswerRepository;


public DemandDetailService(DemandDetailRepository demandDetailRepository, DemandItemRepository itemRepository, UserRepository userRepository, DemandProjectRepository demandProjectRepository, DemandItemRepository demandItemRepository, DemandOrderRepository demandOrderRepository) {
public DemandDetailService(DemandDetailRepository demandDetailRepository, DemandItemRepository itemRepository, UserRepository userRepository, DemandProjectRepository demandProjectRepository, DemandItemRepository demandItemRepository, DemandOrderRepository demandOrderRepository, DemandQuestionRepository demandQuestionRepository, DemandAnswerRepository demandAnswerRepository) {
this.itemRepository = itemRepository;
this.demandDetailRepository = demandDetailRepository;
this.userRepository = userRepository;
this.demandProjectRepository = demandProjectRepository;
this.demandItemRepository= demandItemRepository;
this.demandOrderRepository=demandOrderRepository;
this.demandQuestionRepository=demandQuestionRepository;
this.demandAnswerRepository=demandAnswerRepository;
}


Expand Down Expand Up @@ -71,6 +75,18 @@ public ResponseEntity createDemandForm(Long demand_project_id, DemandFormRequest
demandDetailRepository.save(demandDetail);
}

//추가질문 답변 입력받는 부분
for (int i = 0; i < requestDto.getDemandAnswerDtoList().size(); i++) {
DemandQuestion demandQuestion = demandQuestionRepository.findByQuestion_Id(requestDto.getDemandAnswerDtoList().get(i).getQuestionId());
String answer = requestDto.getDemandAnswerDtoList().get(i).getAnswer();
DemandAnswer demandAnswer = DemandAnswer.builder()
.demandOrder(demandOrder)
.demandQuestion(demandQuestion)
.answer(answer)
.build();
demandAnswerRepository.save(demandAnswer);
}

//참여인원 업데이트
demandProjectRepository.updateParticipantNumber(demand_project_id);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wowmarket.wow_server.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import wowmarket.wow_server.domain.DemandAnswer;

public interface DemandAnswerRepository extends JpaRepository<DemandAnswer, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package wowmarket.wow_server.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import wowmarket.wow_server.domain.DemandQuestion;
import java.util.List;

public interface DemandQuestionRepository extends JpaRepository<DemandQuestion, Long> {
List<DemandQuestion> findByDemandProject_Id(Long demand_project_id);

@Query(nativeQuery = true, value = "select * from demand_question where demand_question_id =?")
DemandQuestion findByQuestion_Id(Long questionId);
}

0 comments on commit 98dd42a

Please sign in to comment.