From 369a8907af19beb1e51da4a38011120daf93852e Mon Sep 17 00:00:00 2001 From: theanonymousexyz Date: Thu, 21 Apr 2022 21:59:44 +0200 Subject: [PATCH] Add endpoint and delete user test --- src/main/java/me/kavin/piped/ServerLauncher.java | 10 ++++++++++ .../me/kavin/piped/utils/resp/DeleteUserRequest.java | 7 +++++++ testing/api-test.sh | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 src/main/java/me/kavin/piped/utils/resp/DeleteUserRequest.java diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index 21732ec..1ad93ac 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -14,6 +14,7 @@ import io.activej.inject.module.Module; import io.activej.launchers.http.MultithreadedHttpServerLauncher; import me.kavin.piped.consts.Constants; import me.kavin.piped.utils.*; +import me.kavin.piped.utils.resp.DeleteUserRequest; import me.kavin.piped.utils.resp.ErrorResponse; import me.kavin.piped.utils.resp.LoginRequest; import me.kavin.piped.utils.resp.SubscriptionUpdateRequest; @@ -327,6 +328,15 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } catch (Exception e) { return getErrorResponse(e, request.getPath()); } + })).map(POST, "/user/delete", AsyncServlet.ofBlocking(executor, request -> { + try { + DeleteUserRequest body = Constants.mapper.readValue(request.loadBody().getResult().asArray(), + DeleteUserRequest.class); + return getJsonResponse(ResponseHelper.deleteUserResponse(request.getHeader(AUTHORIZATION), body.password), + "private"); + } catch (Exception e) { + return getErrorResponse(e, request.getPath()); + } })); return new CustomServletDecorator(router); diff --git a/src/main/java/me/kavin/piped/utils/resp/DeleteUserRequest.java b/src/main/java/me/kavin/piped/utils/resp/DeleteUserRequest.java new file mode 100644 index 0000000..f6228e2 --- /dev/null +++ b/src/main/java/me/kavin/piped/utils/resp/DeleteUserRequest.java @@ -0,0 +1,7 @@ +package me.kavin.piped.utils.resp; + +public class DeleteUserRequest { + + public String password; + +} diff --git a/testing/api-test.sh b/testing/api-test.sh index 817d834..127cecd 100755 --- a/testing/api-test.sh +++ b/testing/api-test.sh @@ -107,3 +107,8 @@ curl ${CURLOPTS[@]} $HOST/user/playlists/remove -X POST -H "Content-Type: applic # Delete Playlist Test curl ${CURLOPTS[@]} $HOST/user/playlists/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID '{"playlistId": $playlistId}') || exit 1 + +DELETE_REQ=$(jq -n --compact-output --arg password "$PASS" '{"password": $password}') + +# Delete User Test +curl ${CURLOPTS[@]} $HOST/user/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $DELETE_REQ || exit 1