Skip to content

Commit

Permalink
Merge branch 'develop' into feature/introduce
Browse files Browse the repository at this point in the history
  • Loading branch information
tape4 authored Dec 4, 2024
2 parents 9c38331 + 2016285 commit 102f489
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,15 +15,17 @@ public class RecruitByKeyword {
private final Long recruitId;
private final String recruitTitle;
private final List<String> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Getter
@Builder
Expand All @@ -22,7 +23,7 @@ public class RecruitReviewListByKeywordResponse {
@Schema(description = "검색 키워드가 review에 포함된 공고 목록")
private final List<ReviewByKeyword> reviewResult;

public static RecruitReviewListByKeywordResponse from(String keyword, List<Recruit> recruits, List<RecruitReviewDto> reviews) {
public static RecruitReviewListByKeywordResponse from(String keyword, Map<Recruit, String> recruitMap, List<RecruitReviewDto> reviews) {
List<ReviewByKeyword> reviewResult = new ArrayList<>();

for (RecruitReviewDto recruitReviewDto : reviews) {
Expand All @@ -35,10 +36,10 @@ public static RecruitReviewListByKeywordResponse from(String keyword, List<Recru
else existingReview.addReview(recruitReviewDto);
}


return RecruitReviewListByKeywordResponse.builder()
.keyword(keyword)
.recruitResult(recruits.stream().map(RecruitByKeyword::from).toList())
.recruitResult(recruitMap.entrySet().stream().map(entry ->
RecruitByKeyword.from(entry.getKey(), entry.getValue())).toList())
.reviewResult(reviewResult)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class ValidRecruitInfo {
private Long id;
private String title;
private List<String> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

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
public class ValidRecruitDto {
private Long id;
private RecruitStatus status;
private String title;
private String reviewTag;
private List<String> tags;

public static ValidRecruitDto from(Recruit recruit) {
public static ValidRecruitDto from(List<Review> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,10 +29,19 @@ public RecruitReviewListByKeywordResponse findRecruitByKeyword(Member requestMem
List<Recruit> recruits = recruitRepository.searchRecruitByKeyword(requestMember.getId(), keyword);
List<RecruitReviewDto> reviews = reviewRepository.findReviewByKeyword(requestMember.getId(), keyword);

Map<Recruit, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,6 +26,8 @@
public class RecruitServiceImpl implements RecruitService {

private final RecruitRepository recruitRepository;
private final ReviewRepository reviewRepository;


@Override
public Recruit getById(long id) {
Expand Down Expand Up @@ -84,14 +89,15 @@ public List<Recruit> findAllByEndTime(Member requestMember, LocalDate date) {
public List<Recruit> findAllByEndTimeAfter(Member requestMember, LocalDateTime endTime) {
return recruitRepository.findAllActiveRecruitByMemberIdAndEndTimeAfter(requestMember.getId(), endTime);
}

@Override
public List<ValidRecruitDto> findAllValidRecruitByMember(Member requestMember, LocalDateTime endTime) {
List<Recruit> recruits = recruitRepository.findAllActiveRecruitByMemberId(requestMember.getId());
return recruits.stream()
.filter(item -> !isUnappliedOrPlanned(item) || item.getEndTime().isAfter(endTime))
.map(ValidRecruitDto::from)
.toList();
.map(recruit -> {
List<Review> reviews = reviewRepository.findAllByRecruitId(recruit.getId());
return ValidRecruitDto.from(reviews!=null?reviews: Collections.emptyList(),recruit);
}).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 102f489

Please sign in to comment.