Implement Entity/Repository station helpers.
This commit is contained in:
parent
d03a60258f
commit
fe87dc2fae
|
@ -53,7 +53,7 @@ final class DeleteArtAction
|
|||
): ResponseInterface {
|
||||
$station = $request->getStation();
|
||||
|
||||
$media = $this->mediaRepo->find($media_id, $station);
|
||||
$media = $this->mediaRepo->findForStation($media_id, $station);
|
||||
if (!($media instanceof Entity\StationMedia)) {
|
||||
return $response->withStatus(404)
|
||||
->withJson(Entity\Api\Error::notFound());
|
||||
|
|
|
@ -64,7 +64,7 @@ final class GetArtAction
|
|||
$response = $response->withCacheLifetime(Response::CACHE_ONE_YEAR);
|
||||
$mediaPath = Entity\StationMedia::getArtPath($media_id);
|
||||
} else {
|
||||
$media = $this->mediaRepo->find($media_id, $station);
|
||||
$media = $this->mediaRepo->findForStation($media_id, $station);
|
||||
if ($media instanceof Entity\StationMedia) {
|
||||
$mediaPath = Entity\StationMedia::getArtPath($media->getUniqueId());
|
||||
} else {
|
||||
|
|
|
@ -56,7 +56,7 @@ final class PostArtAction
|
|||
): ResponseInterface {
|
||||
$station = $request->getStation();
|
||||
|
||||
$media = $this->mediaRepo->find($media_id, $station);
|
||||
$media = $this->mediaRepo->findForStation($media_id, $station);
|
||||
if (!($media instanceof Entity\StationMedia)) {
|
||||
return $response->withStatus(404)
|
||||
->withJson(Entity\Api\Error::notFound());
|
||||
|
|
|
@ -27,7 +27,7 @@ final class PlayAction
|
|||
|
||||
$station = $request->getStation();
|
||||
|
||||
$media = $this->mediaRepo->find($id, $station);
|
||||
$media = $this->mediaRepo->findForStation($id, $station);
|
||||
|
||||
if (!$media instanceof Entity\StationMedia) {
|
||||
return $response->withStatus(404)
|
||||
|
|
|
@ -47,7 +47,7 @@ final class DeleteIntroAction
|
|||
string $id
|
||||
): ResponseInterface {
|
||||
$station = $request->getStation();
|
||||
$mount = $this->mountRepo->find($station, $id);
|
||||
$mount = $this->mountRepo->findForStation($id, $station);
|
||||
|
||||
if (null === $mount) {
|
||||
return $response->withStatus(404)
|
||||
|
|
|
@ -53,7 +53,7 @@ final class GetIntroAction
|
|||
set_time_limit(600);
|
||||
|
||||
$station = $request->getStation();
|
||||
$mount = $this->mountRepo->find($station, $id);
|
||||
$mount = $this->mountRepo->findForStation($id, $station);
|
||||
|
||||
if ($mount instanceof Entity\StationMount) {
|
||||
$introPath = $mount->getIntroPath();
|
||||
|
|
|
@ -55,7 +55,7 @@ final class PostIntroAction
|
|||
}
|
||||
|
||||
if (null !== $id) {
|
||||
$mount = $this->mountRepo->find($station, $id);
|
||||
$mount = $this->mountRepo->findForStation($id, $station);
|
||||
if (null === $mount) {
|
||||
return $response->withStatus(404)
|
||||
->withJson(Entity\Api\Error::notFound());
|
||||
|
|
|
@ -45,6 +45,20 @@ class Repository
|
|||
return $this->repository;
|
||||
}
|
||||
|
||||
public function getEntityManager(): ReloadableEntityManagerInterface
|
||||
{
|
||||
return $this->em;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $id
|
||||
* @return TEntity|null
|
||||
*/
|
||||
public function find(int|string $id): ?object
|
||||
{
|
||||
return $this->em->find($this->entityClass, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an array result of all records.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Interfaces;
|
||||
|
||||
use App\Entity\Station;
|
||||
|
||||
interface StationAwareInterface
|
||||
{
|
||||
public function getStation(): ?Station;
|
||||
}
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use NowPlaying\Result\Client;
|
||||
|
||||
|
@ -16,7 +15,9 @@ use NowPlaying\Result\Client;
|
|||
ORM\Index(columns: ['device_os_family'], name: 'idx_statistics_os'),
|
||||
ORM\Index(columns: ['device_browser_family'], name: 'idx_statistics_browser')
|
||||
]
|
||||
class Listener implements IdentifiableEntityInterface
|
||||
class Listener implements
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -15,7 +14,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
ORM\Table(name: 'podcast'),
|
||||
Attributes\Auditable
|
||||
]
|
||||
class Podcast implements IdentifiableEntityInterface
|
||||
class Podcast implements Interfaces\IdentifiableEntityInterface
|
||||
{
|
||||
use Traits\HasUniqueId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity\Interfaces\StationAwareInterface;
|
||||
use App\Entity\Station;
|
||||
|
||||
/**
|
||||
* @template TEntity as object
|
||||
*/
|
||||
abstract class AbstractStationBasedRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* @param int|string $id
|
||||
* @param Station $station
|
||||
* @return TEntity|null
|
||||
*/
|
||||
public function findForStation(int|string $id, Station $station): ?object
|
||||
{
|
||||
$record = $this->find($id);
|
||||
|
||||
if ($record instanceof StationAwareInterface && $station === $record->getStation()) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
use App\Environment;
|
||||
use App\Radio\Backend\Liquidsoap\Command\FeedbackCommand;
|
||||
|
@ -15,9 +14,9 @@ use Psr\Log\LoggerInterface;
|
|||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\SongHistory>
|
||||
* @extends AbstractStationBasedRepository<Entity\SongHistory>
|
||||
*/
|
||||
class SongHistoryRepository extends Repository
|
||||
class SongHistoryRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
|
|
|
@ -44,21 +44,16 @@ class StationMediaRepository extends Repository
|
|||
parent::__construct($em, $serializer, $environment, $logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $id
|
||||
* @param Entity\Station|Entity\StorageLocation $source
|
||||
*
|
||||
*/
|
||||
public function find(int|string $id, Entity\Station|Entity\StorageLocation $source): ?Entity\StationMedia
|
||||
public function findForStation(int|string $id, Entity\Station $station): ?Entity\StationMedia
|
||||
{
|
||||
if (!is_numeric($id) && Entity\StationMedia::UNIQUE_ID_LENGTH === strlen($id)) {
|
||||
$media = $this->findByUniqueId($id, $source);
|
||||
$media = $this->findByUniqueId($id, $station);
|
||||
if ($media instanceof Entity\StationMedia) {
|
||||
return $media;
|
||||
}
|
||||
}
|
||||
|
||||
$storageLocation = $this->getStorageLocation($source);
|
||||
$storageLocation = $this->getStorageLocation($station);
|
||||
|
||||
/** @var Entity\StationMedia|null $media */
|
||||
$media = $this->repository->findOneBy(
|
||||
|
|
|
@ -4,27 +4,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
use App\Flysystem\StationFilesystems;
|
||||
use App\Service\Flow\UploadedFile;
|
||||
use Azura\Files\ExtendedFilesystemInterface;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationMount>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationMount>
|
||||
*/
|
||||
class StationMountRepository extends Repository
|
||||
class StationMountRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
public function find(Entity\Station $station, int|string $id): ?Entity\StationMount
|
||||
{
|
||||
return $this->repository->findOneBy(
|
||||
[
|
||||
'station' => $station,
|
||||
'id' => (int)$id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function setIntro(
|
||||
Entity\StationMount $mount,
|
||||
UploadedFile $file,
|
||||
|
|
|
@ -4,13 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationPlaylistFolder>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationPlaylistFolder>
|
||||
*/
|
||||
class StationPlaylistFolderRepository extends Repository
|
||||
class StationPlaylistFolderRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
/**
|
||||
* @param Entity\Station $station
|
||||
|
|
|
@ -4,13 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationPlaylist>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationPlaylist>
|
||||
*/
|
||||
class StationPlaylistRepository extends Repository
|
||||
class StationPlaylistRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
/**
|
||||
* @return Entity\StationPlaylist[]
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
|
@ -12,9 +11,9 @@ use Doctrine\ORM\Query;
|
|||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationQueue>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationQueue>
|
||||
*/
|
||||
class StationQueueRepository extends Repository
|
||||
class StationQueueRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
public function clearForMediaAndPlaylist(Entity\StationMedia $media, Entity\StationPlaylist $playlist): void
|
||||
{
|
||||
|
|
|
@ -4,13 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationRemote>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationRemote>
|
||||
*/
|
||||
class StationRemoteRepository extends Repository
|
||||
class StationRemoteRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
/**
|
||||
* @param Entity\Station $station
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace App\Entity\Repository;
|
||||
|
||||
use App\Doctrine\ReloadableEntityManagerInterface;
|
||||
use App\Doctrine\Repository;
|
||||
use App\Entity;
|
||||
use App\Environment;
|
||||
use App\Exception;
|
||||
|
@ -18,9 +17,9 @@ use Psr\Log\LoggerInterface;
|
|||
use Symfony\Component\Serializer\Serializer;
|
||||
|
||||
/**
|
||||
* @extends Repository<Entity\StationRequest>
|
||||
* @extends AbstractStationBasedRepository<Entity\StationRequest>
|
||||
*/
|
||||
class StationRequestRepository extends Repository
|
||||
class StationRequestRepository extends AbstractStationBasedRepository
|
||||
{
|
||||
public function __construct(
|
||||
ReloadableEntityManagerInterface $em,
|
||||
|
|
|
@ -12,11 +12,6 @@ use App\Entity;
|
|||
*/
|
||||
class UserRepository extends Repository
|
||||
{
|
||||
public function find(int|string $id): ?Entity\User
|
||||
{
|
||||
return $this->repository->find((int)$id);
|
||||
}
|
||||
|
||||
public function findByEmail(string $email): ?Entity\User
|
||||
{
|
||||
return $this->repository->findOneby(['email' => $email]);
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Attributes\Auditable;
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use App\Validator\Constraints\UniqueEntity;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Exception;
|
||||
|
@ -23,7 +22,9 @@ use const PASSWORD_ARGON2ID;
|
|||
UniqueEntity(fields: ['username']),
|
||||
Auditable
|
||||
]
|
||||
class SftpUser implements IdentifiableEntityInterface
|
||||
class SftpUser implements
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use App\Entity\Interfaces\SongInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
|
@ -14,7 +13,10 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
ORM\Index(columns: ['timestamp_start'], name: 'idx_timestamp_start'),
|
||||
ORM\Index(columns: ['timestamp_end'], name: 'idx_timestamp_end')
|
||||
]
|
||||
class SongHistory implements SongInterface, IdentifiableEntityInterface
|
||||
class SongHistory implements
|
||||
Interfaces\SongInterface,
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateInts;
|
||||
|
|
|
@ -26,7 +26,8 @@ class StationMount implements
|
|||
Stringable,
|
||||
Interfaces\StationMountInterface,
|
||||
Interfaces\StationCloneAwareInterface,
|
||||
Interfaces\IdentifiableEntityInterface
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
@ -417,7 +418,7 @@ class StationMount implements
|
|||
$response->url = $fa->getUrlForMount($this->station, $this, $base_url);
|
||||
|
||||
$response->listeners = new Api\NowPlaying\Listeners(
|
||||
total: $this->listeners_total,
|
||||
total: $this->listeners_total,
|
||||
unique: $this->listeners_unique
|
||||
);
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class StationPlaylist implements
|
||||
Stringable,
|
||||
Interfaces\StationCloneAwareInterface,
|
||||
Interfaces\IdentifiableEntityInterface
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
|
@ -13,7 +13,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
class StationPlaylistFolder implements
|
||||
Interfaces\PathAwareInterface,
|
||||
Interfaces\StationCloneAwareInterface,
|
||||
Interfaces\IdentifiableEntityInterface
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
|
@ -4,8 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use App\Entity\Interfaces\SongInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[
|
||||
|
@ -16,7 +14,10 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
ORM\Index(columns: ['sent_to_autodj'], name: 'idx_sent_to_autodj'),
|
||||
ORM\Index(columns: ['timestamp_cued'], name: 'idx_timestamp_cued')
|
||||
]
|
||||
class StationQueue implements SongInterface, IdentifiableEntityInterface
|
||||
class StationQueue implements
|
||||
Interfaces\SongInterface,
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateInts;
|
||||
|
|
|
@ -25,7 +25,8 @@ class StationRemote implements
|
|||
Stringable,
|
||||
Interfaces\StationMountInterface,
|
||||
Interfaces\StationCloneAwareInterface,
|
||||
Interfaces\IdentifiableEntityInterface
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Interfaces\IdentifiableEntityInterface;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use DateTimeZone;
|
||||
|
@ -14,7 +13,9 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
ORM\Entity,
|
||||
ORM\Table(name: 'station_requests')
|
||||
]
|
||||
class StationRequest implements IdentifiableEntityInterface
|
||||
class StationRequest implements
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class StationWebhook implements
|
||||
Stringable,
|
||||
Interfaces\StationCloneAwareInterface,
|
||||
Interfaces\IdentifiableEntityInterface
|
||||
Interfaces\IdentifiableEntityInterface,
|
||||
Interfaces\StationAwareInterface
|
||||
{
|
||||
use Traits\HasAutoIncrementId;
|
||||
use Traits\TruncateStrings;
|
||||
|
|
Loading…
Reference in New Issue