diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index f48021c..c62ebcd 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -4,19 +4,37 @@ declare(strict_types=1); namespace App\Controller; +use App\Entity\Article; +use App\Service\NostrClient; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class DefaultController extends AbstractController { + public function __construct(private readonly EntityManagerInterface $entityManager, + private readonly NostrClient $nostrClient) + { + } /** - * @Route("/default") + * @throws \Exception */ - #[\Symfony\Component\Routing\Attribute\Route('/', name: 'default')] + #[Route('/', name: 'default')] public function index(): Response { - return $this->render('home.html.twig'); + $list = $this->entityManager->getRepository(Article::class)->findAll(); + $current = array_slice($list, 0,10); + + $npubs = array_map(function($obj) { + return $obj->getPubkey(); + }, $list); + + $this->nostrClient->getMetadata(array_unique($npubs)); + + return $this->render('home.html.twig', [ + 'list' => $current + ]); } } diff --git a/src/Entity/Journal.php b/src/Entity/Journal.php new file mode 100644 index 0000000..7edfd5a --- /dev/null +++ b/src/Entity/Journal.php @@ -0,0 +1,80 @@ +id; + } + + public function getNpub(): ?string + { + return $this->npub; + } + + public function setNpub(string $npub): static + { + $this->npub = $npub; + + return $this; + } + + public function getMainCategories(): array + { + return $this->mainCategories; + } + + public function setMainCategories(array $mainCategories): static + { + $this->mainCategories = $mainCategories; + + return $this; + } + + public function getLists(): ?array + { + return $this->lists; + } + + public function setLists(?array $lists): static + { + $this->lists = $lists; + + return $this; + } + + public function getEditor(): ?string + { + return $this->editor; + } + + public function setEditor(?string $editor): static + { + $this->editor = $editor; + + return $this; + } +} diff --git a/src/Repository/JournalRepository.php b/src/Repository/JournalRepository.php new file mode 100644 index 0000000..f4846f7 --- /dev/null +++ b/src/Repository/JournalRepository.php @@ -0,0 +1,43 @@ + + */ +class JournalRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Journal::class); + } + + // /** + // * @return Journal[] Returns an array of Journal objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('j') + // ->andWhere('j.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('j.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Journal + // { + // return $this->createQueryBuilder('j') + // ->andWhere('j.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Service/NostrClient.php b/src/Service/NostrClient.php index 7e433e0..ca4b825 100644 --- a/src/Service/NostrClient.php +++ b/src/Service/NostrClient.php @@ -39,7 +39,7 @@ class NostrClient $filter = new Filter(); $filter->setKinds([KindsEnum::LONGFORM]); // TODO make filters configurable - $filter->setSince(strtotime('-1 day')); // + $filter->setSince(strtotime('-1 week')); // $requestMessage = new RequestMessage($subscriptionId, [$filter]); // TODO make relays configurable $relays = new RelaySet(); diff --git a/src/Twig/Components/Molecules/Card.php b/src/Twig/Components/Molecules/Card.php index 472f762..41ce453 100644 --- a/src/Twig/Components/Molecules/Card.php +++ b/src/Twig/Components/Molecules/Card.php @@ -8,4 +8,6 @@ use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; final class Card { public string $tag = 'div'; -} \ No newline at end of file + public string $category = ''; + public object $article; +} diff --git a/src/Twig/Components/Molecules/UserFromNpub.php b/src/Twig/Components/Molecules/UserFromNpub.php new file mode 100644 index 0000000..b8981b4 --- /dev/null +++ b/src/Twig/Components/Molecules/UserFromNpub.php @@ -0,0 +1,24 @@ +npub = $npub; + $this->user = $this->entityManager->getRepository(User::class)->findOneBy(['npub' => $npub]); + } +} diff --git a/src/Twig/Components/Organisms/CardList.php b/src/Twig/Components/Organisms/CardList.php index 329245b..8cfd3ab 100644 --- a/src/Twig/Components/Organisms/CardList.php +++ b/src/Twig/Components/Organisms/CardList.php @@ -7,4 +7,5 @@ use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; #[AsTwigComponent] final class CardList { + public array $list; } diff --git a/templates/components/Molecules/Card.html.twig b/templates/components/Molecules/Card.html.twig index 1f30bbf..f0e6e6f 100644 --- a/templates/components/Molecules/Card.html.twig +++ b/templates/components/Molecules/Card.html.twig @@ -5,6 +5,6 @@
Hello, {{ app.user.displayName }}
- Log out +