Skip to content

Commit fc1939b

Browse files
committed
refactor/OPS-346 : 검색 기능 출처 누락 수정
1 parent 1568ea0 commit fc1939b

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/controller/DatasourceController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public ResponseEntity<?> search(
231231
@RequestParam(required = false) String title,
232232
@RequestParam(required = false) String summary,
233233
@RequestParam(required = false) String category,
234+
@RequestParam(required = false) String keyword,
234235
@RequestParam(required = false) Integer folderId,
235236
@RequestParam(required = false) String folderName,
236237
@RequestParam(required = false, defaultValue = "true") Boolean isActive,
@@ -247,6 +248,7 @@ public ResponseEntity<?> search(
247248
.folderId(folderId)
248249
.folderName(folderName)
249250
.isActive(isActive)
251+
.keyword(keyword)
250252
.build();
251253

252254
Page<DataSourceSearchItem> page = dataSourceService.search(memberId, cond, pageable);

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/dto/DataSourceSearchCondition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ public class DataSourceSearchCondition {
1212
private final Integer folderId;
1313
private final String folderName;
1414
private final Boolean isActive;
15+
private final String keyword;
1516
}

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/dto/DataSourceSearchItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DataSourceSearchItem {
1313
private String title;
1414
private LocalDate dataCreatedDate;
1515
private String summary;
16+
private String source;
1617
private String sourceUrl;
1718
private String imageUrl;
1819
private List<String> tags;

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/repository/DataSourceQRepositoryImpl.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.*;
2121
import java.util.stream.Collectors;
2222

23+
import static org.springframework.util.StringUtils.hasText;
24+
2325
@Repository
2426
@RequiredArgsConstructor
2527
public class DataSourceQRepositoryImpl implements DataSourceQRepository {
@@ -52,6 +54,15 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
5254
if (cond.getCategory() != null && !cond.getCategory().isBlank()) {
5355
where.and(ds.category.stringValue().containsIgnoreCase(cond.getCategory()));
5456
}
57+
if (hasText(cond.getKeyword())) {
58+
String kw = cond.getKeyword();
59+
where.and(
60+
ds.title.containsIgnoreCase(kw)
61+
.or(ds.summary.containsIgnoreCase(kw))
62+
.or(ds.category.stringValue().containsIgnoreCase(kw))
63+
);
64+
}
65+
5566
if (cond.getFolderName() != null && !cond.getFolderName().isBlank()) {
5667
where.and(ds.folder.name.eq(cond.getFolderName()));
5768
}
@@ -72,7 +83,7 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
7283

7384
// content
7485
JPAQuery<Tuple> contentQuery = queryFactory
75-
.select(ds.id, ds.title, ds.dataCreatedDate, ds.summary, ds.sourceUrl, ds.imageUrl, ds.category)
86+
.select(ds.id, ds.title, ds.dataCreatedDate, ds.summary, ds.source, ds.sourceUrl, ds.imageUrl, ds.category)
7687
.from(ds)
7788
.join(ds.folder, folder)
7889
.join(pa).on(pa.archive.eq(folder.archive))
@@ -110,13 +121,13 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
110121
Collectors.mapping(row -> row.get(tag.tagName), Collectors.toList())
111122
));
112123

113-
// map to DTO
114124
List<DataSourceSearchItem> content = tuples.stream()
115125
.map(row -> new DataSourceSearchItem(
116126
row.get(ds.id),
117127
row.get(ds.title),
118128
row.get(ds.dataCreatedDate),
119129
row.get(ds.summary),
130+
row.get(ds.source),
120131
row.get(ds.sourceUrl),
121132
row.get(ds.imageUrl),
122133
tagsById.getOrDefault(row.get(ds.id), List.of()),
@@ -140,7 +151,7 @@ private List<OrderSpecifier<?>> toOrderSpecifiers(Sort sort) {
140151
switch (o.getProperty()) {
141152
case "title" ->
142153
specs.add(new OrderSpecifier<>(dir, root.getString("title")));
143-
case "createdAt" -> // 요청 키
154+
case "createdAt" ->
144155
specs.add(new OrderSpecifier<>(dir, root.getDate("dataCreatedDate", java.time.LocalDate.class)));
145156
default -> { }
146157
}

0 commit comments

Comments
 (0)