Skip to content
Snippets Groups Projects
Commit 989b2645 authored by 김재현's avatar 김재현
Browse files

get_likes

parent b4d7795a
No related branches found
No related tags found
No related merge requests found
......@@ -4,18 +4,26 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
import kr.ajousw.myspringweb.dto.Musiclist;
import kr.ajousw.myspringweb.entity.FavoriteMusic;
import kr.ajousw.myspringweb.repository.FavoriteRepository;
@RestController
public class MyWebController {
@Autowired
FavoriteRepository albumsRepo;
@GetMapping(value = "/musicSearch/{term}")
public Musiclist musicSearchByPath(@RequestParam String term) {
public Musiclist musicSearchByPath(@PathVariable String term) {
RestTemplate restTemplate = new RestTemplate();
String url = "https://itunes.apple.com/search?term=" + term +
"&entity=musicVideo";
String url = "https://itunes.apple.com/search?term=" + term + "&entity=musicVideo";
// String url = "https://itunes.apple.com/search?term=aespa&entity=album";
try {
String response = restTemplate.getForObject(url, String.class);
......@@ -31,11 +39,10 @@ public class MyWebController {
}
@GetMapping(value = "/musicSearch")
public Musiclist musicSearchByParam(@RequestParam(value = "term") String name) {
public Musiclist musicSearchByParam(@RequestParam String term) {
RestTemplate restTemplate = new RestTemplate();
// String url = "https://itunes.apple.com/search?term=" + term +
// "&entity=musicVideo";
String url = "https://itunes.apple.com/search?term=aespa&entity=album";
String url = "https://itunes.apple.com/search?term=" + term + "&entity=musicVideo";
// String url = "https://itunes.apple.com/search?term=aespa&entity=album";
try {
String response = restTemplate.getForObject(url, String.class);
ObjectMapper mapper = new ObjectMapper();
......@@ -48,4 +55,21 @@ public class MyWebController {
}
return null;
}
@GetMapping(value = "/likes")
public List<FavoriteMusic> getLikes() {
try {
return albumsRepo.findAll();
} catch (Exception e) {
System.out.println(e.toString());
return null;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment