diff --git a/postSong.json b/postSong.json new file mode 100644 index 0000000000000000000000000000000000000000..ddb0c7efb7bca05f5cdcb8b0000059a226fd2add --- /dev/null +++ b/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" +} diff --git a/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java b/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java index 7236e43326dd8ebce3c7578cf01e24a947b9d76c..2507cfc848c65949602e630de271e4ee7bfae6d8 100644 --- a/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java +++ b/src/main/java/kr/ajousw/myspringweb/controller/MyWebController.java @@ -1,12 +1,16 @@ package kr.ajousw.myspringweb.controller; 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.fasterxml.jackson.databind.ObjectMapper; +import jakarta.transaction.Transactional; +import kr.ajousw.myspringweb.dto.FavoriteMusicRequestDto; import kr.ajousw.myspringweb.dto.MusicList; import kr.ajousw.myspringweb.entity.FavoriteMusic; import kr.ajousw.myspringweb.repository.FavoriteRepository; @@ -69,4 +73,16 @@ 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; + } + } + } diff --git a/src/main/java/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.java b/src/main/java/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.java new file mode 100644 index 0000000000000000000000000000000000000000..565c52d9b4df408833f3a2370087e1ff169b54f6 --- /dev/null +++ b/src/main/java/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.java @@ -0,0 +1,34 @@ +package kr.ajousw.myspringweb.dto; + +import kr.ajousw.myspringweb.entity.FavoriteMusic; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString + +public class FavoriteMusicRequestDto { + private String collectionId; + private String collectionType; + private String artistId; + private String artistName; + private String artistViewUrl; + private String collectionName; + private String collectionViewUrl; + + 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.setCollectionName(this.collectionName); + music.setCollectionViewUrl(this.collectionViewUrl); + + return music; + } + +} diff --git a/src/main/java/kr/ajousw/myspringweb/entity/FavoriteMusic.java b/src/main/java/kr/ajousw/myspringweb/entity/FavoriteMusic.java index ea99a88ae4eea5d905b3785a51f3bedf98153be3..3d239948de534eab2feb43321efc0ce58118578b 100644 --- a/src/main/java/kr/ajousw/myspringweb/entity/FavoriteMusic.java +++ b/src/main/java/kr/ajousw/myspringweb/entity/FavoriteMusic.java @@ -9,19 +9,27 @@ import lombok.Setter; import lombok.ToString; @Entity -@Table(name="favoriteMusic") +@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; + @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/target/classes/kr/ajousw/myspringweb/controller/MyWebController.class b/target/classes/kr/ajousw/myspringweb/controller/MyWebController.class index 5d95d9ca108c211410e86759565c45809ab1952b..e3d46829fac59f27c95f09dfe65d1fa5635e88dd 100644 Binary files a/target/classes/kr/ajousw/myspringweb/controller/MyWebController.class and b/target/classes/kr/ajousw/myspringweb/controller/MyWebController.class differ diff --git a/target/classes/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.class b/target/classes/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.class new file mode 100644 index 0000000000000000000000000000000000000000..2ede3d4e8f67c7df709f4599f8c12b6ea7411685 Binary files /dev/null and b/target/classes/kr/ajousw/myspringweb/dto/FavoriteMusicRequestDto.class differ