mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
clean(api): remove track position (#1198)
This commit is contained in:
@@ -26,24 +26,4 @@ class PlaylistTrackFactory extends Factory
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*/
|
||||
public function configure(): static
|
||||
{
|
||||
$this->afterCreating(function (PlaylistTrack $track): void {
|
||||
if ($track->playlist_id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$position = PlaylistTrack::query()
|
||||
->whereBelongsTo($track->playlist)
|
||||
->max(PlaylistTrack::ATTRIBUTE_POSITION) ?? 0;
|
||||
|
||||
$track->update([PlaylistTrack::ATTRIBUTE_POSITION => $position + 1]);
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class PlaylistFactory extends Factory
|
||||
->createOne();
|
||||
|
||||
if ($index === 1) {
|
||||
$track->moveToStart();
|
||||
$track->position = 1;
|
||||
$playlist->first()->associate($track)->save();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class PlaylistFactory extends Factory
|
||||
}
|
||||
|
||||
if ($index === $count) {
|
||||
$track->moveToEnd();
|
||||
$track->position = $index;
|
||||
$playlist->last()->associate($track);
|
||||
$playlist->save();
|
||||
}
|
||||
@@ -114,6 +114,7 @@ class PlaylistFactory extends Factory
|
||||
->createOne();
|
||||
|
||||
if ($index === 1) {
|
||||
$track->position = 1;
|
||||
$playlist->first()->associate($track)->save();
|
||||
}
|
||||
|
||||
@@ -126,6 +127,7 @@ class PlaylistFactory extends Factory
|
||||
}
|
||||
|
||||
if ($index === count($videoIds)) {
|
||||
$track->position = $index;
|
||||
$playlist->last()->associate($track);
|
||||
$playlist->save();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user