Skip to content
Snippets Groups Projects
Commit d93da0ce authored by HyunjinNoh's avatar HyunjinNoh
Browse files

post_likes

parent 81ae0aac
No related branches found
No related tags found
No related merge requests found
Pipeline #8315 canceled
......@@ -4,13 +4,17 @@ import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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.RestController;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import kr.ajousw.myspringweb.dto.FavoriteMusicRequestDto;
import kr.ajousw.myspringweb.dto.MusicList;
import kr.ajousw.myspringweb.entity.FavoriteMusic;
import kr.ajousw.myspringweb.repository.FavoriteRepository;
......@@ -48,4 +52,16 @@ public class MyWebController {
return null;
}
}
@PostMapping(value="/likes")
@Transactional
public int postLikes(@RequestBody FavoriteMusicRequestDto favorite) {
FavoriteMusic music = albumsRepo.save(favorite.toEntity());
if(music != null) {
return 1;
}
else {
return 0;
}
}
}
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;
}
}
{
"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"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment