Accounts: Add edit and delete pages; implement forms (no real actions yet)

This commit is contained in:
Lexi / Zoe 2021-07-31 00:34:35 +02:00
parent 4e8d879008
commit 7859ef77ee
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
9 changed files with 258 additions and 23 deletions

View file

@ -70,4 +70,58 @@ class AccountController extends BaseController
return $this->view->render($response, 'account_details.html.twig', $renderData);
}
public function showAccountCreate(Request $request, Response $response): Response
{
return $this->showAccounts($request, $response);
}
public function showAccountEdit(Request $request, Response $response, array $args): Response
{
// Parse URL arguments
$accountId = (int)$args['id'];
// Get account data from database
$accountData = $this->accountRepository->fetchAccountById($accountId);
$renderData = [
'id' => $accountId,
'accountUsername' => $accountData['username'],
'accountData' => $accountData,
];
return $this->view->render($response, 'account_edit.html.twig', $renderData);
}
public function editAccount(Request $request, Response $response, array $args): Response
{
// TODO: just a placeholder
$this->view->getEnvironment()->addGlobal('error', 'Not implemented yet!');
return $this->showAccountEdit($request, $response, $args);
}
public function showAccountDelete(Request $request, Response $response, array $args): Response
{
// Parse URL arguments
$accountId = (int)$args['id'];
// Get account data and list of aliases from database
$accountData = $this->accountRepository->fetchAccountById($accountId);
$aliases = $this->aliasRepository->fetchAliasesForUserId($accountId);
$renderData = [
'id' => $accountId,
'accountUsername' => $accountData['username'],
'aliases' => $aliases,
];
return $this->view->render($response, 'account_delete.html.twig', $renderData);
}
public function deleteAccount(Request $request, Response $response, array $args): Response
{
// TODO: just a placeholder
$this->view->getEnvironment()->addGlobal('error', 'Not implemented yet!');
return $this->showAccountDelete($request, $response, $args);
}
}

View file

@ -26,8 +26,11 @@ class Routes
// Accounts
$app->get('/accounts', AccountController::class . ':showAccounts');
$app->get('/accounts/new', AccountController::class . ':showAccountCreate');
$app->get('/accounts/{id:[1-9][0-9]*}', AccountController::class . ':showAccountDetails');
$app->get('/accounts/{id:[1-9][0-9]*}/edit', AccountController::class . ':showAccountDetails');
$app->get('/accounts/{id:[1-9][0-9]*}/delete', AccountController::class . ':showAccountDetails');
$app->get('/accounts/{id:[1-9][0-9]*}/edit', AccountController::class . ':showAccountEdit');
$app->post('/accounts/{id:[1-9][0-9]*}/edit', AccountController::class . ':editAccount');
$app->get('/accounts/{id:[1-9][0-9]*}/delete', AccountController::class . ':showAccountDelete');
$app->post('/accounts/{id:[1-9][0-9]*}/delete', AccountController::class . ':deleteAccount');
}
}