From 7345d888b00abbf543bdff7f601381fab80c8f61 Mon Sep 17 00:00:00 2001 From: JangMH <dnsfl1517@ajou.ac.kr> Date: Wed, 9 Apr 2025 16:23:17 +0900 Subject: [PATCH] musicSearch --- .../myweb/controller/MyWebController.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java b/src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java index 2e28cf2..5a95aaa 100644 --- a/src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java +++ b/src/main/java/com/ajou/procoding/myweb/controller/MyWebController.java @@ -16,13 +16,25 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class MyWebController { @GetMapping(value="/musicSearch/{term}") - public String musicSearchByPath(@PathVariable String term) { - return ""; + public MusicList musicSearchByPath(@PathVariable String term) { + RestTemplate restTemplate = new RestTemplate(); + String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term); + try { + String response = restTemplate.getForObject(url, String.class); + ObjectMapper mapper = new ObjectMapper(); + MusicList list = mapper.readValue(response, MusicList.class); + System.out.println(list.getResultCount()); + return list; + } catch (IOException e) { + System.out.println(e.toString()); + return null; + } } @GetMapping(value="/musicSearch") - public MusicList musicSearchByParam(@RequestParam String term) { RestTemplate restTemplate = new RestTemplate(); + public MusicList musicSearchByParam(@RequestParam String term) { + RestTemplate restTemplate = new RestTemplate(); String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term); try { String response = restTemplate.getForObject(url, String.class); -- GitLab