diff --git a/src/Controller/CalendarController.php b/src/Controller/CalendarController.php index 8b57df91559a93f389e2a371c4871cd9eabafda1..2808935ebc57946c168998009fa6c89751658f99 100644 --- a/src/Controller/CalendarController.php +++ b/src/Controller/CalendarController.php @@ -2,7 +2,13 @@ namespace App\Controller; +use App\Entity\User; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -15,4 +21,37 @@ class CalendarController extends AbstractController 'controller_name' => 'CalendarController', ]); } + + #[Route('/calendar/receive', name: 'calendar_receive')] + #[IsGranted('ROLE_USER')] + public function calendarReceive() + { + $user = $this->getUser(); + if (!$user || !$user instanceof User) + { + throw new \LogicException("The calendar could not be sent because there are no existing user."); + } + + $calendar = $user->getCalendarFile(); + + return new JsonResponse($calendar); + } + + #[Route('/calendar/send', name: 'calendar_send')] + #[IsGranted('ROLE_USER')] + public function calendarSend(Request $request, EntityManagerInterface $manager) + { + $json = $request->getContent(); + $calendar = json_decode($json, true); + + /** @var User */ + $user = $this->getUser(); + if (!$user || !$user instanceof User) + { + throw new \LogicException("The calendar could not be sent because there are no existing user."); + } + + $user->setCalendarFile($calendar); + $manager->flush(); + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 5936034773d99160f263d90bfe6175900c4e54db..84635275cfa0ed95a2c2ce33c41ff50a3a94b6e1 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -28,6 +28,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: 'string', length: 255)] private $displayName; + #[ORM\Column(type: 'json', nullable: true)] + private $CalendarFile = []; + public function getId(): ?int { return $this->id; @@ -109,4 +112,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function getCalendarFile(): ?array + { + return $this->CalendarFile; + } + + public function setCalendarFile(?array $CalendarFile): self + { + $this->CalendarFile = $CalendarFile; + + return $this; + } }