Add endpoint and delete user test

This commit is contained in:
theanonymousexyz 2022-04-21 21:59:44 +02:00
parent 640f59d0c9
commit 369a8907af
No known key found for this signature in database
GPG key ID: 35EE09F5481049BB
3 changed files with 22 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import io.activej.inject.module.Module;
import io.activej.launchers.http.MultithreadedHttpServerLauncher; import io.activej.launchers.http.MultithreadedHttpServerLauncher;
import me.kavin.piped.consts.Constants; import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.*; 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.ErrorResponse;
import me.kavin.piped.utils.resp.LoginRequest; import me.kavin.piped.utils.resp.LoginRequest;
import me.kavin.piped.utils.resp.SubscriptionUpdateRequest; import me.kavin.piped.utils.resp.SubscriptionUpdateRequest;
@ -327,6 +328,15 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
} catch (Exception e) { } catch (Exception e) {
return getErrorResponse(e, request.getPath()); 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); return new CustomServletDecorator(router);

View file

@ -0,0 +1,7 @@
package me.kavin.piped.utils.resp;
public class DeleteUserRequest {
public String password;
}

View file

@ -107,3 +107,8 @@ curl ${CURLOPTS[@]} $HOST/user/playlists/remove -X POST -H "Content-Type: applic
# Delete Playlist Test # 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 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