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 2e28cf22f1999d4d856ff279744cd9b126c86647..5a95aaab85a1e68332e2f7e46fe72eba5f3dfb70 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);