Skip to content

Commit

Permalink
Feat : 활동 검색 기능 추가
Browse files Browse the repository at this point in the history
- 활동명에 특정 keyword가 포함된 활동 조회 API 추가
  • Loading branch information
hyeonda02 committed Nov 9, 2024
1 parent 8ab0cee commit 47c34e7
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,21 @@ public CareerResponse<List<FindDetailResponse>> findTagAndDetail(
baseCareerService.findAllDetailByTag(requestMember, tagId, sort)
);
}
@GetMapping("/find")
@Operation(
summary = "활동 검색 - 활동",
description = "활동을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 주세요. " )
public CareerResponse<List<FindCareerResponse>> findCareerWithKeyword(
@Login LoginInfo loginInfo,
@RequestParam(name = "keyword") String keyword,
@RequestParam(name = "sort") String sort
){
Member requestMember = memberService.getById(loginInfo.getMemberId());
return CareerResponse.success(
CareerResponseMessage.CAREER_FINDALL_SUCCESS,
baseCareerService.findCareerWithKeyword(requestMember, keyword, sort)
);

}

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

import lombok.*;
import umc.kkijuk.server.career.domain.BaseCareer;

import java.time.LocalDate;

@Data
@Getter
@Setter
@Builder
@AllArgsConstructor
public class FindCareerResponse {
private Long careerId;
private String careerType;
private String careerTitle;
private String careerAlias;
private LocalDate startdate;
private LocalDate enddate;

public FindCareerResponse(BaseCareer career, String careerType){
this.careerId = career.getId();
this.careerType = careerType;
this.careerTitle = career.getName();
this.careerAlias = career.getAlias();
this.startdate = career.getStartdate();
this.enddate = career.getEnddate();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface ActivityRepository extends JpaRepository<Activity, Long> {
List<Activity> findByMemberId(Long memberId);
List<Activity> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface CircleRepository extends JpaRepository<Circle, Long> {
List<Circle> findByMemberId(Long memberId);
List<Circle> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface CompetitionRepository extends JpaRepository<Competition, Long> {
List<Competition> findByMemberId(Long memberId);
List<Competition> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface EduCareerRepository extends JpaRepository<EduCareer,Long> {
List<EduCareer> findByMemberId(Long memberId);
List<EduCareer> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface EmploymentRepository extends JpaRepository<Employment,Long> {
List<Employment> findByMemberId(Long memberId);
List<Employment> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface ProjectRepository extends JpaRepository<Project, Long> {
List<Project> findByMemberId(Long memberId);
List<Project> findByMemberIdAndNameContaining(Long memberId, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public interface BaseCareerService {
List<FindTagResponse> findAllTag(Member requestMember, String keyword);

List<FindDetailResponse> findAllDetailByTag(Member requestMember, Long tagId, String sort);

List<FindCareerResponse> findCareerWithKeyword(Member requestMember, String keyword, String sort);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.time.LocalDate;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -505,9 +504,27 @@ public List<FindDetailResponse> findAllDetailByTag(Member requestMember, Long ta
return buildDetailResponse(detailList, sort);
}

@Override
public List<FindCareerResponse> findCareerWithKeyword(Member requestMember, String keyword, String sort) {
List<BaseCareer> careers = new ArrayList<>();
careers.addAll(activityRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));
careers.addAll(eduCareerRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));
careers.addAll(employmentRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));
careers.addAll(circleRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));
careers.addAll(projectRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));
careers.addAll(competitionRepository.findByMemberIdAndNameContaining(requestMember.getId(),keyword));

if ("new".equalsIgnoreCase(sort)) {
careers.sort(Comparator.comparing(BaseCareer::getEnddate).reversed());
} else {
careers.sort(Comparator.comparing(BaseCareer::getEnddate));
}

return careers.stream().limit(2)
.map(career -> new FindCareerResponse(career, career.getClass().getSimpleName()))
.collect(Collectors.toList());


}


private List<FindDetailResponse> buildDetailResponse(List<BaseCareerDetail> detailList, String sort) {
Expand Down

0 comments on commit 47c34e7

Please sign in to comment.