Add ability to remove feeds

This commit is contained in:
Lewis Dale 2024-12-31 16:32:00 +00:00
parent 5c8892e12f
commit cee4f9944e
6 changed files with 26 additions and 7 deletions

View File

@ -54,4 +54,16 @@ class FeedController
return $this->view->render($response, 'create.twig.html');
}
public function delete(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$this->logger->info("FeedController::delete() called");
$feed = $this->feedRepository->find($request->getAttribute('id'));
if (empty($feed)) {
return $response->withStatus(404);
}
$this->feedRepository->delete($feed);
return $response->withStatus(201)->withHeader('Location', '/feed');
}
}

View File

@ -16,7 +16,7 @@ class LoginController {
}
public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
return $this->view->render($response, 'login/index.twig.html', []);
return $this->view->render($response, 'account/login.twig.html', []);
}
public function login(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
@ -27,7 +27,7 @@ class LoginController {
$user = $this->users->validateCredentials($email, $password);
if (!$user) {
return $this->view->render($response, 'login/index.twig.html', ['error' => 'Invalid email or password']);
return $this->view->render($response, 'account/login.twig.html', ['error' => 'Invalid email or password']);
}
$_SESSION['user'] = $user->id;

View File

@ -21,4 +21,10 @@ class FeedRepository extends EntityRepository
$this->_em->persist($feed);
$this->_em->flush();
}
public function delete(Feed $feed): void
{
$this->_em->remove($feed);
$this->_em->flush();
}
}

View File

@ -24,10 +24,11 @@ $app->add('csrf');
$app->get("/", [HomeController::class, 'get']);
$app->get('/feed', [FeedController::class, 'get'])
->add($container->get(\Lewisdale\App\Session\LoginMiddleware::class));
$app->get('/feed/{id}', [FeedController::class, 'get_feed']);
$app->group('/feed', function (\Slim\Routing\RouteCollectorProxy $group) use ($app) {
$group->get('[/]', [FeedController::class, 'get'])->add(\Lewisdale\App\Session\LoginMiddleware::class);
$group->get('/{id}', [FeedController::class, 'get_feed']);
$group->get('/{id}/delete', [FeedController::class, 'delete'])->add(\Lewisdale\App\Session\LoginMiddleware::class);
});
$app->group('/account', function (\Slim\Routing\RouteCollectorProxy $group) use ($app, $container) {
$group->get('/login', [LoginController::class, 'index']);

View File

@ -9,7 +9,7 @@
{% for feed in feeds %}
<tr>
<td>{{ feed.title }}</td>
<td><a href="/feed/{{ feed.id }}">Link to feed</a></td>
<td><a href="/feed/{{ feed.id }}">Link to feed</a><a href="/feed/{{ feed.id }}/delete">Delete</a></td>
</tr>
{% endfor %}
</tbody>