Skip to content

Commit

Permalink
[Feature] 검색어 공백 및 특수문자 처리 기능 추가
Browse files Browse the repository at this point in the history
[Feature] 검색어 공백 및 특수문자 처리 기능 추가
  • Loading branch information
Jeongmin39 authored Oct 8, 2024
2 parents ed7a478 + 378d448 commit c49559a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.spot.spotserver.api.spot.domain.Work;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface WorkRepository extends JpaRepository<Work, Long> {
List<Work> findByNameContainingIgnoreCase(String workName);
@Query("SELECT w FROM Work w WHERE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(w.name, ' ', ''), '!', ''), '?', ''), ',', ''), '-', ''), ':', '') " +
"LIKE CONCAT('%', REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(:workName, ' ', ''), '!', ''), '?', ''), ',', ''), '-', ''), ':', ''), '%')")
List<Work> searchWorksByName(String workName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ public List<SpotSummaryResponse> getTop5Spots(User user) {
}

public List<SpotSearchResponse> searchSpotsByWorkName(String workName, User user) {
List<Work> works = workRepository.findByNameContainingIgnoreCase(workName);
String trimmedWorkName = workName.trim().replaceAll("[!?,:-]", "");

List<Work> works = workRepository.searchWorksByName(trimmedWorkName);
if (works.isEmpty()) {
return new ArrayList<>();
}
Expand Down

0 comments on commit c49559a

Please sign in to comment.