Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.movelog.global.config.security.token.UserPrincipal;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -34,10 +35,11 @@ public class KeywordService {

public List<SearchKeywordInStatsRes> searchKeywordInStats(UserPrincipal userPrincipal, String keyword) {

User user = validUserById(userPrincipal);
validUserById(userPrincipal);

// 검색어를 포함한 키워드 리스트 조회
List<Keyword> keywords = keywordRepository.findAllByUserAndKeywordContaining(user, keyword);
List<Keyword> keywords = keywordRepository.findAllKeywordStartingWith(keyword);
log.info("Searching for keywords starting with: {}", keyword);

// 기록이 많은 순서대로 정렬
keywords = sortKeywordByRecordCount(keywords);
Expand Down Expand Up @@ -123,8 +125,8 @@ private double roundToTwoDecimal(double value) {
}

private User validUserById(UserPrincipal userPrincipal) {
Optional<User> userOptional = userService.findById(userPrincipal.getId());
// Optional<User> userOptional = userRepository.findById(5L);
// Optional<User> userOptional = userService.findById(userPrincipal.getId());
Optional<User> userOptional = userRepository.findById(5L);
if (userOptional.isEmpty()) { throw new UserNotFoundException(); }
return userOptional.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.movelog.domain.record.domain.VerbType;
import com.movelog.domain.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -21,4 +22,8 @@ public interface KeywordRepository extends JpaRepository<Keyword,Long> {

List<Keyword> findAllByUserAndKeywordContaining(User user, String keyword);

@Query("SELECT k FROM Keyword k WHERE LOWER(k.keyword) LIKE LOWER(CONCAT(:keyword, '%'))")
List<Keyword> findAllKeywordStartingWith(String keyword);


}