Add ability to remove feeds
This commit is contained in:
parent
5c8892e12f
commit
cee4f9944e
@ -54,4 +54,16 @@ class FeedController
|
|||||||
|
|
||||||
return $this->view->render($response, 'create.twig.html');
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ class LoginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
|
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 {
|
public function login(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
|
||||||
@ -27,7 +27,7 @@ class LoginController {
|
|||||||
$user = $this->users->validateCredentials($email, $password);
|
$user = $this->users->validateCredentials($email, $password);
|
||||||
|
|
||||||
if (!$user) {
|
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;
|
$_SESSION['user'] = $user->id;
|
||||||
|
@ -21,4 +21,10 @@ class FeedRepository extends EntityRepository
|
|||||||
$this->_em->persist($feed);
|
$this->_em->persist($feed);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(Feed $feed): void
|
||||||
|
{
|
||||||
|
$this->_em->remove($feed);
|
||||||
|
$this->_em->flush();
|
||||||
|
}
|
||||||
}
|
}
|
@ -24,10 +24,11 @@ $app->add('csrf');
|
|||||||
|
|
||||||
$app->get("/", [HomeController::class, 'get']);
|
$app->get("/", [HomeController::class, 'get']);
|
||||||
|
|
||||||
$app->get('/feed', [FeedController::class, 'get'])
|
$app->group('/feed', function (\Slim\Routing\RouteCollectorProxy $group) use ($app) {
|
||||||
->add($container->get(\Lewisdale\App\Session\LoginMiddleware::class));
|
$group->get('[/]', [FeedController::class, 'get'])->add(\Lewisdale\App\Session\LoginMiddleware::class);
|
||||||
|
$group->get('/{id}', [FeedController::class, 'get_feed']);
|
||||||
$app->get('/feed/{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) {
|
$app->group('/account', function (\Slim\Routing\RouteCollectorProxy $group) use ($app, $container) {
|
||||||
$group->get('/login', [LoginController::class, 'index']);
|
$group->get('/login', [LoginController::class, 'index']);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
{% for feed in feeds %}
|
{% for feed in feeds %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ feed.title }}</td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
Reference in New Issue
Block a user