diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitByKeyword.java b/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitByKeyword.java index fca93281..ac223470 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitByKeyword.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitByKeyword.java @@ -4,6 +4,7 @@ import lombok.Getter; import umc.kkijuk.server.recruit.domain.Recruit; import umc.kkijuk.server.recruit.domain.RecruitStatus; +import umc.kkijuk.server.review.domain.Review; import java.time.LocalDateTime; import java.util.List; @@ -14,15 +15,17 @@ public class RecruitByKeyword { private final Long recruitId; private final String recruitTitle; private final List tags; + private final String reviewTag; private final LocalDateTime startTime; private final LocalDateTime endTime; private final RecruitStatus status; - public static RecruitByKeyword from(Recruit recruit) { + public static RecruitByKeyword from(Recruit recruit,String reviewTitle) { return RecruitByKeyword.builder() .recruitId(recruit.getId()) .recruitTitle(recruit.getTitle()) .tags(recruit.getTags()) + .reviewTag(reviewTitle) .startTime(recruit.getStartTime()) .endTime(recruit.getEndTime()) .status(recruit.getStatus()) diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitReviewListByKeywordResponse.java b/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitReviewListByKeywordResponse.java index 184efd82..d16fc7b4 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitReviewListByKeywordResponse.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/response/RecruitReviewListByKeywordResponse.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; @Getter @Builder @@ -22,7 +23,7 @@ public class RecruitReviewListByKeywordResponse { @Schema(description = "검색 키워드가 review에 포함된 공고 목록") private final List reviewResult; - public static RecruitReviewListByKeywordResponse from(String keyword, List recruits, List reviews) { + public static RecruitReviewListByKeywordResponse from(String keyword, Map recruitMap, List reviews) { List reviewResult = new ArrayList<>(); for (RecruitReviewDto recruitReviewDto : reviews) { @@ -35,10 +36,10 @@ public static RecruitReviewListByKeywordResponse from(String keyword, List + RecruitByKeyword.from(entry.getKey(), entry.getValue())).toList()) .reviewResult(reviewResult) .build(); } diff --git a/src/main/java/umc/kkijuk/server/recruit/controller/response/ValidRecruitInfo.java b/src/main/java/umc/kkijuk/server/recruit/controller/response/ValidRecruitInfo.java index 9b583544..88166da0 100644 --- a/src/main/java/umc/kkijuk/server/recruit/controller/response/ValidRecruitInfo.java +++ b/src/main/java/umc/kkijuk/server/recruit/controller/response/ValidRecruitInfo.java @@ -12,11 +12,13 @@ public class ValidRecruitInfo { private Long id; private String title; private List tags; + private String reviewTag; public static ValidRecruitInfo from(ValidRecruitDto dto) { return ValidRecruitInfo.builder() .id(dto.getId()) .title(dto.getTitle()) + .reviewTag(dto.getReviewTag()) .tags(dto.getTags()) .build(); } diff --git a/src/main/java/umc/kkijuk/server/recruit/domain/ValidRecruitDto.java b/src/main/java/umc/kkijuk/server/recruit/domain/ValidRecruitDto.java index 9b3b34dc..a10ba5e3 100644 --- a/src/main/java/umc/kkijuk/server/recruit/domain/ValidRecruitDto.java +++ b/src/main/java/umc/kkijuk/server/recruit/domain/ValidRecruitDto.java @@ -2,8 +2,11 @@ import lombok.Builder; import lombok.Getter; +import umc.kkijuk.server.review.domain.Review; +import java.util.Comparator; import java.util.List; +import java.util.Objects; @Getter @Builder @@ -11,13 +14,16 @@ public class ValidRecruitDto { private Long id; private RecruitStatus status; private String title; + private String reviewTag; private List tags; - public static ValidRecruitDto from(Recruit recruit) { + public static ValidRecruitDto from(List reviews, Recruit recruit) { return ValidRecruitDto.builder() .id(recruit.getId()) .status(recruit.getStatus()) .title(recruit.getTitle()) + .reviewTag(reviews.stream().max(Comparator.comparing(Review::getDate)) + .map(Review::getTitle).orElse("")) .tags(recruit.getTags()) .build(); } diff --git a/src/main/java/umc/kkijuk/server/recruit/service/RecruitSearchServiceImpl.java b/src/main/java/umc/kkijuk/server/recruit/service/RecruitSearchServiceImpl.java index dd1bf3ab..bd51c8d8 100644 --- a/src/main/java/umc/kkijuk/server/recruit/service/RecruitSearchServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/recruit/service/RecruitSearchServiceImpl.java @@ -9,9 +9,14 @@ import umc.kkijuk.server.recruit.domain.Recruit; import umc.kkijuk.server.review.domain.RecruitReviewDto; import umc.kkijuk.server.recruit.service.port.RecruitRepository; +import umc.kkijuk.server.review.domain.Review; import umc.kkijuk.server.review.service.port.ReviewRepository; +import java.lang.management.ManagementPermission; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Slf4j @Service @@ -24,10 +29,19 @@ public RecruitReviewListByKeywordResponse findRecruitByKeyword(Member requestMem List recruits = recruitRepository.searchRecruitByKeyword(requestMember.getId(), keyword); List reviews = reviewRepository.findReviewByKeyword(requestMember.getId(), keyword); + Map reviewMap = new HashMap<>(); + for (Recruit recruit : recruits) { + String reviewTitle = reviewRepository.findAllByRecruitId(recruit.getId()) + .stream().max(Comparator.comparing(Review::getDate)) + .map(Review::getTitle).orElse(""); + reviewMap.put(recruit, reviewTitle); + } + for (RecruitReviewDto review : reviews) { log.info("keyword: {}, result: {}", keyword, review.getReviewContent()); } - return RecruitReviewListByKeywordResponse.from(keyword, recruits, reviews); + + return RecruitReviewListByKeywordResponse.from(keyword, reviewMap, reviews); } } diff --git a/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java b/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java index 19e46f4c..58c12f73 100644 --- a/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/recruit/service/RecruitServiceImpl.java @@ -11,9 +11,12 @@ import umc.kkijuk.server.recruit.domain.RecruitApplyDateUpdate; import umc.kkijuk.server.recruit.domain.*; import umc.kkijuk.server.recruit.service.port.RecruitRepository; +import umc.kkijuk.server.review.domain.Review; +import umc.kkijuk.server.review.service.port.ReviewRepository; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -23,6 +26,8 @@ public class RecruitServiceImpl implements RecruitService { private final RecruitRepository recruitRepository; + private final ReviewRepository reviewRepository; + @Override public Recruit getById(long id) { @@ -84,14 +89,15 @@ public List findAllByEndTime(Member requestMember, LocalDate date) { public List findAllByEndTimeAfter(Member requestMember, LocalDateTime endTime) { return recruitRepository.findAllActiveRecruitByMemberIdAndEndTimeAfter(requestMember.getId(), endTime); } - @Override public List findAllValidRecruitByMember(Member requestMember, LocalDateTime endTime) { List recruits = recruitRepository.findAllActiveRecruitByMemberId(requestMember.getId()); return recruits.stream() .filter(item -> !isUnappliedOrPlanned(item) || item.getEndTime().isAfter(endTime)) - .map(ValidRecruitDto::from) - .toList(); + .map(recruit -> { + List reviews = reviewRepository.findAllByRecruitId(recruit.getId()); + return ValidRecruitDto.from(reviews!=null?reviews: Collections.emptyList(),recruit); + }).toList(); } @Override diff --git a/src/test/java/umc/kkijuk/server/unitTest/recruit/service/RecruitServiceTest.java b/src/test/java/umc/kkijuk/server/unitTest/recruit/service/RecruitServiceTest.java index bbf37d67..b4a351e8 100644 --- a/src/test/java/umc/kkijuk/server/unitTest/recruit/service/RecruitServiceTest.java +++ b/src/test/java/umc/kkijuk/server/unitTest/recruit/service/RecruitServiceTest.java @@ -9,9 +9,11 @@ import umc.kkijuk.server.member.domain.State; import umc.kkijuk.server.recruit.controller.port.RecruitService; import umc.kkijuk.server.recruit.domain.*; +import umc.kkijuk.server.review.service.port.ReviewRepository; import umc.kkijuk.server.unitTest.mock.FakeRecruitRepository; import umc.kkijuk.server.recruit.service.RecruitServiceImpl; import umc.kkijuk.server.recruit.service.port.RecruitRepository; +import umc.kkijuk.server.unitTest.mock.FakeReviewRepository; import java.time.LocalDate; import java.time.LocalDateTime; @@ -51,8 +53,11 @@ void init() { RecruitRepository recruitRepository = new FakeRecruitRepository(); + ReviewRepository reviewRepository = new FakeReviewRepository(); + this.recruitService = RecruitServiceImpl.builder() .recruitRepository(recruitRepository) + .reviewRepository(reviewRepository) .build(); Recruit recruit = Recruit.builder()