53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Application\Controller\Calendar;
|
|
|
|
use App\Infrastructure\Repository\EventRepository;
|
|
use App\Application\DTO\CalendarDTO;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use OpenApi\Attributes as OA;
|
|
use Nelmio\ApiDocBundle\Attribute\Model;
|
|
|
|
|
|
#[Route('/api/calendar', name: 'api_calendar_')]
|
|
class CalendarController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly EventRepository $eventRepository
|
|
) {
|
|
}
|
|
|
|
#[Route('', name: 'get', methods: ['GET'])]
|
|
#[OA\Tag(name: 'Calendar')]
|
|
#[OA\Response(
|
|
response: 200,
|
|
description: 'Returns calendar data with events',
|
|
content: new OA\JsonContent(
|
|
ref: new Model(type: CalendarDTO::class)
|
|
)
|
|
)]
|
|
public function getCalendar(Request $request): JsonResponse
|
|
{
|
|
$start = $request->query->get('start');
|
|
$end = $request->query->get('end');
|
|
|
|
if (!$start || !$end) {
|
|
// Default to current month if not specified
|
|
$now = new \DateTimeImmutable();
|
|
$start = $now->modify('first day of this month')->setTime(0, 0);
|
|
$end = $now->modify('last day of this month')->setTime(23, 59, 59);
|
|
} else {
|
|
$start = new \DateTimeImmutable($start);
|
|
$end = new \DateTimeImmutable($end);
|
|
}
|
|
|
|
$events = $this->eventRepository->findByDateRange($start, $end);
|
|
|
|
return $this->json([
|
|
'events' => $events,
|
|
]);
|
|
}
|
|
}
|