diff --git a/src/main/java/com/ajou/prcoding/myweb/Controller/MyWebController.java b/src/main/java/com/ajou/prcoding/myweb/Controller/MyWebController.java index 9c18e8480d4194b7fe4d403253f445e2c5dae412..0d6bfa16c8b74381889f47f884f34917a375c73b 100644 --- a/src/main/java/com/ajou/prcoding/myweb/Controller/MyWebController.java +++ b/src/main/java/com/ajou/prcoding/myweb/Controller/MyWebController.java @@ -4,6 +4,7 @@ import com.ajou.prcoding.myweb.dto.MusicList; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @@ -29,6 +30,19 @@ public class MyWebController { } } - + @GetMapping(value="/musicSearch") + public MusicList musicSearchByParam(@RequestParam String term){ + try { + String url = "https://itunes.apple.com/search?term=" + term + "&entity=album"; + 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; + } + } }