Skip to content

Commit

Permalink
Merge pull request #84 from Princess-in-silvertown/refactor/82
Browse files Browse the repository at this point in the history
Refactor: ํ•™๊ต ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ์ตœ์†Œ Limit ์„ค์ •
  • Loading branch information
loveysuby authored Sep 29, 2024
2 parents 70a2244 + a0df7df commit 62ec94e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private List<GroupResponse> findRegisteredGroups(Long userId) {
}

private List<GroupResponse> findGroupsByKeywords(String keyword) {
return groupRepository.findByNameLike(keyword).stream()
String keywordWithWildcard = "%" + keyword + "%";
return groupRepository.findTop30ByNameLike(keywordWithWildcard).stream()
.map(each -> new GroupResponse(each.getId(), each.getName()))
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import slvtwn.khu.toyouserver.domain.Group;

public interface GroupRepository extends JpaRepository<Group, Long> {

@Query("select g from Group g where g.name like %:keyword%")
List<Group> findByNameLike(String keyword);
List<Group> findTop30ByNameLike(String keyword);
}

0 comments on commit 62ec94e

Please sign in to comment.