diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php index ca7f238..4a40635 100644 --- a/src/Controller/SnipController.php +++ b/src/Controller/SnipController.php @@ -28,6 +28,16 @@ class SnipController extends AbstractController { return $this->render('snip/index.html.twig', [ 'snips' => $this->repository->findByUser($this->getUser()), + 'title' => 'My Snips' + ]); + } + + #[Route('/public', name: '_public')] + public function public(): Response + { + return $this->render('snip/index.html.twig', [ + 'snips' => $this->repository->findPublic(), + 'title' => 'Public Snips' ]); } diff --git a/src/Repository/SnipRepository.php b/src/Repository/SnipRepository.php index ccdd8dd..da6d1a7 100644 --- a/src/Repository/SnipRepository.php +++ b/src/Repository/SnipRepository.php @@ -49,4 +49,14 @@ class SnipRepository extends ServiceEntityRepository return $qb->getQuery()->getResult(); } + + public function findPublic(): array + { + $qb = $this->createQueryBuilder('s'); + $qb->where('s.public = :public') + ->setParameter('public', true) + ->orderBy('s.createdAt', 'DESC'); + + return $qb->getQuery()->getResult(); + } } diff --git a/src/Service/SnipServiceFactory.php b/src/Service/SnipServiceFactory.php index 52c5e1e..86ec2a8 100644 --- a/src/Service/SnipServiceFactory.php +++ b/src/Service/SnipServiceFactory.php @@ -22,6 +22,9 @@ class SnipServiceFactory $repoPath = sprintf('%s/%s', $this->snipBasePath, $snip->getId()); if (!is_dir($repoPath)) { $repo = $git->init($repoPath); + touch(sprintf('%s/.gitignore', $repoPath)); + $repo->addFile('.gitignore'); + $repo->commit('Initial commit'); } else { $repo = $git->open($repoPath); } diff --git a/templates/base/navbar.html.twig b/templates/base/navbar.html.twig index 4f4b080..866ec72 100644 --- a/templates/base/navbar.html.twig +++ b/templates/base/navbar.html.twig @@ -19,6 +19,9 @@ + {% endif %}