Skip to content

Commit 6c0b8a8

Browse files
Update VideoController.java
1 parent 6215c87 commit 6c0b8a8

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/main/java/com/programming/videoService/controller/VideoController.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
import java.io.InputStream;
2222
import java.nio.charset.StandardCharsets;
2323
import java.sql.Timestamp;
24+
import java.util.ArrayList;
25+
import java.util.LinkedHashSet;
2426
import java.util.List;
2527
import java.util.Map;
28+
import java.util.Set;
2629

2730
import org.slf4j.Logger;
2831
import org.slf4j.LoggerFactory;
@@ -311,6 +314,29 @@ public ResponseEntity<?> getThumbnailsByUserGenres(@PathVariable String userId)
311314
}
312315
}
313316

317+
@GetMapping("/getThumbnailsByUserGenres2/{userId}")
318+
public ResponseEntity<?> getThumbnailsByUserGenres2(@PathVariable String userId) {
319+
try {
320+
// Gọi phương thức getThumbnailsByUserGenres để lấy danh sách đầu tiên
321+
List<String> thumbnailsByGenres = videoService.getThumbnailIdsByUserGenres(userId);
322+
323+
// Gọi phương thức listIdThumbnail để lấy danh sách thứ hai
324+
List<String> allThumbnails = videoService.listIdThumbnail();
325+
326+
// Sử dụng Set để xử lý loại bỏ trùng lặp
327+
Set<String> uniqueThumbnails = new LinkedHashSet<>(thumbnailsByGenres);
328+
uniqueThumbnails.addAll(allThumbnails);
329+
330+
// Chuyển Set thành List
331+
List<String> combinedThumbnails = new ArrayList<>(uniqueThumbnails);
332+
333+
return new ResponseEntity<>(combinedThumbnails, HttpStatus.OK);
334+
} catch (Exception e) {
335+
return new ResponseEntity<>("Error fetching thumbnails: " + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
336+
}
337+
}
338+
339+
314340

315341

316342
@PostMapping("/process/{userId}")
@@ -340,4 +366,4 @@ public ResponseEntity<?> videoIdLargerThanFive() {
340366
return new ResponseEntity<>(videoService.getReportsWithHighFrequencyVideoIds(), HttpStatus.OK);
341367
}
342368

343-
}
369+
}

0 commit comments

Comments
 (0)