diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 6a8dd24..55c4395 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -965,9 +965,12 @@ public class ResponseHelper { s.save(playlist); s.getTransaction().begin(); s.getTransaction().commit(); - } - return Constants.mapper.writeValueAsBytes(new AcceptedResponse()); + ObjectNode response = Constants.mapper.createObjectNode(); + response.put("playlistId", String.valueOf(playlist.getPlaylistId())); + + return Constants.mapper.writeValueAsBytes(response); + } } public static byte[] playlistsResponse(String session) throws IOException { diff --git a/src/main/java/me/kavin/piped/utils/obj/db/Playlist.java b/src/main/java/me/kavin/piped/utils/obj/db/Playlist.java index bbcd4ca..3948c19 100644 --- a/src/main/java/me/kavin/piped/utils/obj/db/Playlist.java +++ b/src/main/java/me/kavin/piped/utils/obj/db/Playlist.java @@ -38,7 +38,8 @@ public class Playlist { @Column(name = "thumbnail", length = 300) private String thumbnail; - @Column(name = "owner", nullable = false) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "owner") private User owner; @ElementCollection(fetch = FetchType.LAZY) diff --git a/testing/api-test.sh b/testing/api-test.sh index 045bf11..155c3c8 100755 --- a/testing/api-test.sh +++ b/testing/api-test.sh @@ -84,3 +84,17 @@ sleep 2 # Check Feed curl ${CURLOPTS[@]} $HOST/feed -G --data-urlencode "authToken=$AUTH_TOKEN" || exit 1 + +PLAYLIST_NAME=$(openssl rand -hex 6) + +# Create a Playlist +curl ${CURLOPTS[@]} $HOST/user/playlists/create -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg name "$PLAYLIST_NAME" '{"name": $name}') || exit 1 + +# See created playlists +curl ${CURLOPTS[@]} $HOST/user/playlists -H "Authorization: $AUTH_TOKEN" || exit 1 + +# Get Playlist ID +PLAYLIST_ID=$(curl -s -o - -f $HOST/user/playlists -H "Authorization: $AUTH_TOKEN" | jq -r ".[0].id") || exit 1 + +# Playlist Test +curl ${CURLOPTS[@]} $HOST/playlists/$PLAYLIST_ID || exit 1