Skip to content
Snippets Groups Projects
Commit 7ec89df3 authored by kim daeun's avatar kim daeun
Browse files

get_likes

parent ad4b9d53
No related branches found
No related tags found
No related merge requests found
package com.ajou.procoding.myweb.controller; package com.ajou.procoding.myweb.controller;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -8,17 +10,22 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -8,17 +10,22 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.ajou.procoding.myweb.dto.MusicList; import com.ajou.procoding.myweb.dto.MusicList;
import com.ajou.procoding.myweb.entity.FavoriteMusic;
import com.ajou.procoding.myweb.repository.FavoriteRepository;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@RestController @RestController
public class MyWebController { public class MyWebController {
RestTemplate restTemplate = new RestTemplate();
@Autowired
FavoriteRepository albumsRepo;
@GetMapping(value="/musicSearch/{term}") @GetMapping(value="/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term) { public MusicList musicSearchByPath(@PathVariable String term) {
try { try {
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term); String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term);
String response = restTemplate.getForObject(url, String.class); String response = restTemplate.getForObject(url, String.class);
//String response = restTemplate.getForObject("https://itunes.apple.com/search?term=aespa&entity=album", String.class);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class); MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount()); System.out.println(list.getResultCount());
...@@ -34,7 +41,6 @@ public class MyWebController { ...@@ -34,7 +41,6 @@ public class MyWebController {
try { try {
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term); String url = String.format("https://itunes.apple.com/search?term=%s&entity=album", term);
String response = restTemplate.getForObject(url, String.class); String response = restTemplate.getForObject(url, String.class);
//String response = restTemplate.getForObject("https://itunes.apple.com/search?term=aespa&entity=album", String.class);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
MusicList list = mapper.readValue(response, MusicList.class); MusicList list = mapper.readValue(response, MusicList.class);
System.out.println(list.getResultCount()); System.out.println(list.getResultCount());
...@@ -46,6 +52,21 @@ public class MyWebController { ...@@ -46,6 +52,21 @@ public class MyWebController {
} }
//몇 줄 아닌거 같아 보이는데 많은 일을 함 //몇 줄 아닌거 같아 보이는데 많은 일을 함
RestTemplate restTemplate = new RestTemplate(); //Get Favorite Music list from Database
@GetMapping(value="/likes")
public List<FavoriteMusic> getLikes() {
try {
return albumsRepo.findAll();
} catch (Exception e) {
System.out.println(e.toString());
}
return null;
}
} }
\ No newline at end of file
package com.ajou.procoding.myweb.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Entity
@Table(name="favoriteMusic")
@Getter
@Setter
@ToString
public class FavoriteMusic {
@Id @Column(length=32) private String collectionId;
@Column private String collectionType;
@Column private String artistId;
@Column private String artistName;
@Column private String artistViewUrl;
@Column private String collectionName;
@Column private String collectionViewUrl;
}
\ No newline at end of file
package com.ajou.procoding.myweb.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import com.ajou.procoding.myweb.entity.FavoriteMusic;
public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String> {
List<FavoriteMusic> findAll();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment