Skip to content

Commit

Permalink
Merge pull request #1 from KurzGedanke/feature/send-band-start-notifi…
Browse files Browse the repository at this point in the history
…cation

Feature/send band start notification
  • Loading branch information
KurzGedanke authored May 25, 2024
2 parents b675bc9 + cb89909 commit 505c355
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Command/SendBandReminderCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use App\Repository\TimeSlotRepository;

#[AsCommand(
name: 'send:band-reminder',
description: 'Add a short description for your command',
)]
class SendBandReminderCommand extends Command
{
private TimeSlotRepository $timeSlotRepository;

public function __construct(TimeSlotRepository $timeSlotRepository)
{
$this->timeSlotRepository = $timeSlotRepository;
parent::__construct();
}

protected function configure(): void
{
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
date_default_timezone_set('Europe/Berlin');

$dateNow = date('Y-m-d H:i:00', time());
$dateLater = date('Y-m-d H:i:00', (time() + 5 * 60 ));

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

foreach ($timeSlots as $timeSlot) {
$io->comment($timeSlot->getBand()->getName());
}

$io->success($timeSlots);
$io->success($dateNow);
$io->success($dateLater);

return Command::SUCCESS;
}
}
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));
}
}
25 changes: 25 additions & 0 deletions 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 @@ -45,4 +47,27 @@ public function __construct(ManagerRegistry $registry)
// ->getOneOrNullResult()
// ;
// }

public function findNextTimeSlotsBasedOn5Minutes(string $dateNow, string $dateLater): array
{
return $this->createQueryBuilder('t')
->andWhere('t.startTime > :dateNow')
->andWhere('t.startTime < :dateLater')
->setParameter('dateNow', $dateNow)
->setParameter('dateLater', $dateLater)
->orderBy('t.startTime', 'ASC')
->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 505c355

Please sign in to comment.