Skip to content
Snippets Groups Projects
Commit a4fd9c08 authored by 최현수's avatar 최현수
Browse files

get_likes

parent 43fbeb68
No related branches found
No related tags found
No related merge requests found
Pipeline #8271 canceled
package kr.ajousw.myspringweb.controller; package kr.ajousw.myspringweb.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,9 +11,14 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -8,9 +11,14 @@ 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 kr.ajousw.myspringweb.dto.MusicList; import kr.ajousw.myspringweb.dto.MusicList;
import kr.ajousw.myspringweb.entity.FavoriteMusic;
import kr.ajousw.myspringweb.repository.FavoriteRepository;
@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) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
...@@ -42,4 +50,14 @@ public class MyWebController { ...@@ -42,4 +50,14 @@ public class MyWebController {
return null; return null;
} }
} }
@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.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@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;
import org.springframework.stereotype.Repository;
public interface FavoriteRepository extends JpaRepository<FavoriteMusic, String> {
List<FavoriteMusic> findAll();
}
CREATE DATABASE webdev default character set utf8 collate utf8_general_ci
\ No newline at end of file
create database webdev default character set utf8 collate utf8_general_ci
\ 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