Skip to content
Snippets Groups Projects
Commit f7720ab7 authored by DongHwi Kim's avatar DongHwi Kim
Browse files

connect react

parent 2fda3af3
Branches
No related tags found
No related merge requests found
...@@ -25,8 +25,6 @@ import kr.ajousw.myspringweb.service.MusicService; ...@@ -25,8 +25,6 @@ import kr.ajousw.myspringweb.service.MusicService;
@RestController @RestController
public class MyWebController{ public class MyWebController{
private final RestTemplate restTemplate = new RestTemplate();
private final String BASE_URL = "<https://itunes.apple.com/search?entity=song&attribute=songTerm&term=>";
@Autowired @Autowired
MusicService service; MusicService service;
......
package kr.ajousw.myspringweb.service; package kr.ajousw.myspringweb.service;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -24,19 +26,23 @@ public class MusicService { ...@@ -24,19 +26,23 @@ public class MusicService {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
HttpServletRequest request; HttpServletRequest request;
public MusicList searchMusic(String name){ public MusicList searchMusic(String name){
String url = "https://itunes.apple.com/search?term=" + name + "&entity=album";
RestTemplate restTemplate = new RestTemplate();
MusicList musicList = null;
try { try {
String jsonString = restTemplate.getForObject(request.getRequestURI(), String.class); String response = restTemplate.getForObject(url, String.class);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
musicList = objectMapper.readValue(jsonString, MusicList.class); MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount());
return list;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); System.out.println(e.toString());
return null;
} }
return musicList;
} }
public List<FavoriteMusic> getLikes() { public List<FavoriteMusic> getLikes() {
try{ try{
return albumsRepo.findAll(); return albumsRepo.findAll();
......
This diff is collapsed.
<!doctype html>
<html>
<head>
<title> muiBasic </title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</head>
<body>
<div id="app"></div>
<script src="./app.bundle.js" type="text/javascript"></script>
</body>
</html>
\ No newline at end of file
No preview for this file type
No preview for this file type
This diff is collapsed.
<!doctype html>
<html>
<head>
<title> muiBasic </title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</head>
<body>
<div id="app"></div>
<script src="./app.bundle.js" type="text/javascript"></script>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment