diff --git a/src/main/java/wowmarket/wow_server/detail/demandproject/controller/DemandProjectController.java b/src/main/java/wowmarket/wow_server/detail/demandproject/controller/DemandProjectController.java index 1413446..175fbff 100644 --- a/src/main/java/wowmarket/wow_server/detail/demandproject/controller/DemandProjectController.java +++ b/src/main/java/wowmarket/wow_server/detail/demandproject/controller/DemandProjectController.java @@ -34,9 +34,9 @@ public DemandProjectImgResponseDto getProjectImg(@PathVariable Long demand_proje return demandProjectService.getDemandProjectImg(demand_project_id); } - //참여폼: 우측 폼 정보 불러오기(상품명, 판매가) + //참여폼: 우측 폼 정보 불러오기(상품명, 판매가, 추가질문) @GetMapping("/{demand_project_id}/item") //path 수정해야함 - public List getItemInfo(@PathVariable Long demand_project_id){ + public DemandResponseDto getItemInfo(@PathVariable Long demand_project_id){ return demandItemService.getDemandItemInfo(demand_project_id); } diff --git a/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandQuestionResponseDto.java b/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandQuestionResponseDto.java new file mode 100644 index 0000000..fd17230 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandQuestionResponseDto.java @@ -0,0 +1,19 @@ +package wowmarket.wow_server.detail.demandproject.dto; + +import lombok.Getter; +import wowmarket.wow_server.domain.DemandQuestion; + +//참여폼 추가질문 정보 불러오는 Dto + +@Getter +public class DemandQuestionResponseDto { + private Long id; + private String question; //질문 내용 + private boolean essential; //필수 여부 + + public DemandQuestionResponseDto(DemandQuestion demandQuestion) { + this.id = demandQuestion.getId(); + this.question = demandQuestion.getQuestion(); + this.essential = demandQuestion.isEssential(); + } +} \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandResponseDto.java b/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandResponseDto.java new file mode 100644 index 0000000..a7955b3 --- /dev/null +++ b/src/main/java/wowmarket/wow_server/detail/demandproject/dto/DemandResponseDto.java @@ -0,0 +1,18 @@ +package wowmarket.wow_server.detail.demandproject.dto; + +import lombok.Getter; + +import java.util.List; + +//참여폼 정보 불러오는 Dto + +@Getter +public class DemandResponseDto { + private List demandItemResponseDtoList; + private List demandQuestionResponseDtoList; + + public DemandResponseDto(List demandItemResponseDtoList, List demandQuestionResponseDtoList) { + this.demandItemResponseDtoList = demandItemResponseDtoList; + this.demandQuestionResponseDtoList = demandQuestionResponseDtoList; + } +} \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/detail/demandproject/service/DemandItemService.java b/src/main/java/wowmarket/wow_server/detail/demandproject/service/DemandItemService.java index 0730bd0..fd11d73 100644 --- a/src/main/java/wowmarket/wow_server/detail/demandproject/service/DemandItemService.java +++ b/src/main/java/wowmarket/wow_server/detail/demandproject/service/DemandItemService.java @@ -6,6 +6,11 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.server.ResponseStatusException; import wowmarket.wow_server.detail.demandproject.dto.DemandItemResponseDto; +import wowmarket.wow_server.detail.demandproject.dto.DemandQuestionResponseDto; +import wowmarket.wow_server.detail.demandproject.dto.DemandResponseDto; +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.*; import wowmarket.wow_server.global.jwt.SecurityUtil; import wowmarket.wow_server.repository.*; @@ -16,17 +21,29 @@ @Service public class DemandItemService { private final DemandItemRepository itemRepository; + private final DemandProjectRepository demandProjectRepository; + private final DemandQuestionRepository demandQuestionRepository; - public DemandItemService(DemandItemRepository itemRepository) { + public DemandItemService(DemandItemRepository itemRepository, DemandProjectRepository demandProjectRepository, DemandQuestionRepository demandQuestionRepository) { this.itemRepository = itemRepository; + this.demandProjectRepository = demandProjectRepository; + this.demandQuestionRepository = demandQuestionRepository; } - public List getDemandItemInfo(Long demand_project_id){ + public DemandResponseDto getDemandItemInfo(Long demand_project_id){ List itemList = itemRepository.findDemandItemByDemandProject_Id(demand_project_id); - return itemList.stream() // DB 에서 조회한 List -> stream 으로 변환 - .map(DemandItemResponseDto::new) // stream 처리를 통해, DemandItem 객체 -> DemandItemResponseDto 로 변환 - .toList(); - } + List itemResponseDtoList = + itemList.stream() + .map(DemandItemResponseDto::new) + .toList(); + + List demandQuestions = demandQuestionRepository.findByDemandProject_Id(demand_project_id); + List demandQuestionResponseDtoList = + demandQuestions.stream() + .map(DemandQuestionResponseDto::new) + .toList(); + return new DemandResponseDto(itemResponseDtoList, demandQuestionResponseDtoList); + } } \ No newline at end of file diff --git a/src/main/java/wowmarket/wow_server/repository/DemandProjectRepository.java b/src/main/java/wowmarket/wow_server/repository/DemandProjectRepository.java index 51b5fd5..6bbdc00 100644 --- a/src/main/java/wowmarket/wow_server/repository/DemandProjectRepository.java +++ b/src/main/java/wowmarket/wow_server/repository/DemandProjectRepository.java @@ -8,10 +8,12 @@ import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; import wowmarket.wow_server.domain.DemandProject; +import wowmarket.wow_server.domain.Project; import java.time.LocalDateTime; public interface DemandProjectRepository extends JpaRepository { + @Query("SELECT dp FROM DemandProject dp " + "WHERE dp.isEnd = false " + "AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +