Skip to content

Commit

Permalink
Feat : 자소서 검색기능(초안) 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Dec 2, 2024
1 parent b32970e commit c3dd176
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import umc.kkijuk.server.dashboard.controller.response.IntroduceRemindResponse;
import umc.kkijuk.server.dashboard.controller.response.RecruitRemindResponse;
import umc.kkijuk.server.introduce.domain.Introduce;
import umc.kkijuk.server.introduce.domain.IntroduceRepository;
import umc.kkijuk.server.introduce.repository.IntroduceRepository;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.Recruit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import umc.kkijuk.server.introduce.common.BaseResponse;
import umc.kkijuk.server.introduce.controller.response.IntroduceListResponse;
import umc.kkijuk.server.introduce.controller.response.IntroduceResponse;
import umc.kkijuk.server.introduce.controller.response.MasterIntroduceResponse;
import umc.kkijuk.server.introduce.dto.*;
import umc.kkijuk.server.introduce.service.IntroduceService;
import umc.kkijuk.server.introduce.service.MasterIntroduceService;
import umc.kkijuk.server.login.argumentresolver.Login;
import umc.kkijuk.server.login.controller.dto.LoginInfo;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.member.service.MemberService;

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

@Tag(name = "introduce", description = "자기소개서 API")
Expand All @@ -26,6 +29,7 @@
@RequestMapping("/history/intro/")
public class IntroduceController {
private final IntroduceService introduceService;
private final MasterIntroduceService masterIntroduceService;
private final MemberService memberService;

private final Member requestMember = Member.builder()
Expand Down Expand Up @@ -90,4 +94,11 @@ public ResponseEntity<Object> delete(
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 삭제 완료", intro_Id));
}

@GetMapping("/search")
@Operation(summary = "키워드로 자기소개서 문단 검색")
public ResponseEntity<List<Object>> searchIntroduceByKeyword(@RequestParam String keyword) {
List<Object> response = introduceService.searchIntroduceAndMasterByKeyword(keyword);
return ResponseEntity.status(HttpStatus.OK).body(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package umc.kkijuk.server.introduce.controller.response;

import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Getter
@Builder
@AllArgsConstructor
public class FindIntroduceResponse {
private Long introId;
private String title;
private String content;
private LocalDateTime createdDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package umc.kkijuk.server.introduce.controller.response;

import lombok.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Getter
@Builder
@AllArgsConstructor
public class FindMasterIntroduceResponse {
private Long masterIntroId;
private String title;
private String content;
private LocalDateTime createdDate;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package umc.kkijuk.server.introduce.domain;
package umc.kkijuk.server.introduce.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import org.springframework.data.domain.Pageable;
import umc.kkijuk.server.introduce.domain.Introduce;

import java.util.List;
import java.util.Optional;

Expand All @@ -16,4 +18,10 @@ public interface IntroduceRepository extends JpaRepository<Introduce, Long> {
@Query("SELECT i FROM Introduce i WHERE i.memberId = :memberId AND i.state = :state ORDER BY i.recruit.endTime ASC")
Page<Introduce> findByMemberIdAndStateOrderByEndTimeAsc(@Param("memberId") Long memberId, @Param("state") int state, Pageable pageable);

@Query("SELECT i FROM Introduce i " +
"JOIN i.questions q " +
"WHERE q.content LIKE %:keyword%")
List<Introduce> searchIntroduceByKeyword(String keyword);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package umc.kkijuk.server.introduce.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import umc.kkijuk.server.introduce.domain.MasterIntroduce;

import java.util.List;
import java.util.Optional;

public interface MasterIntroduceRepository extends JpaRepository<MasterIntroduce, Long> {
Optional<MasterIntroduce> findByMemberId(Long memberId);
@Query("SELECT m FROM MasterIntroduce m " +
"JOIN m.masterQuestion mq " +
"WHERE mq.content LIKE %:keyword%")
List<MasterIntroduce> searchMasterIntroduceByKeyword(String keyword);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package umc.kkijuk.server.introduce.domain;
package umc.kkijuk.server.introduce.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import umc.kkijuk.server.introduce.domain.MasterQuestion;

public interface MasterQuestionRepository extends JpaRepository<MasterQuestion, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package umc.kkijuk.server.introduce.domain;
package umc.kkijuk.server.introduce.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import umc.kkijuk.server.introduce.domain.Question;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import org.springframework.stereotype.Service;
import umc.kkijuk.server.common.domian.exception.IntroFoundException;
import umc.kkijuk.server.common.domian.exception.IntroOwnerMismatchException;
import umc.kkijuk.server.common.domian.exception.RecruitOwnerMismatchException;
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException;
import umc.kkijuk.server.introduce.controller.response.FindIntroduceResponse;
import umc.kkijuk.server.introduce.controller.response.FindMasterIntroduceResponse;
import umc.kkijuk.server.introduce.controller.response.IntroduceListResponse;
import umc.kkijuk.server.introduce.controller.response.IntroduceResponse;
import umc.kkijuk.server.introduce.domain.*;
import umc.kkijuk.server.introduce.dto.*;
import umc.kkijuk.server.introduce.repository.IntroduceRepository;
import umc.kkijuk.server.introduce.repository.MasterIntroduceRepository;
import umc.kkijuk.server.introduce.repository.QuestionRepository;
import umc.kkijuk.server.member.domain.Member;
import umc.kkijuk.server.recruit.infrastructure.RecruitEntity;
import umc.kkijuk.server.recruit.infrastructure.RecruitJpaRepository;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -26,6 +29,7 @@ public class IntroduceService {
private final IntroduceRepository introduceRepository;
private final RecruitJpaRepository recruitJpaRepository;
private final QuestionRepository questionRepository;
private final MasterIntroduceRepository masterIntroduceRepository;

@Transactional
public IntroduceResponse saveIntro(Member requestMember, Long recruitId, IntroduceReqDto introduceReqDto){
Expand Down Expand Up @@ -169,4 +173,41 @@ public List<String> getIntroduceTitles() {
.map(opt -> opt.get().toModel().getTitle()) // Get the title of the Recruit
.collect(Collectors.toList()); // Collect titles into a List
}*/

public List<Object> searchIntroduceAndMasterByKeyword(String keyword) {
// 자기소개서 검색
List<FindIntroduceResponse> introduceList = introduceRepository.searchIntroduceByKeyword(keyword)
.stream()
.flatMap(introduce -> introduce.getQuestions().stream() // 각 Question을 개별 항목으로 처리
.filter(q -> q.getContent().contains(keyword)) // 키워드가 포함된 문단만 필터링
.map(q -> FindIntroduceResponse.builder()
.introId(introduce.getId())
.title(q.getTitle()) // 해당 문단의 제목
.content(q.getContent()) // 해당 문단의 내용
.createdDate(introduce.getCreatedAt()) // 생성일
.build()))
.collect(Collectors.toList());

// 마스터 자기소개서 검색
List<FindMasterIntroduceResponse> masterIntroduceList = masterIntroduceRepository.searchMasterIntroduceByKeyword(keyword)
.stream()
.flatMap(masterIntroduce -> masterIntroduce.getMasterQuestion().stream() // 각 MasterQuestion을 개별 항목으로 처리
.filter(mq -> mq.getContent().contains(keyword)) // 키워드가 포함된 문단만 필터링
.map(mq -> FindMasterIntroduceResponse.builder()
.masterIntroId(masterIntroduce.getId())
.title(mq.getTitle()) // 해당 문단의 제목
.content(mq.getContent()) // 해당 문단의 내용
.createdDate(masterIntroduce.getCreatedAt()) // 생성일
.build()))
.collect(Collectors.toList());

// 두 리스트를 합쳐서 반환
List<Object> result = new ArrayList<>();
result.addAll(introduceList);
result.addAll(masterIntroduceList);

return result;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import umc.kkijuk.server.introduce.domain.*;
import umc.kkijuk.server.introduce.dto.IntroduceReqDto;
import umc.kkijuk.server.introduce.dto.QuestionDto;
import umc.kkijuk.server.introduce.repository.MasterIntroduceRepository;
import umc.kkijuk.server.introduce.repository.MasterQuestionRepository;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -124,4 +126,5 @@ public MasterIntroduceResponse updateMasterIntro(Long memberId, IntroduceReqDto
.build();
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package umc.kkijuk.server.recruit.infrastructure;

import jakarta.persistence.*;
import lombok.Getter;
import umc.kkijuk.server.common.converter.StringListToStringConverter;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitStatus;
Expand All @@ -10,6 +11,7 @@
import java.util.List;

@Entity
@Getter
@Table(name = "recruit")
public class RecruitEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.junit.jupiter.SpringExtension;
Expand All @@ -19,6 +18,7 @@
import umc.kkijuk.server.introduce.domain.*;
import umc.kkijuk.server.introduce.dto.IntroduceReqDto;
import umc.kkijuk.server.introduce.dto.QuestionDto;
import umc.kkijuk.server.introduce.repository.IntroduceRepository;
import umc.kkijuk.server.introduce.service.IntroduceService;
import umc.kkijuk.server.login.controller.SessionConst;
import umc.kkijuk.server.login.controller.dto.LoginInfo;
Expand All @@ -34,7 +34,6 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down

0 comments on commit c3dd176

Please sign in to comment.