Skip to content

Commit

Permalink
added up next route
Browse files Browse the repository at this point in the history
  • Loading branch information
KurzGedanke committed May 25, 2024
1 parent 25be6cc commit cb89909
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Command/SendBandReminderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$dateNow = date('Y-m-d H:i:00', time());
$dateLater = date('Y-m-d H:i:00', (time() + 5 * 60 ));

$timeSlots = $this->timeSlotRepository->findNextTimeSlots($dateNow, $dateLater);
$timeSlots = $this->timeSlotRepository->findNextTimeSlotsBasedOn5Minutes($dateNow, $dateLater);

foreach ($timeSlots as $timeSlot) {
$io->comment($timeSlot->getBand()->getName());
Expand Down
24 changes: 24 additions & 0 deletions src/Controller/API/FestivalApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,28 @@ public function listFestivalStagesTimeSlots(FestivalRepository $festivalReposito

return JsonResponse::fromJsonString($serializer->serializeCircularReferenceJson($timeSlotArray));
}

#[Route('/api/festivals/{festival}/stages/{stageName}/upnext', name: 'festival-stages-upnext')]
public function listFestivalStagesUpNext(FestivalRepository $festivalRepository, StageRepository $stageRepository, TimeSlotRepository $timeSlotRepository, string $festival, string $stageName): JsonResponse
{
$serializer = new SerializerService();
// $festivals = $festivalRepository->findOneBy(['name' => $festival]);

date_default_timezone_set('Europe/Berlin');

$dateNow = date('Y-m-d H:i:00', time());

// $stage = $stageRepository->findBy(['name' => $stageName, 'festival' => $festivals]);
$timeSlot = $timeSlotRepository->findNextTimeSlots($dateNow);

$upNext = [];

$upNext[] = [
'startTime' => $timeSlot->getStartTime()->format('H:i:s d.m.Y '),
'band' => $timeSlot->getBand()->getName(),
'stage' => $timeSlot->getStage()->getName(),
];

return JsonResponse::fromJsonString($serializer->serializeCircularReferenceJson($upNext));
}
}
15 changes: 14 additions & 1 deletion src/Repository/TimeSlotRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Repository;

use App\Entity\Stage;
use App\Entity\TimeSlot;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Validator\Constraints\Time;

/**
* @extends ServiceEntityRepository<TimeSlot>
Expand Down Expand Up @@ -46,7 +48,7 @@ public function __construct(ManagerRegistry $registry)
// ;
// }

public function findNextTimeSlots(string $dateNow, string $dateLater): array
public function findNextTimeSlotsBasedOn5Minutes(string $dateNow, string $dateLater): array
{
return $this->createQueryBuilder('t')
->andWhere('t.startTime > :dateNow')
Expand All @@ -57,4 +59,15 @@ public function findNextTimeSlots(string $dateNow, string $dateLater): array
->getQuery()
->getResult();
}

public function findNextTimeSlots(string $dateNow): TimeSlot
{
return $this->createQueryBuilder('t')
->andWhere('t.startTime > :dateNow')
->setParameter('dateNow', $dateNow)
->orderBy('t.startTime', 'ASC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}
}

0 comments on commit cb89909

Please sign in to comment.