From 84bb4232e0413fea5c4a464fab7d6b3125309064 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Tue, 2 Dec 2025 07:58:10 -0300 Subject: [PATCH] Create an endpoint to list hosted lyrics id --- .../api/controller/LyricsController.java | 10 ++++++++++ .../wordview/api/service/VideoLyricsService.java | 16 ++++++++++++++++ .../VideoLyricsServiceInterface.java | 3 +++ .../api/controller/LyricsControllerTest.java | 7 +++++++ 4 files changed, 36 insertions(+) diff --git a/src/main/java/cc/wordview/api/controller/LyricsController.java b/src/main/java/cc/wordview/api/controller/LyricsController.java index acaba31..4def126 100644 --- a/src/main/java/cc/wordview/api/controller/LyricsController.java +++ b/src/main/java/cc/wordview/api/controller/LyricsController.java @@ -20,6 +20,7 @@ import cc.wordview.api.Application; import cc.wordview.api.response.LyricsResponse; import cc.wordview.api.service.LyricsService; +import cc.wordview.api.service.specification.VideoLyricsServiceInterface; import cc.wordview.api.util.ArrayUtil; import cc.wordview.api.util.WordViewResourceResolver; import cc.wordview.gengolex.Language; @@ -44,6 +45,9 @@ public class LyricsController extends ServiceController { @Autowired private WordViewResourceResolver resourceResolver; + @Autowired + private VideoLyricsServiceInterface videoLyricsService; + @GetMapping(produces = "application/json;charset=utf-8") public ResponseEntity getLyrics(@RequestParam String id, @RequestParam String lang, @RequestParam String trackName, @RequestParam String artistName) throws IOException, LyricsNotFoundException, LanguageNotFoundException { String decodedTrackName = URLDecoder.decode(trackName); @@ -59,4 +63,10 @@ public ResponseEntity getLyrics(@RequestParam String id, @RequestParam String return ok(new LyricsResponse(lyrics, words)); } + + @GetMapping(produces = "application/json;charset=utf-8", path = "/list") + public ResponseEntity getLyricsList() { + ArrayList ids = videoLyricsService.listLyricsIds(); + return ok(ids); + } } diff --git a/src/main/java/cc/wordview/api/service/VideoLyricsService.java b/src/main/java/cc/wordview/api/service/VideoLyricsService.java index db178fb..5905118 100644 --- a/src/main/java/cc/wordview/api/service/VideoLyricsService.java +++ b/src/main/java/cc/wordview/api/service/VideoLyricsService.java @@ -24,8 +24,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Optional; +import static org.antlr.v4.runtime.tree.xpath.XPath.findAll; + @Service public class VideoLyricsService implements VideoLyricsServiceInterface { @Autowired @@ -43,6 +46,19 @@ public VideoLyrics getByVideoId(String videoId) throws NoSuchEntryException { } @Override + public ArrayList listLyricsIds() { + Iterable allLyrics = repository.findAll(); + ArrayList ids = new ArrayList<>(); + + for (VideoLyrics lyric : allLyrics) { + ids.add(lyric.getVideoId()); + } + + return ids; + } + + + @Override public VideoLyrics getById(Long id) { throw new UnsupportedOperationException("getById is disabled for VideoLyricsService"); } diff --git a/src/main/java/cc/wordview/api/service/specification/VideoLyricsServiceInterface.java b/src/main/java/cc/wordview/api/service/specification/VideoLyricsServiceInterface.java index 84e202c..142747c 100644 --- a/src/main/java/cc/wordview/api/service/specification/VideoLyricsServiceInterface.java +++ b/src/main/java/cc/wordview/api/service/specification/VideoLyricsServiceInterface.java @@ -20,6 +20,9 @@ import cc.wordview.api.database.entity.VideoLyrics; import cc.wordview.api.exception.NoSuchEntryException; +import java.util.ArrayList; + public interface VideoLyricsServiceInterface extends ServiceInterface { VideoLyrics getByVideoId(String videoId) throws NoSuchEntryException; + ArrayList listLyricsIds(); } diff --git a/src/test/java/cc/wordview/api/test/api/controller/LyricsControllerTest.java b/src/test/java/cc/wordview/api/test/api/controller/LyricsControllerTest.java index 90ca61d..212496d 100644 --- a/src/test/java/cc/wordview/api/test/api/controller/LyricsControllerTest.java +++ b/src/test/java/cc/wordview/api/test/api/controller/LyricsControllerTest.java @@ -63,5 +63,12 @@ void getLyricsNotFound() throws Exception { URLEncoder.encode("aa") )).andExpect(status().isNotFound()); } + + @Test + void getListOfLyricsIds() throws Exception { + req.get("/lyrics/list") + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=utf-8")); + } }