wip: synchro

This commit is contained in:
2022-05-07 02:22:28 +02:00
parent 9935af0497
commit 811798e23f
14 changed files with 315 additions and 43 deletions

View File

@@ -45,7 +45,7 @@ class RemoteCalendarConnectAzureController
return $this->clientRegistry
->getClient('azure') // key used in config/packages/knpu_oauth2_client.yaml
->redirect([
'User.Read', 'Calendars.Read', 'Calendars.Read.Shared',
'https://graph.microsoft.com/.default'
]);
}

View File

@@ -11,11 +11,16 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\Controller;
use Chill\CalendarBundle\Synchro\Connector\MSGraph\RemoteEventConverter;
use Chill\CalendarBundle\Synchro\Connector\RemoteCalendarConnectorInterface;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/**
* Contains method to get events (Calendar) from remote calendar.
@@ -24,18 +29,45 @@ class RemoteCalendarProxyController
{
private RemoteCalendarConnectorInterface $remoteCalendarConnector;
private SerializerInterface $serializer;
public function __construct(RemoteCalendarConnectorInterface $remoteCalendarConnector, SerializerInterface $serializer)
{
$this->remoteCalendarConnector = $remoteCalendarConnector;
$this->serializer = $serializer;
}
/**
* @Route("api/1.0/calendar/proxy/calendar/by-user/{id}/events")
*/
public function listEventForCalendar(User $user, Request $request): Response
{
if ($request->query->has('startDate')) {
$startDate = DateTimeImmutable::createFromFormat('Y-m-dTHis', $request->query->get('startDate') . '000000');
$startDate = DateTimeImmutable::createFromFormat('Y-m-d', $request->query->get('startDate'));
if (false === $startDate) {
throw new BadRequestHttpException("startDate on bad format");
}
} else {
throw new BadRequestHttpException('startDate not provided');
}
if ($request->query->has('endDate')) {
$startDate = DateTimeImmutable::createFromFormat('Y-m-dTHis', $request->query->get('endDate') . '000000');
$endDate = DateTimeImmutable::createFromFormat('Y-m-d', $request->query->get('endDate'));
if (false === $endDate) {
throw new BadRequestHttpException("endDate on bad format");
}
} else {
throw new BadRequestHttpException('endDate not provided');
}
$events = $this->remoteCalendarConnector->listEventsForUser($user, $startDate, $endDate);
return new JsonResponse(
$this->serializer->serialize($events, 'json', ['groups' => ['read']]),
JsonResponse::HTTP_OK,
[],
true
);
}
}