|
|
@@ -0,0 +1,43 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Controller;
|
|
|
+
|
|
|
+use App\Entity\User;
|
|
|
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
+use Symfony\Component\Routing\Annotation\Route;
|
|
|
+
|
|
|
+class ProfileManagerController extends AbstractController
|
|
|
+{
|
|
|
+ #[Route('/profile/{username}/follow', name: 'follow')]
|
|
|
+ public function follow($username): Response
|
|
|
+ {
|
|
|
+ $session = $this->get('session');
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $repository_profile = $em->getRepository(User::class);
|
|
|
+ $profile = $repository_profile->findOneBy(array('username' => $session->get('user')));
|
|
|
+ $followuser = $repository_profile->findOneBy(array('username' => $username));
|
|
|
+ $profile->addSubscription($followuser);
|
|
|
+ $followuser->addFollower($profile);
|
|
|
+ $em->persist($profile);
|
|
|
+ $em->persist($followuser);
|
|
|
+ $em->flush();
|
|
|
+ return $this->redirectToRoute('profile', ['username' => $username]);
|
|
|
+ }
|
|
|
+
|
|
|
+ #[Route('/profile/{username}/unfollow', name: 'unfollow')]
|
|
|
+ public function unfollow($username): Response
|
|
|
+ {
|
|
|
+ $session = $this->get('session');
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
+ $repository_profile = $em->getRepository(User::class);
|
|
|
+ $profile = $repository_profile->findOneBy(array('username' => $session->get('user')));
|
|
|
+ $followuser = $repository_profile->findOneBy(array('username' => $username));
|
|
|
+ $profile->removeSubscription($followuser);
|
|
|
+ $followuser->removeFollower($profile);
|
|
|
+ $em->persist($profile);
|
|
|
+ $em->persist($followuser);
|
|
|
+ $em->flush();
|
|
|
+ return $this->redirectToRoute('profile', ['username' => $username]);
|
|
|
+ }
|
|
|
+}
|