2121import java .io .InputStream ;
2222import java .nio .charset .StandardCharsets ;
2323import java .sql .Timestamp ;
24+ import java .util .ArrayList ;
25+ import java .util .LinkedHashSet ;
2426import java .util .List ;
2527import java .util .Map ;
28+ import java .util .Set ;
2629
2730import org .slf4j .Logger ;
2831import 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