Skip to content

Commit

Permalink
Merge pull request #71 from teamMinari/Feat/#70
Browse files Browse the repository at this point in the history
Feat :: 검색 기능 강화
  • Loading branch information
whitenoise13 authored Oct 17, 2024
2 parents 049f921 + 3bd0814 commit 1e2e412
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public ResponseData<List<TermResponseDTO>> getLevelTerms(@PathVariable Long leve
return termService.getLevelTerms(level);
}

@GetMapping("/keyword")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "키워드가 포함된 용어 조회", description = "키워드를 포함한 모든 용어들을 리스트로 보여줍니다.")
public ResponseData<List<TermResponseDTO>> getTermsByKeyword(@RequestParam String keyword) {
return termService.getTermsByKeyword(keyword);
}

// 용어 등록
@PostMapping
@ResponseStatus(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import lombok.Builder;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;

@Getter
@Builder
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public ResponseData<TermOneLikeLoadRes> getTermsWithNm(String termNm) {
}
}

// 키워드가 포함된 모든 용어 조회
public ResponseData<List<TermResponseDTO>> getTermsByKeyword(String keyword) {
List<Term> termList = termRepository.findByTermNmContaining(keyword);

return ResponseData.of(HttpStatus.OK, "키워드가 포함된 모든 단어 조회 성공!",
termList.stream().map(
TermResponseDTO::of
).toList());
}


// 용어 생성
public Response createTerm(TermRequestDTO requestDTO) {
MemberEntity curMember = userSessionHolder.current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;

Expand All @@ -15,4 +17,7 @@ public interface TermRepository extends JpaRepository<Term, Long> {
Page<Term> findAll(Pageable pageable);
Term findByTermNm(String termNm);

@Query("SELECT t FROM Term t WHERE t.termNm LIKE %:keyword%")
List<Term> findByTermNmContaining(@Param("keyword") String keyword);

}

0 comments on commit 1e2e412

Please sign in to comment.