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

@ -5,10 +5,12 @@ namespace App\Service;
use App\Entity\Torrent;
use App\Entity\TorrentLocales;
use App\Entity\TorrentSensitive;
use App\Entity\TorrentBookmark;
use App\Repository\TorrentRepository;
use App\Repository\TorrentLocalesRepository;
use App\Repository\TorrentSensitiveRepository;
use App\Repository\TorrentBookmarkRepository;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Filesystem\Filesystem;
@ -158,6 +160,19 @@ class TorrentService
->findTorrentSensitive($torrentId);
}
/// Bookmark
public function findUserLastTorrentBookmarkValue(int $torrentId, int $userId): bool
{
if ($torrentBookmark = $this->entityManagerInterface
->getRepository(TorrentBookmark::class)
->findUserLastTorrentBookmark($torrentId, $userId))
{
return $torrentBookmark->isValue();
}
return false;
}
// Update
public function toggleTorrentLocalesApproved(
int $id
@ -204,6 +219,31 @@ class TorrentService
return $torrentLocales;
}
public function toggleTorrentBookmark(
int $torrentId,
int $userId,
int $added
): ?TorrentBookmark
{
$torrentBookmark = new TorrentBookmark();
$torrentBookmark->setTorrentId($torrentId);
$torrentBookmark->setUserId($userId);
$torrentBookmark->setAdded($added);
$torrentBookmark->setValue(
!$this->findUserLastTorrentBookmarkValue(
$torrentId,
$userId
)
);
$this->entityManagerInterface->persist($torrentBookmark);
$this->entityManagerInterface->flush();
return $torrentBookmark;
}
public function deleteTorrentSensitive(
int $id
): ?TorrentSensitive