mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
refactor bookmarks to stars
This commit is contained in:
parent
997d9db562
commit
f260bda7ee
6 changed files with 46 additions and 46 deletions
|
|
@ -126,13 +126,13 @@ class TorrentController extends AbstractController
|
|||
)
|
||||
]
|
||||
],
|
||||
'bookmark' =>
|
||||
'star' =>
|
||||
[
|
||||
'exist' => (bool) $torrentService->findTorrentBookmark(
|
||||
'exist' => (bool) $torrentService->findTorrentStar(
|
||||
$torrent->getId(),
|
||||
$user->getId()
|
||||
),
|
||||
'total' => $torrentService->findTorrentBookmarksTotalByTorrentId(
|
||||
'total' => $torrentService->findTorrentStarsTotalByTorrentId(
|
||||
$torrent->getId()
|
||||
)
|
||||
],
|
||||
|
|
@ -901,10 +901,10 @@ class TorrentController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Torrent bookmark
|
||||
// Torrent star
|
||||
#[Route(
|
||||
'/{_locale}/torrent/{torrentId}/bookmark/toggle',
|
||||
name: 'torrent_bookmark_toggle',
|
||||
'/{_locale}/torrent/{torrentId}/star/toggle',
|
||||
name: 'torrent_star_toggle',
|
||||
requirements:
|
||||
[
|
||||
'torrentId' => '\d+',
|
||||
|
|
@ -914,7 +914,7 @@ class TorrentController extends AbstractController
|
|||
'GET'
|
||||
]
|
||||
)]
|
||||
public function toggleBookmark(
|
||||
public function toggleStar(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
|
|
@ -941,7 +941,7 @@ class TorrentController extends AbstractController
|
|||
}
|
||||
|
||||
// Update
|
||||
$torrentService->toggleTorrentBookmark(
|
||||
$torrentService->toggleTorrentStar(
|
||||
$torrent->getId(),
|
||||
$user->getId(),
|
||||
time()
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\TorrentBookmarkRepository;
|
||||
use App\Repository\TorrentStarRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: TorrentBookmarkRepository::class)]
|
||||
class TorrentBookmark
|
||||
#[ORM\Entity(repositoryClass: TorrentStarRepository::class)]
|
||||
class TorrentStar
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
|
|
@ -2,29 +2,29 @@
|
|||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\TorrentBookmark;
|
||||
use App\Entity\TorrentStar;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<TorrentBookmark>
|
||||
* @extends ServiceEntityRepository<TorrentStar>
|
||||
*
|
||||
* @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)
|
||||
* @method TorrentStar|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method TorrentStar|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method TorrentStar[] findAll()
|
||||
* @method TorrentStar[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class TorrentBookmarkRepository extends ServiceEntityRepository
|
||||
class TorrentStarRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, TorrentBookmark::class);
|
||||
parent::__construct($registry, TorrentStar::class);
|
||||
}
|
||||
|
||||
public function findTorrentBookmark(
|
||||
public function findTorrentStar(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentBookmark
|
||||
): ?TorrentStar
|
||||
{
|
||||
return $this->createQueryBuilder('tb')
|
||||
->where('tb.torrentId = :torrentId')
|
||||
|
|
@ -38,7 +38,7 @@ class TorrentBookmarkRepository extends ServiceEntityRepository
|
|||
;
|
||||
}
|
||||
|
||||
public function findTorrentBookmarksTotalByTorrentId(
|
||||
public function findTorrentStarsTotalByTorrentId(
|
||||
int $torrentId
|
||||
): int
|
||||
{
|
||||
|
|
@ -5,14 +5,14 @@ namespace App\Service;
|
|||
use App\Entity\Torrent;
|
||||
use App\Entity\TorrentLocales;
|
||||
use App\Entity\TorrentSensitive;
|
||||
use App\Entity\TorrentBookmark;
|
||||
use App\Entity\TorrentStar;
|
||||
use App\Entity\TorrentDownloadFile;
|
||||
use App\Entity\TorrentDownloadMagnet;
|
||||
|
||||
use App\Repository\TorrentRepository;
|
||||
use App\Repository\TorrentLocalesRepository;
|
||||
use App\Repository\TorrentSensitiveRepository;
|
||||
use App\Repository\TorrentBookmarkRepository;
|
||||
use App\Repository\TorrentStarRepository;
|
||||
use App\Repository\TorrentDownloadFileRepository;
|
||||
use App\Repository\TorrentDownloadMagnetRepository;
|
||||
|
||||
|
|
@ -424,45 +424,45 @@ class TorrentService
|
|||
return $torrentSensitive;
|
||||
}
|
||||
|
||||
// Torrent bookmark
|
||||
public function findTorrentBookmark(
|
||||
// Torrent star
|
||||
public function findTorrentStar(
|
||||
int $torrentId,
|
||||
int $userId
|
||||
): ?TorrentBookmark
|
||||
): ?TorrentStar
|
||||
{
|
||||
return $this->entityManagerInterface
|
||||
->getRepository(TorrentBookmark::class)
|
||||
->findTorrentBookmark($torrentId, $userId);
|
||||
->getRepository(TorrentStar::class)
|
||||
->findTorrentStar($torrentId, $userId);
|
||||
}
|
||||
|
||||
public function findTorrentBookmarksTotalByTorrentId(int $torrentId): int
|
||||
public function findTorrentStarsTotalByTorrentId(int $torrentId): int
|
||||
{
|
||||
return $this->entityManagerInterface
|
||||
->getRepository(TorrentBookmark::class)
|
||||
->findTorrentBookmarksTotalByTorrentId($torrentId);
|
||||
->getRepository(TorrentStar::class)
|
||||
->findTorrentStarsTotalByTorrentId($torrentId);
|
||||
}
|
||||
|
||||
public function toggleTorrentBookmark(
|
||||
public function toggleTorrentStar(
|
||||
int $torrentId,
|
||||
int $userId,
|
||||
int $added
|
||||
): void
|
||||
{
|
||||
if ($torrentBookmark = $this->findTorrentBookmark($torrentId, $userId))
|
||||
if ($torrentStar = $this->findTorrentStar($torrentId, $userId))
|
||||
{
|
||||
$this->entityManagerInterface->remove($torrentBookmark);
|
||||
$this->entityManagerInterface->remove($torrentStar);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$torrentBookmark = new TorrentBookmark();
|
||||
$torrentStar = new TorrentStar();
|
||||
|
||||
$torrentBookmark->setTorrentId($torrentId);
|
||||
$torrentBookmark->setUserId($userId);
|
||||
$torrentBookmark->setAdded($added);
|
||||
$torrentStar->setTorrentId($torrentId);
|
||||
$torrentStar->setUserId($userId);
|
||||
$torrentStar->setAdded($added);
|
||||
|
||||
$this->entityManagerInterface->persist($torrentBookmark);
|
||||
$this->entityManagerInterface->persist($torrentStar);
|
||||
$this->entityManagerInterface->flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue