Implement comments (#10)

Allow logged users to comment posts. Edition is not allowed via the API since it doesn't support auth yet.

Symfony UX is used with Turbo to avoid full pages reload, without JavaScript™.

Co-authored-by: clfreville2 <clement.freville2@etu.uca.fr>
Reviewed-on: https://codefirst.iut.uca.fr/git/clement.freville2/herbarium/pulls/10
This commit is contained in:
2024-06-11 17:17:24 +02:00
parent b4a1ae592f
commit 8859cd0000
20 changed files with 477 additions and 5 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Repository;
use App\Entity\Comment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Comment>
*/
class CommentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Comment::class);
}
// /**
// * @return Comment[] Returns an array of Comment objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Comment
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}

View File

@@ -25,6 +25,8 @@ class PostRepository extends ServiceEntityRepository
public function findPaginatedPosts(int $page, int $limit): Paginator
{
$query = $this->createQueryBuilder('p')
->addSelect('species')
->leftJoin('p.species', 'species')
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit);