From 9f4ce2fc4e3a062a3e7950b917c990ecb9e21881 Mon Sep 17 00:00:00 2001 From: Tim <47184194+imgde@users.noreply.github.com> Date: Sun, 22 Jun 2025 14:22:30 +0200 Subject: [PATCH] Fix Account Deletion --- .../de/htwsaar/webshop/controller/AccountController.java | 2 +- 01-frontend/src/components/Account.tsx | 2 +- 01-frontend/src/helper/adminpanel/AccountsInfo.tsx | 8 +++++--- 01-frontend/src/helper/query/Queries.tsx | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/00-backend/src/main/java/de/htwsaar/webshop/controller/AccountController.java b/00-backend/src/main/java/de/htwsaar/webshop/controller/AccountController.java index 09e90ce..38a0e46 100644 --- a/00-backend/src/main/java/de/htwsaar/webshop/controller/AccountController.java +++ b/00-backend/src/main/java/de/htwsaar/webshop/controller/AccountController.java @@ -96,7 +96,7 @@ public class AccountController { @RequestMapping(path = ACCOUNT_ADMIN, method = RequestMethod.DELETE, produces = "application/json") public ResponseEntity deleteAccount(HttpServletRequest request, @RequestParam(PARAM_EMAIL) String email, - @RequestParam(PARAM_PASSWORD) UUID token, + @RequestParam(PARAM_UUID) UUID token, @RequestParam(PARAM_ID) Long accountId) { logRequest(request); if (!sessionService.isAdmin(token, email)) { diff --git a/01-frontend/src/components/Account.tsx b/01-frontend/src/components/Account.tsx index 6484640..dc81756 100644 --- a/01-frontend/src/components/Account.tsx +++ b/01-frontend/src/components/Account.tsx @@ -38,7 +38,7 @@ export type SubmitLoginSession = { export type AdminAccountOperation = { email: string; - session: string; + uuid: string; accountId: number; } diff --git a/01-frontend/src/helper/adminpanel/AccountsInfo.tsx b/01-frontend/src/helper/adminpanel/AccountsInfo.tsx index 0004d2c..19a201b 100644 --- a/01-frontend/src/helper/adminpanel/AccountsInfo.tsx +++ b/01-frontend/src/helper/adminpanel/AccountsInfo.tsx @@ -62,11 +62,13 @@ export default function AccountsInfo() { }; const handleDeleteSelected = async () => { - selectedRows.forEach(async (row) => { + selectedRows.forEach(async (rowId) => { + let id = rows.find((row) => row.id === rowId)?.id + if(id === undefined) id = -1; await deleteAccount.mutateAsync({ email: loginData?.email || '', - session: loginData?.session || '', - accountId: row.id as number + uuid: loginData?.session || '', + accountId: id, }); }) diff --git a/01-frontend/src/helper/query/Queries.tsx b/01-frontend/src/helper/query/Queries.tsx index 5099f58..7915dd2 100644 --- a/01-frontend/src/helper/query/Queries.tsx +++ b/01-frontend/src/helper/query/Queries.tsx @@ -152,8 +152,8 @@ export const deleteAccount = async (user: User) => { return await response.json(); }; -export const deleteAccountAdmin = async (user: AdminAccountOperation) => { - const response = await fetch('http://localhost:8085/account/admin?email=' + user.email + '&session=' + user.session + '&accountId=' + user.accountId, { +export const deleteAccountAdmin = async (operation: AdminAccountOperation) => { + const response = await fetch('http://localhost:8085/account/admin?email=' + operation.email + '&uuid=' + operation.uuid + '&id=' + operation.accountId, { method: 'DELETE', }); if (!response.ok) {