Skip to content
Snippets Groups Projects
Commit c87d1ae7 authored by suhyeon's avatar suhyeon
Browse files

get_likes

parent c6f0738b
No related branches found
No related tags found
No related merge requests found
Pipeline #8292 canceled
package kr.ajousw.myspringweb.controller; package kr.ajousw.myspringweb.controller;
import kr.ajousw.myspringweb.dto.MusicList; import kr.ajousw.myspringweb.dto.MusicList;
import kr.ajousw.myspringweb.entity.FavoriteMusic;
import kr.ajousw.myspringweb.repository.FavoriteRepository;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
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;
...@@ -12,6 +17,10 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -12,6 +17,10 @@ import org.springframework.web.bind.annotation.RequestParam;
@RestController @RestController
public class MyWebController { public class MyWebController {
@Autowired
FavoriteRepository albumsRepo;
@GetMapping(value="/musicSearch/{term}") @GetMapping(value="/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term) { public MusicList musicSearchByPath(@PathVariable String term) {
...@@ -54,4 +63,15 @@ public class MyWebController { ...@@ -54,4 +63,15 @@ public class MyWebController {
return null; 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;
}
}
} }
\ No newline at end of file
package kr.ajousw.myspringweb.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import jakarta.persistence.*;
@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;
}
package kr.ajousw.myspringweb.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import kr.ajousw.myspringweb.entity.FavoriteMusic;
public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String> {
List<FavoriteMusic> findAll();
}
\ 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