Skip to content

Commit

Permalink
Merge pull request #162 from UMC-WOWMARKET/feat/demandnew
Browse files Browse the repository at this point in the history
[feat] 참여폼 추가질문 불러오기 API
  • Loading branch information
minji1289 authored Jan 11, 2024
2 parents 48ea30f + 8338b1f commit d291c09
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DemandItemResponseDto> getItemInfo(@PathVariable Long demand_project_id){
public DemandResponseDto getItemInfo(@PathVariable Long demand_project_id){
return demandItemService.getDemandItemInfo(demand_project_id);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<DemandItemResponseDto> demandItemResponseDtoList;
private List<DemandQuestionResponseDto> demandQuestionResponseDtoList;

public DemandResponseDto(List<DemandItemResponseDto> demandItemResponseDtoList, List<DemandQuestionResponseDto> demandQuestionResponseDtoList) {
this.demandItemResponseDtoList = demandItemResponseDtoList;
this.demandQuestionResponseDtoList = demandQuestionResponseDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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<DemandItemResponseDto> getDemandItemInfo(Long demand_project_id){
public DemandResponseDto getDemandItemInfo(Long demand_project_id){
List<DemandItem> itemList = itemRepository.findDemandItemByDemandProject_Id(demand_project_id);
return itemList.stream() // DB 에서 조회한 List -> stream 으로 변환
.map(DemandItemResponseDto::new) // stream 처리를 통해, DemandItem 객체 -> DemandItemResponseDto 로 변환
.toList();
}
List<DemandItemResponseDto> itemResponseDtoList =
itemList.stream()
.map(DemandItemResponseDto::new)
.toList();

List<DemandQuestion> demandQuestions = demandQuestionRepository.findByDemandProject_Id(demand_project_id);
List<DemandQuestionResponseDto> demandQuestionResponseDtoList =
demandQuestions.stream()
.map(DemandQuestionResponseDto::new)
.toList();
return new DemandResponseDto(itemResponseDtoList, demandQuestionResponseDtoList);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<DemandProject, Long> {

@Query("SELECT dp FROM DemandProject dp " +
"WHERE dp.isEnd = false " +
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +
Expand Down

0 comments on commit d291c09

Please sign in to comment.