Allow browsing public snips

Fixed big with branch name not existing if nothing committed
This commit is contained in:
Tim
2023-04-06 20:30:11 +02:00
parent ce456adf10
commit 004044022d
7 changed files with 49 additions and 4 deletions

View File

@ -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'
]);
}

View File

@ -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();
}
}

View File

@ -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);
}