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 053be3444a31efbd2ac37bbf0635ad5e02953042..79f41e3aafc88efb17fd10581cff1f2ff4e27cca 100644 --- a/src/main/java/com/ajou/prcoding/myweb/controller/MyWebController.java +++ b/src/main/java/com/ajou/prcoding/myweb/controller/MyWebController.java @@ -1,7 +1,9 @@ package com.ajou.prcoding.myweb.controller; 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.PathVariable; import org.springframework.web.bind.annotation.RequestParam; @@ -9,13 +11,19 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import com.ajou.prcoding.myweb.dto.MusicList; +import com.ajou.prcoding.myweb.entity.FavoriteMusic; +import com.ajou.prcoding.myweb.repository.FavoriteRepository; import com.fasterxml.jackson.databind.ObjectMapper; @RestController public class MyWebController { + @Autowired + FavoriteRepository albumsRepo; + + RestTemplate restTemplate = new RestTemplate(); + @GetMapping(value="/musicSearch/{term}") public MusicList musicSearchByPath(@PathVariable String term) { - RestTemplate restTemplate = new RestTemplate(); try { String response = restTemplate.getForObject("https://itunes.apple.com/search?term={term}&entity=album",String.class, "aespa"); ObjectMapper mapper = new ObjectMapper(); @@ -41,6 +49,16 @@ public class MyWebController { } return null; } + //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; + } +} diff --git a/src/main/java/com/ajou/prcoding/myweb/entity/FavoriteMusic.java b/src/main/java/com/ajou/prcoding/myweb/entity/FavoriteMusic.java new file mode 100644 index 0000000000000000000000000000000000000000..921201c94e84d778cc6fe29f412fa4e4960956cb --- /dev/null +++ b/src/main/java/com/ajou/prcoding/myweb/entity/FavoriteMusic.java @@ -0,0 +1,24 @@ +package com.ajou.prcoding.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; +} diff --git a/src/main/java/com/ajou/prcoding/myweb/repository/FavoriteRepository.java b/src/main/java/com/ajou/prcoding/myweb/repository/FavoriteRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..662d49d1fee319f483ed0cc6f7e8bc9095d170f6 --- /dev/null +++ b/src/main/java/com/ajou/prcoding/myweb/repository/FavoriteRepository.java @@ -0,0 +1,12 @@ +package com.ajou.prcoding.myweb.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.ajou.prcoding.myweb.entity.FavoriteMusic; + +public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String>{ + List<FavoriteMusic> findAll(); + +}