Skip to content

Commit 4b39a34

Browse files
committed
fix: address filter #99
1 parent 02afe00 commit 4b39a34

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

backend/src/main/java/com/example/backend/search/domain/SearchSpecification.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.springframework.data.jpa.domain.Specification;
55

66
import java.time.LocalDateTime;
7-
import java.util.List;
87

98
public class SearchSpecification {
109

@@ -53,25 +52,24 @@ public static Specification<CaseEntity> hasPolice(String police) {
5352
// police == null ? criteriaBuilder.conjunction() : criteriaBuilder.equal(root.get("police"), police);
5453
}
5554

56-
57-
// cctv_id 필터 추가 (cctv_info 테이블에서 가져온 id 값)
58-
public static Specification<CaseEntity> hasCctvIds(List<Integer> cctvIds) {
55+
// 주소 포함 필터
56+
public static Specification<CaseEntity> hasAddress(String address) {
5957
return (root, query, criteriaBuilder) -> {
60-
if (cctvIds == null || cctvIds.isEmpty()) {
61-
return criteriaBuilder.conjunction(); // 조건 없으면 전체 조회
58+
if (address == null || address.trim().isEmpty()) {
59+
return criteriaBuilder.conjunction();
6260
}
63-
return root.get("cctv").get("id").in(cctvIds);
61+
return criteriaBuilder.like(root.get("cctv").get("address"), "%" + address + "%");
6462
};
6563
}
6664

6765
// 여러 조건을 조합하는 메서드
68-
public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, List<Integer> cctvIds, Integer officeId) {
66+
public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, String address, Integer officeId) {
6967
return Specification
7068
.where(hasOffice(officeId))
7169
.and(hasState("완료"))
72-
.and(hasDateRange(startDate, endDate)) // 날짜 범위 조건을 추가
73-
.and(hasCctvIds(cctvIds))
74-
.and(hasPolice(police)) // police 필터 추가
70+
.and(hasDateRange(startDate, endDate))
71+
.and(hasAddress(address))
72+
.and(hasPolice(police))
7573
.and(hasCategory(category));
7674
}
7775

backend/src/main/java/com/example/backend/search/service/SearchService.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.example.backend.common.domain.CaseEntity;
44
import com.example.backend.search.domain.SearchSpecification;
55
import com.example.backend.search.dto.*;
6-
import com.example.backend.search.repository.CctvRepository;
76
import com.example.backend.search.repository.SearchRepository;
87
import lombok.RequiredArgsConstructor;
98
import org.springframework.data.domain.*;
@@ -20,18 +19,12 @@
2019
@RequiredArgsConstructor
2120
public class SearchService {
2221
private final SearchRepository searchRepository;
23-
private final CctvRepository cctvRepository;
2422
private static final int PAGE_SIZE = 8; // 한 페이지당 8개씩
2523

2624
public SearchResult getCheckLog(String category, LocalDateTime startDate, LocalDateTime endDate, String address, String police, String order, Integer page, Integer officeId) {
27-
// address가 있을 경우, cctv_info에서 해당 주소를 가진 cctv_id 리스트 조회
28-
List<Integer> cctvIds = null;
29-
if (address != null) {
30-
cctvIds = cctvRepository.findCctvIdsByAddress(address);
31-
}
3225

3326
// 동적 검색 조건 생성
34-
Specification<CaseEntity> spec = SearchSpecification.filterCases(category, startDate, endDate, police, cctvIds, officeId);
27+
Specification<CaseEntity> spec = SearchSpecification.filterCases(category, startDate, endDate, police, address, officeId);
3528

3629
// 정렬 설정
3730
Sort sort = Sort.unsorted();

0 commit comments

Comments
 (0)