Merge remote-tracking branch 'origin' into controllers

pull/21/head
remrem 10 months ago
commit 7039eeda76

@ -81,9 +81,11 @@ class PostController extends AbstractController
public function removePost(int $id): Response public function removePost(int $id): Response
{ {
$post = $this->em->getRepository(Post::class)->find($id); $post = $this->em->getRepository(Post::class)->find($id);
$this->em->remove($post); if($post->getProfil()->getId() === $this->getUser()->getId())
$this->em->flush(); {
$this->em->remove($post);
$this->em->flush();
}
return new Response(); return new Response();
} }
} }

@ -66,6 +66,12 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/unfollow', name: 'profil_unfollow', requirements: ['page' => '\d+'])] #[Route('/profil/{id}/unfollow', name: 'profil_unfollow', requirements: ['page' => '\d+'])]
public function unfollowProfil(int $id): Response public function unfollowProfil(int $id): Response
{ {
try{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) { if ($profil instanceof Profil) {
$profil->removeFollower($this->getUser()); $profil->removeFollower($this->getUser());
@ -101,14 +107,6 @@ class ProfilController extends AbstractController
]); ]);
} }
// #[Route('/profil/new', name: 'profil_new')]
// public function new(): Response
// {
// $profil = new Profil();
// return $this->redirectToRoute('profil_show', ['id' => $profil->getId()]);
// }
#[Route('/profil/{id}/edit', name: 'profil_edit', requirements: ['page' => '\d'])] #[Route('/profil/{id}/edit', name: 'profil_edit', requirements: ['page' => '\d'])]
public function editProfil(int $id, Request $request): Response public function editProfil(int $id, Request $request): Response
{ {
@ -134,12 +132,20 @@ class ProfilController extends AbstractController
#[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])] #[Route('/profil/{id}/follow', name: 'profil_follow', requirements: ['page' => '\d+'])]
public function followProfil(int $id): Response public function followProfil(int $id): Response
{ {
try{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED');
}catch (\Exception $e){
return $this->redirectToRoute('app_login');
}
$profil = $this->mgr->find(Profil::class, $id); $profil = $this->mgr->find(Profil::class, $id);
if ($profil instanceof Profil) { if ($profil instanceof Profil) {
$profil->addFollower($this->getUser()); if ($profil->getId() !== $this->getUser()->getId()) {
$this->mgr->persist($profil); $profil->addFollower($this->getUser());
$this->mgr->flush(); $this->mgr->persist($profil);
$this->addFlash('success', ''); $this->mgr->flush();
$this->addFlash('success', '');
}
return $this->redirectToRoute('profil_show', ['id' => $id]); return $this->redirectToRoute('profil_show', ['id' => $id]);
} else { } else {
$this->addFlash('error', ''); $this->addFlash('error', '');

Loading…
Cancel
Save