diff --git a/src/Controller/GuiController.php b/src/Controller/GuiController.php index 418e071..daa4f1e 100644 --- a/src/Controller/GuiController.php +++ b/src/Controller/GuiController.php @@ -11,11 +11,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use function Symfony\Component\HttpFoundation\Response; class GuiController extends AbstractController { #[Route('/')] #[Template('/index.html.twig')] - public function index(): Array { + public function index(): array { return [ 'title' => 'Joe Carstairs', 'description' => 'Joe Carstairs\' personal website', @@ -24,27 +25,15 @@ class GuiController extends AbstractController { #[Route('/notes', name: 'notes')] #[Template('/notes.html.twig')] - public function notes(): Array { - return [ - 'title' => 'Joe Carstairs\' notes', - 'description' => 'Joe Carstairs\' notes', - ]; - } - - #[Route('/note/{slug}', name: 'note')] - #[Template('/note.html.twig')] - public function note( + public function notes( EntityManagerInterface $entityManager, - string $slug, ): array { - $repository = $entityManager->getRepository(Note::class); - $note = $repository->findOneBy(['slug' => $slug]); + $notes = $entityManager->getRepository(Note::class)->findAll(); return [ 'title' => 'Joe Carstairs\' notes', 'description' => 'Joe Carstairs\' notes', - 'note' => $note, - 'slug' => $slug, + 'notes' => $notes, ]; } @@ -84,4 +73,24 @@ class GuiController extends AbstractController { 'form' => $form, ]); } + + /** + * @return array + */ + #[Route('/notes/{slug}', name: 'note')] + #[Template('/note.html.twig')] + public function note( + EntityManagerInterface $entityManager, + string $slug, + ): array { + $repository = $entityManager->getRepository(Note::class); + $note = $repository->findOneBy(['slug' => $slug]); + + return [ + 'title' => 'Joe Carstairs\' notes', + 'description' => 'Joe Carstairs\' notes', + 'note' => $note, + 'slug' => $slug, + ]; + } } diff --git a/src/Repository/NoteRepository.php b/src/Repository/NoteRepository.php index 2829bdf..72d0ead 100644 --- a/src/Repository/NoteRepository.php +++ b/src/Repository/NoteRepository.php @@ -19,20 +19,15 @@ class NoteRepository extends ServiceEntityRepository } public function countWherePublishedOnDate(DateTime $date): int { - $min = new DateTime($date->format('c')); - $min->setTime(0, 0, 0, 0); - $max = new DateTime($min->format('c')); - $max->add(DateInterval::createFromDateString('1 day')); + $dateStr = substr($date->format('c'), 0, 10); $wherePublishedOnDate = $this->createQueryBuilder('n') - ->andWhere('n.publishedDate >= :min') - ->andWhere('n.publishedDate < :max') - ->setParameter('min', $min) - ->setParameter('max', $max) + ->andWhere('n.publishedDate = :date') + ->setParameter('date', $dateStr) ->getQuery() ->execute(); - return count($wherePublishedOnDate); + return count($wherePublishedOnDate); } // /** diff --git a/templates/notes.html.twig b/templates/notes.html.twig index fe65f80..971b0d2 100644 --- a/templates/notes.html.twig +++ b/templates/notes.html.twig @@ -3,5 +3,12 @@ {% block content %}

Notes

+ + {% for note in notes %} +

Note {{ note.slug }}

+

{{ note.content }}

+ {% else %} +

I have no notes.

+ {% endfor %}
{% endblock %}