Skip to content
Snippets Groups Projects
Commit 6e15a3f7 authored by Yunji Choi's avatar Yunji Choi
Browse files

get_likes

parent 4d174339
No related branches found
No related tags found
No related merge requests found
Pipeline #8282 canceled
package com.ajou.prcoding.myweb.controller; package com.ajou.prcoding.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;
...@@ -9,11 +11,17 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -9,11 +11,17 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.ajou.prcoding.myweb.dto.MusicList; 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; import com.fasterxml.jackson.databind.ObjectMapper;
@RestController @RestController
public class MyWebController { public class MyWebController {
@Autowired
FavoriteRepository albumsRepo;
// PathVariable 방식 => localhost/musicSearch/aespa 로 접속 // PathVariable 방식 => localhost/musicSearch/aespa 로 접속
@GetMapping(value = "/musicSearch/{term}") @GetMapping(value = "/musicSearch/{term}")
public MusicList musicSearchByPath(@PathVariable String term) { public MusicList musicSearchByPath(@PathVariable String term) {
...@@ -50,4 +58,23 @@ public class MyWebController { ...@@ -50,4 +58,23 @@ public class MyWebController {
} }
} }
// 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.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;
}
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();
}
\ No newline at end of file
No preview for this file type
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment