Skip to content

Commit d291c09

Browse files
authored
Merge pull request #162 from UMC-WOWMARKET/feat/demandnew
[feat] 참여폼 추가질문 불러오기 API
2 parents 48ea30f + 8338b1f commit d291c09

File tree

5 files changed

+64
-8
lines changed

5 files changed

+64
-8
lines changed

src/main/java/wowmarket/wow_server/detail/demandproject/controller/DemandProjectController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public DemandProjectImgResponseDto getProjectImg(@PathVariable Long demand_proje
3434
return demandProjectService.getDemandProjectImg(demand_project_id);
3535
}
3636

37-
//참여폼: 우측 폼 정보 불러오기(상품명, 판매가)
37+
//참여폼: 우측 폼 정보 불러오기(상품명, 판매가, 추가질문)
3838
@GetMapping("/{demand_project_id}/item") //path 수정해야함
39-
public List<DemandItemResponseDto> getItemInfo(@PathVariable Long demand_project_id){
39+
public DemandResponseDto getItemInfo(@PathVariable Long demand_project_id){
4040
return demandItemService.getDemandItemInfo(demand_project_id);
4141
}
4242

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package wowmarket.wow_server.detail.demandproject.dto;
2+
3+
import lombok.Getter;
4+
import wowmarket.wow_server.domain.DemandQuestion;
5+
6+
//참여폼 추가질문 정보 불러오는 Dto
7+
8+
@Getter
9+
public class DemandQuestionResponseDto {
10+
private Long id;
11+
private String question; //질문 내용
12+
private boolean essential; //필수 여부
13+
14+
public DemandQuestionResponseDto(DemandQuestion demandQuestion) {
15+
this.id = demandQuestion.getId();
16+
this.question = demandQuestion.getQuestion();
17+
this.essential = demandQuestion.isEssential();
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package wowmarket.wow_server.detail.demandproject.dto;
2+
3+
import lombok.Getter;
4+
5+
import java.util.List;
6+
7+
//참여폼 정보 불러오는 Dto
8+
9+
@Getter
10+
public class DemandResponseDto {
11+
private List<DemandItemResponseDto> demandItemResponseDtoList;
12+
private List<DemandQuestionResponseDto> demandQuestionResponseDtoList;
13+
14+
public DemandResponseDto(List<DemandItemResponseDto> demandItemResponseDtoList, List<DemandQuestionResponseDto> demandQuestionResponseDtoList) {
15+
this.demandItemResponseDtoList = demandItemResponseDtoList;
16+
this.demandQuestionResponseDtoList = demandQuestionResponseDtoList;
17+
}
18+
}

src/main/java/wowmarket/wow_server/detail/demandproject/service/DemandItemService.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import org.springframework.web.bind.annotation.PathVariable;
77
import org.springframework.web.server.ResponseStatusException;
88
import wowmarket.wow_server.detail.demandproject.dto.DemandItemResponseDto;
9+
import wowmarket.wow_server.detail.demandproject.dto.DemandQuestionResponseDto;
10+
import wowmarket.wow_server.detail.demandproject.dto.DemandResponseDto;
11+
import wowmarket.wow_server.detail.project.dto.ItemResponseDto;
12+
import wowmarket.wow_server.detail.project.dto.OrderQuestionResponseDto;
13+
import wowmarket.wow_server.detail.project.dto.OrderResponseDto;
914
import wowmarket.wow_server.domain.*;
1015
import wowmarket.wow_server.global.jwt.SecurityUtil;
1116
import wowmarket.wow_server.repository.*;
@@ -16,17 +21,29 @@
1621
@Service
1722
public class DemandItemService {
1823
private final DemandItemRepository itemRepository;
24+
private final DemandProjectRepository demandProjectRepository;
25+
private final DemandQuestionRepository demandQuestionRepository;
1926

20-
public DemandItemService(DemandItemRepository itemRepository) {
27+
public DemandItemService(DemandItemRepository itemRepository, DemandProjectRepository demandProjectRepository, DemandQuestionRepository demandQuestionRepository) {
2128
this.itemRepository = itemRepository;
29+
this.demandProjectRepository = demandProjectRepository;
30+
this.demandQuestionRepository = demandQuestionRepository;
2231
}
2332

24-
public List<DemandItemResponseDto> getDemandItemInfo(Long demand_project_id){
33+
public DemandResponseDto getDemandItemInfo(Long demand_project_id){
2534
List<DemandItem> itemList = itemRepository.findDemandItemByDemandProject_Id(demand_project_id);
26-
return itemList.stream() // DB 에서 조회한 List -> stream 으로 변환
27-
.map(DemandItemResponseDto::new) // stream 처리를 통해, DemandItem 객체 -> DemandItemResponseDto 로 변환
28-
.toList();
29-
}
35+
List<DemandItemResponseDto> itemResponseDtoList =
36+
itemList.stream()
37+
.map(DemandItemResponseDto::new)
38+
.toList();
39+
40+
List<DemandQuestion> demandQuestions = demandQuestionRepository.findByDemandProject_Id(demand_project_id);
41+
List<DemandQuestionResponseDto> demandQuestionResponseDtoList =
42+
demandQuestions.stream()
43+
.map(DemandQuestionResponseDto::new)
44+
.toList();
45+
return new DemandResponseDto(itemResponseDtoList, demandQuestionResponseDtoList);
3046

47+
}
3148

3249
}

src/main/java/wowmarket/wow_server/repository/DemandProjectRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import org.springframework.data.repository.query.Param;
99
import org.springframework.transaction.annotation.Transactional;
1010
import wowmarket.wow_server.domain.DemandProject;
11+
import wowmarket.wow_server.domain.Project;
1112

1213
import java.time.LocalDateTime;
1314

1415
public interface DemandProjectRepository extends JpaRepository<DemandProject, Long> {
16+
1517
@Query("SELECT dp FROM DemandProject dp " +
1618
"WHERE dp.isEnd = false " +
1719
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +

0 commit comments

Comments
 (0)