|
22 | 22 | import org.tuna.zoopzoop.backend.domain.datasource.entity.QDataSource; |
23 | 23 | import org.tuna.zoopzoop.backend.domain.datasource.entity.QTag; |
24 | 24 |
|
| 25 | +import java.time.LocalDate; |
25 | 26 | import java.time.LocalDateTime; |
26 | 27 | import java.util.ArrayList; |
27 | 28 | import java.util.List; |
@@ -115,23 +116,30 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi |
115 | 116 | .where(ds.id.in(ids)) |
116 | 117 | .fetch() |
117 | 118 | .stream() |
| 119 | + .filter(row -> row.get(tag.tagName) != null) |
118 | 120 | .collect(Collectors.groupingBy( |
119 | 121 | row -> row.get(ds.id), |
120 | 122 | Collectors.mapping(row -> row.get(tag.tagName), Collectors.toList()) |
121 | 123 | )); |
122 | 124 |
|
123 | 125 | List<DataSourceSearchItem> content = tuples.stream() |
124 | | - .map(row -> new DataSourceSearchItem( |
125 | | - row.get(ds.id), |
126 | | - row.get(ds.title), |
127 | | - row.get(ds.createDate).toLocalDate(), |
128 | | - row.get(ds.summary), |
129 | | - row.get(ds.source), |
130 | | - row.get(ds.sourceUrl), |
131 | | - row.get(ds.imageUrl), |
132 | | - tagsById.getOrDefault(row.get(ds.id), List.of()), |
133 | | - row.get(ds.category).name() |
134 | | - )) |
| 126 | + .map(row -> { |
| 127 | + Category cat = row.get(ds.category); |
| 128 | + String categoryCode = (cat != null ? cat.name() : null); |
| 129 | + LocalDateTime createdAt = row.get(ds.createDate); |
| 130 | + LocalDate createdDate = (createdAt != null ? createdAt.toLocalDate() : null); |
| 131 | + return new DataSourceSearchItem( |
| 132 | + row.get(ds.id), |
| 133 | + row.get(ds.title), |
| 134 | + createdDate, |
| 135 | + row.get(ds.summary), |
| 136 | + row.get(ds.source), |
| 137 | + row.get(ds.sourceUrl), |
| 138 | + row.get(ds.imageUrl), |
| 139 | + tagsById.getOrDefault(row.get(ds.id), List.of()), |
| 140 | + categoryCode |
| 141 | + ); |
| 142 | + }) |
135 | 143 | .toList(); |
136 | 144 |
|
137 | 145 | return new PageImpl<>(content, pageable, total); |
@@ -230,24 +238,30 @@ public Page<DataSourceSearchItem> searchInArchive(Integer archiveId, DataSourceS |
230 | 238 | .where(ds.id.in(tuples.stream().map(t -> t.get(ds.id)).toList())) |
231 | 239 | .fetch() |
232 | 240 | .stream() |
| 241 | + .filter(row -> row.get(tag.tagName) != null) |
233 | 242 | .collect(Collectors.groupingBy( |
234 | 243 | row -> row.get(ds.id), |
235 | 244 | Collectors.mapping(row -> row.get(tag.tagName), Collectors.toList()) |
236 | 245 | )); |
237 | 246 |
|
238 | 247 | List<DataSourceSearchItem> content = tuples.stream() |
239 | | - .map(row -> new DataSourceSearchItem( |
240 | | - row.get(ds.id), |
241 | | - row.get(ds.title), |
242 | | - // LocalDateTime(createDate) → LocalDate |
243 | | - row.get(ds.createDate).toLocalDate(), |
244 | | - row.get(ds.summary), |
245 | | - row.get(ds.source), |
246 | | - row.get(ds.sourceUrl), |
247 | | - row.get(ds.imageUrl), |
248 | | - tagsById.getOrDefault(row.get(ds.id), List.of()), |
249 | | - row.get(ds.category).name() // 응답은 영문 코드 유지 |
250 | | - )) |
| 248 | + .map(row -> { |
| 249 | + Category category = row.get(ds.category); |
| 250 | + String categoryCode = (category != null ? category.name() : null); // null 허용 |
| 251 | + LocalDateTime createdAt = row.get(ds.createDate); |
| 252 | + LocalDate createdDate = (createdAt != null ? createdAt.toLocalDate() : null); |
| 253 | + return new DataSourceSearchItem( |
| 254 | + row.get(ds.id), |
| 255 | + row.get(ds.title), |
| 256 | + createdDate, |
| 257 | + row.get(ds.summary), |
| 258 | + row.get(ds.source), |
| 259 | + row.get(ds.sourceUrl), |
| 260 | + row.get(ds.imageUrl), |
| 261 | + tagsById.getOrDefault(row.get(ds.id), List.of()), |
| 262 | + categoryCode |
| 263 | + ); |
| 264 | + }) |
251 | 265 | .toList(); |
252 | 266 |
|
253 | 267 | return new PageImpl<>(content, pageable, total); |
|
0 commit comments