implement torrent bookmarks feature

This commit is contained in:
ghost 2023-10-08 20:08:30 +03:00
parent a8b08bed06
commit 3d74818303
5 changed files with 277 additions and 36 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace App\Repository;
use App\Entity\TorrentBookmark;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<TorrentBookmark>
*
* @method TorrentBookmark|null find($id, $lockMode = null, $lockVersion = null)
* @method TorrentBookmark|null findOneBy(array $criteria, array $orderBy = null)
* @method TorrentBookmark[] findAll()
* @method TorrentBookmark[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class TorrentBookmarkRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, TorrentBookmark::class);
}
public function findUserLastTorrentBookmark(
int $torrentId,
int $userId
): ?TorrentBookmark
{
return $this->createQueryBuilder('tb')
->where('tb.torrentId = :torrentId')
->andWhere('tb.userId = :userId')
->setParameter('torrentId', $torrentId)
->setParameter('userId', $userId)
->orderBy('tb.id', 'DESC') // same to ts.added
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
}
}