Skip to content

Commit

Permalink
Allow to set the temporary playlist id by api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
usox committed May 11, 2022
1 parent 694426b commit bb883da
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ protected function run(
'TemporaryPlaylistUpdate.json',
);

$temporaryPlaylistId = $body['playlistId'];

// find existing playlist; if not available, create a new one
$temporaryPlaylist = $this->temporaryPlaylistRepository->findOneBy([
'owner' => $user,
'id' => $body['playlistId'],
'id' => $temporaryPlaylistId,
]);
if ($temporaryPlaylist === null) {
$temporaryPlaylist = $this->temporaryPlaylistRepository
->prototype()
->setId($temporaryPlaylistId)
->setOwner($user);
}

Expand Down
12 changes: 8 additions & 4 deletions src/Orm/Model/TemporaryPlaylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\Doctrine\UuidType;
use Uxmp\Core\Orm\Repository\TemporaryPlaylistRepository;

Expand All @@ -15,11 +14,10 @@
class TemporaryPlaylist implements TemporaryPlaylistInterface
{
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
#[ORM\Id, ORM\GeneratedValue(strategy: 'NONE')]
private string $id;

#[ORM\Column(type: Types::INTEGER, options: ['default' => 0], unique: true)]
#[ORM\Column(type: Types::INTEGER, options: ['default' => 0])]
private int $owner_user_id = 0;

#[ORM\Column(type: Types::INTEGER, options: ['default' => 0])]
Expand All @@ -41,6 +39,12 @@ public function getId(): string
return $this->id;
}

public function setId(string $id): TemporaryPlaylistInterface
{
$this->id = $id;
return $this;
}

public function getOwner(): UserInterface
{
return $this->owner;
Expand Down
2 changes: 2 additions & 0 deletions src/Orm/Model/TemporaryPlaylistInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface TemporaryPlaylistInterface
{
public function getId(): string;

public function setId(string $id): TemporaryPlaylistInterface;

public function getOwner(): UserInterface;

public function setOwner(UserInterface $owner): TemporaryPlaylistInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function testRunReturnsResult(): void
->with($user)
->once()
->andReturnSelf();
$obj->shouldReceive('setId')
->with($playlistId)
->once()
->andReturnSelf();
$obj->shouldReceive('updateSongList')
->with([$songId])
->once();
Expand Down
1 change: 1 addition & 0 deletions tests/Orm/Model/TemporaryPlaylistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function setUp(): void
public function setterGetterDataProvider(): array
{
return [
['Id', 'set-some-id'],
['Owner', Mockery::mock(UserInterface::class)],
['SongList', [666, 42]],
['SongCount', 33],
Expand Down

0 comments on commit bb883da

Please sign in to comment.