WatchList::class, '_api_operation_name' => 'create', ], methods: ['POST'] )] public function createWatchList(Request $request): WatchList { $watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']); /** @var User $user */ $user = $this->getUser(); $watchList->setUser($user); $this->em->persist($watchList); $this->em->flush(); return $watchList; } /** * @throws ParseException * @throws EofException * @throws InvalidDataException * @throws \Exception */ #[Route( path: '/api/watchlists/{token}/calendar', name: 'watchlist_calendar', defaults: [ '_api_resource_class' => WatchList::class, '_api_operation_name' => 'calendar', ] )] public function getWatchlistCalendar(string $token): Response { /** @var WatchList $watchList */ $watchList = $this->watchListRepository->findOneBy(['token' => $token]); $calendar = new Calendar(); /** @var Domain $domain */ foreach ($watchList->getDomains()->getIterator() as $domain) { $attendees = []; /** @var DomainEntity $entity */ foreach ($domain->getDomainEntities()->toArray() as $entity) { $vCard = Reader::readJson($entity->getEntity()->getJCard()); if (isset($vCard->EMAIL) && isset($vCard->FN)) { $email = (string) $vCard->EMAIL; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { continue; } $attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string) $vCard->FN); } } /** @var DomainEvent $event */ foreach ($domain->getEvents()->toArray() as $event) { $calendar->addEvent((new Event()) ->setLastModified(new Timestamp($domain->getUpdatedAt())) ->setStatus(EventStatus::CONFIRMED()) ->setSummary($domain->getLdhName().' ('.$event->getAction().')') ->addCategory(new Category($event->getAction())) ->setAttendees($attendees) ->setOccurrence(new SingleDay(new Date($event->getDate()))) ); } } $calendarResponse = (new CalendarFactory())->createCalendar($calendar); $calendarName = $watchList->getName(); if (null !== $calendarName) { $calendarResponse->withProperty(new Property('X-WR-CALNAME', new TextValue($calendarName))); } return new Response($calendarResponse, Response::HTTP_OK, [ 'Content-Type' => 'text/calendar; charset=utf-8', ]); } #[Route( path: '/api/watchlists', name: 'watchlist_get_all_mine', defaults: [ '_api_resource_class' => WatchList::class, '_api_operation_name' => 'get_all_mine', ], methods: ['GET'] )] public function getWatchLists(): Collection { /** @var User $user */ $user = $this->getUser(); return $user->getWatchLists(); } }