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 38f70a000483abad66fca1dd01c4936a14271fd6..cee19956a5976b5b539171954bce18f682a1830a 100644 --- a/src/main/java/com/ajou/prcoding/myweb/controller/MyWebController.java +++ b/src/main/java/com/ajou/prcoding/myweb/controller/MyWebController.java @@ -6,15 +6,20 @@ 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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import com.ajou.prcoding.myweb.dto.FavoriteMusicRequestDto; 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 jakarta.transaction.Transactional; + @RestController public class MyWebController { @@ -77,4 +82,15 @@ public class MyWebController { } + @PostMapping(value = "/likes") + @Transactional + public int postLikes(@RequestBody FavoriteMusicRequestDto favorite) { + FavoriteMusic music = albumsRepo.save(favorite.toEntity()); + if (music != null) { + return 1; + } else { + return 0; + } + } + } \ No newline at end of file diff --git a/src/main/java/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.java b/src/main/java/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.java new file mode 100644 index 0000000000000000000000000000000000000000..109a04c55f4588126a673c872a3dc15c1ccd323f --- /dev/null +++ b/src/main/java/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.java @@ -0,0 +1,33 @@ +package com.ajou.prcoding.myweb.dto; + +import com.ajou.prcoding.myweb.entity.FavoriteMusic; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class FavoriteMusicRequestDto { + private String collectionId; + private String collectionViewUrl; + private String collectionType; + private String collectionName; + private String artistId; + private String artistName; + private String artistViewUrl; + + public FavoriteMusic toEntity() { + FavoriteMusic music = new FavoriteMusic(); + music.setCollectionId(this.collectionId); + music.setCollectionType(this.collectionType); + music.setArtistId(this.artistId); + music.setArtistName(this.artistName); + music.setArtistViewUrl(this.artistViewUrl); + music.setCollectionViewUrl(this.collectionViewUrl); + music.setCollectionName(this.collectionName); + + return music; + } +} diff --git a/src/main/java/com/ajou/prcoding/myweb/postSong.json b/src/main/java/com/ajou/prcoding/myweb/postSong.json new file mode 100644 index 0000000000000000000000000000000000000000..936a55bb7145ce7e6d826ae32208e180a8e7265c --- /dev/null +++ b/src/main/java/com/ajou/prcoding/myweb/postSong.json @@ -0,0 +1,22 @@ +{ + "wrapperType": "collection", + "collectionType": "Album", + "artistId": 994656, + "collectionId": 580708175, + "amgArtistId": 4739, + "artistName": "Led Zeppelin", + "collectionName": "Led Zeppelin IV (Remastered)", + "collectionCensoredName": "Led Zeppelin IV (Remastered)", + "artistViewUrl": "https://music.apple.com/us/artist/led-zeppelin/994656?uo=4", + "collectionViewUrl": "https://music.apple.com/us/album/led-zeppelin-iv-remastered/580708175?uo=4", + "artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music115/v4/5c/15/9b/5c159b27-95ca-b9a7-84e3-28e795fffd39/dj.kvkrpptq.jpg/60x60bb.jpg", + "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music115/v4/5c/15/9b/5c159b27-95ca-b9a7-84e3-28e795fffd39/dj.kvkrpptq.jpg/100x100bb.jpg", + "collectionPrice": 9.99, + "collectionExplicitness": "notExplicit", + "trackCount": 8, + "copyright": "℗ 1971 Atlantic Recording Corporation, a Warner Music Group Company. Marketed by Rhino Entertainment Company, a Warner Music Group Company.", + "country": "USA", + "currency": "USD", + "releaseDate": "1971-11-08T08:00:00Z", + "primaryGenreName": "Rock" +} \ No newline at end of file diff --git a/target/classes/com/ajou/prcoding/myweb/controller/MyWebController.class b/target/classes/com/ajou/prcoding/myweb/controller/MyWebController.class index 2aad2580c210ad7e8370097ed95393f87ad37fef..0ce323eed2fff8368778f59501a5d27a23511a9e 100644 Binary files a/target/classes/com/ajou/prcoding/myweb/controller/MyWebController.class and b/target/classes/com/ajou/prcoding/myweb/controller/MyWebController.class differ diff --git a/target/classes/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.class b/target/classes/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.class new file mode 100644 index 0000000000000000000000000000000000000000..ab526b30891ffc0605aac480f2636ee12c8eb554 Binary files /dev/null and b/target/classes/com/ajou/prcoding/myweb/dto/FavoriteMusicRequestDto.class differ diff --git a/target/classes/com/ajou/prcoding/myweb/postSong.json b/target/classes/com/ajou/prcoding/myweb/postSong.json new file mode 100644 index 0000000000000000000000000000000000000000..936a55bb7145ce7e6d826ae32208e180a8e7265c --- /dev/null +++ b/target/classes/com/ajou/prcoding/myweb/postSong.json @@ -0,0 +1,22 @@ +{ + "wrapperType": "collection", + "collectionType": "Album", + "artistId": 994656, + "collectionId": 580708175, + "amgArtistId": 4739, + "artistName": "Led Zeppelin", + "collectionName": "Led Zeppelin IV (Remastered)", + "collectionCensoredName": "Led Zeppelin IV (Remastered)", + "artistViewUrl": "https://music.apple.com/us/artist/led-zeppelin/994656?uo=4", + "collectionViewUrl": "https://music.apple.com/us/album/led-zeppelin-iv-remastered/580708175?uo=4", + "artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music115/v4/5c/15/9b/5c159b27-95ca-b9a7-84e3-28e795fffd39/dj.kvkrpptq.jpg/60x60bb.jpg", + "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music115/v4/5c/15/9b/5c159b27-95ca-b9a7-84e3-28e795fffd39/dj.kvkrpptq.jpg/100x100bb.jpg", + "collectionPrice": 9.99, + "collectionExplicitness": "notExplicit", + "trackCount": 8, + "copyright": "℗ 1971 Atlantic Recording Corporation, a Warner Music Group Company. Marketed by Rhino Entertainment Company, a Warner Music Group Company.", + "country": "USA", + "currency": "USD", + "releaseDate": "1971-11-08T08:00:00Z", + "primaryGenreName": "Rock" +} \ No newline at end of file