From f260bda7ee2002c18bb9d1ed172d560e89262c5b Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 9 Oct 2023 15:35:32 +0300 Subject: [PATCH] refactor bookmarks to stars --- src/Controller/TorrentController.php | 16 ++++----- .../{TorrentBookmark.php => TorrentStar.php} | 6 ++-- ...pository.php => TorrentStarRepository.php} | 22 ++++++------ src/Service/TorrentService.php | 36 +++++++++---------- templates/default/torrent/info.html.twig | 6 ++-- translations/messages+intl-icu.uk.xlf | 6 ++-- 6 files changed, 46 insertions(+), 46 deletions(-) rename src/Entity/{TorrentBookmark.php => TorrentStar.php} (88%) rename src/Repository/{TorrentBookmarkRepository.php => TorrentStarRepository.php} (60%) diff --git a/src/Controller/TorrentController.php b/src/Controller/TorrentController.php index cf3c04f..3d05c75 100644 --- a/src/Controller/TorrentController.php +++ b/src/Controller/TorrentController.php @@ -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() diff --git a/src/Entity/TorrentBookmark.php b/src/Entity/TorrentStar.php similarity index 88% rename from src/Entity/TorrentBookmark.php rename to src/Entity/TorrentStar.php index c3ed994..e5fd435 100644 --- a/src/Entity/TorrentBookmark.php +++ b/src/Entity/TorrentStar.php @@ -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] diff --git a/src/Repository/TorrentBookmarkRepository.php b/src/Repository/TorrentStarRepository.php similarity index 60% rename from src/Repository/TorrentBookmarkRepository.php rename to src/Repository/TorrentStarRepository.php index 1c8e326..bbb6b17 100644 --- a/src/Repository/TorrentBookmarkRepository.php +++ b/src/Repository/TorrentStarRepository.php @@ -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 + * @extends ServiceEntityRepository * - * @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 { diff --git a/src/Service/TorrentService.php b/src/Service/TorrentService.php index 2521b68..4c01c36 100644 --- a/src/Service/TorrentService.php +++ b/src/Service/TorrentService.php @@ -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(); } } diff --git a/templates/default/torrent/info.html.twig b/templates/default/torrent/info.html.twig index 1ad9b3c..5daefd0 100644 --- a/templates/default/torrent/info.html.twig +++ b/templates/default/torrent/info.html.twig @@ -56,8 +56,8 @@ {{ torrent.download.file.total }} - - {% if torrent.bookmark.exist %} + + {% if torrent.star.exist %} @@ -68,7 +68,7 @@ {% endif %} - {{ torrent.bookmark.total }} + {{ torrent.star.total }} {# diff --git a/translations/messages+intl-icu.uk.xlf b/translations/messages+intl-icu.uk.xlf index bbdc1d8..d12869f 100644 --- a/translations/messages+intl-icu.uk.xlf +++ b/translations/messages+intl-icu.uk.xlf @@ -357,9 +357,9 @@ Download torrent file Download torrent file - - Bookmark - Bookmark + + Star + Star Filename