clean(api): remove track position (#1198)

This commit is contained in:
Kyrch
2026-05-08 02:02:20 -03:00
committed by GitHub
parent a3f1a8c7e3
commit fd2ef1611b
9 changed files with 5 additions and 249 deletions
@@ -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;
}
}
+4 -2
View File
@@ -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();
}