Skip to content
Snippets Groups Projects
Commit 9c4ddb59 authored by 김영훈's avatar 김영훈
Browse files

Merge branch 'master' into 'main'

get_likes

See merge request !3
parents 43b0d9be b51db9e9
Branches
No related tags found
1 merge request!3get_likes
package com.ajou.prcoding.myweb.Controller;
import com.ajou.prcoding.myweb.entity.FavoriteMusic;
import com.ajou.prcoding.myweb.repository.FavoriteRepository;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -9,6 +12,7 @@ import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import com.ajou.prcoding.myweb.dto.MusicList;
......@@ -21,7 +25,7 @@ public class MyWebController {
@GetMapping(value = "/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term){
try {
String url = "https://itunes.apple.com/search?term=aespa&entity=album";
String url = String.format("https://itunes.apple.com/search?term=%s&entity=album",term);
String response = restTemplate.getForObject(url, String.class);
ObjectMapper mapper = new ObjectMapper();
......@@ -37,4 +41,16 @@ public class MyWebController {
public String musicSearchByParam(@RequestParam String term){
return "Hello Param!";
}
@GetMapping(value = "/likes")
@Autowired
public List<FavoriteMusic> getLikes(){
FavoriteRepository albumRepo = null;
try {
return albumRepo.findAll();
}catch (Exception e){
System.out.println(e.toString());
return null;
}
}
}
package com.ajou.prcoding.myweb.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(schema = "favoritMusic")
@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;
}
package com.ajou.prcoding.myweb.repository;
import com.ajou.prcoding.myweb.entity.FavoriteMusic;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
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