From 24398a10af3511085e0a25fd1ba5b9854f7a20ee Mon Sep 17 00:00:00 2001 From: Roman Mager Date: Sat, 31 Aug 2024 16:24:28 +0300 Subject: [PATCH] PR fixes --- .../com/ypm/controller/LibraryImportController.java | 10 +++------- src/main/java/com/ypm/controller/VideoController.java | 2 +- .../java/com/ypm/persistence/entity/VideoImport.java | 2 +- .../java/com/ypm/service/youtube/ImportService.java | 2 -- .../java/com/ypm/service/youtube/VideoServiceImp.java | 2 +- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ypm/controller/LibraryImportController.java b/src/main/java/com/ypm/controller/LibraryImportController.java index f984cf4..cbdd242 100644 --- a/src/main/java/com/ypm/controller/LibraryImportController.java +++ b/src/main/java/com/ypm/controller/LibraryImportController.java @@ -17,18 +17,14 @@ public class LibraryImportController { private final ImportService importService; - @PostMapping("/watchLater") - public ResponseEntity importWatchLaterLibrary(@RequestParam("file") MultipartFile file) { + @PostMapping("/watch-later") + public ResponseEntity importWatchLaterLibrary(@RequestParam("file") MultipartFile file) throws IOException { if (file.isEmpty()) { return ResponseEntity.badRequest().build(); } List savedVideos; - try { - savedVideos = importService.importCsv(file); - } catch (IOException e) { - throw new RuntimeException(e); // TODO: Update exception handling - } + savedVideos = importService.importCsv(file); var responseBody = String.format("Saved %s videos", savedVideos.size()); return ResponseEntity.ok().body(responseBody); diff --git a/src/main/java/com/ypm/controller/VideoController.java b/src/main/java/com/ypm/controller/VideoController.java index 5623e52..dc655aa 100644 --- a/src/main/java/com/ypm/controller/VideoController.java +++ b/src/main/java/com/ypm/controller/VideoController.java @@ -20,7 +20,7 @@ public class VideoController { private final VideoService videosService; private final TokenService tokenService; - @PostMapping("/loadData") + @PostMapping("/load") public ResponseEntity> getVideoData(@RequestBody List videoIds) throws IOException { var videoData = videosService.getVideoData(videoIds); diff --git a/src/main/java/com/ypm/persistence/entity/VideoImport.java b/src/main/java/com/ypm/persistence/entity/VideoImport.java index e48a966..249d711 100644 --- a/src/main/java/com/ypm/persistence/entity/VideoImport.java +++ b/src/main/java/com/ypm/persistence/entity/VideoImport.java @@ -21,6 +21,6 @@ public class VideoImport { public VideoImport(String videoId, String videoTimeStamp) { this.videoId = videoId; - this.dateAdded = OffsetDateTime.parse(videoTimeStamp); // TODO: Is it okay solution? + this.dateAdded = OffsetDateTime.parse(videoTimeStamp); } } diff --git a/src/main/java/com/ypm/service/youtube/ImportService.java b/src/main/java/com/ypm/service/youtube/ImportService.java index c5154b1..c8c9edd 100644 --- a/src/main/java/com/ypm/service/youtube/ImportService.java +++ b/src/main/java/com/ypm/service/youtube/ImportService.java @@ -23,7 +23,6 @@ public class ImportService { public List importCsv(MultipartFile file) throws IOException { final List videos = new ArrayList<>(); - // Parse CSV try (var reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) { String line; var header = true; @@ -42,7 +41,6 @@ public List importCsv(MultipartFile file) throws IOException { } } - // Save into DB return videoRepository.saveAll(videos); } } diff --git a/src/main/java/com/ypm/service/youtube/VideoServiceImp.java b/src/main/java/com/ypm/service/youtube/VideoServiceImp.java index 4868b69..03e634b 100644 --- a/src/main/java/com/ypm/service/youtube/VideoServiceImp.java +++ b/src/main/java/com/ypm/service/youtube/VideoServiceImp.java @@ -75,7 +75,7 @@ public void deleteVideo(String accessToken, String videoId) throws IOException { public List getVideoData(List videoIds) throws IOException { final int maxResults = 50; - // Remove duplicates from the incoming list with ids + // DEV-NOTE: Remove duplicates from the incoming list with ids videoIds = videoIds.stream().distinct().toList(); var videoDtoList = new ArrayList();