mirror of
https://github.com/koel/koel
synced 2024-11-24 05:03:05 +00:00
chore: add User dependency to SmartPlaylistService
This commit is contained in:
parent
b6daeb5d77
commit
444e91ab57
3 changed files with 10 additions and 5 deletions
|
@ -5,14 +5,18 @@ namespace App\Http\Controllers\API;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\API\PlaylistSongUpdateRequest;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\User;
|
||||
use App\Services\PlaylistService;
|
||||
use App\Services\SmartPlaylistService;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class PlaylistSongController extends Controller
|
||||
{
|
||||
/** @param User $user */
|
||||
public function __construct(
|
||||
private SmartPlaylistService $smartPlaylistService,
|
||||
private PlaylistService $playlistService
|
||||
private PlaylistService $playlistService,
|
||||
private Authenticatable $user
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -22,7 +26,7 @@ class PlaylistSongController extends Controller
|
|||
|
||||
return response()->json(
|
||||
$playlist->is_smart
|
||||
? $this->smartPlaylistService->getSongs($playlist)->pluck('id')
|
||||
? $this->smartPlaylistService->getSongs($playlist, $this->user)->pluck('id')
|
||||
: $playlist->songs->pluck('id')
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class PlaylistSongController extends Controller
|
|||
|
||||
return SongResource::collection(
|
||||
$playlist->is_smart
|
||||
? $this->smartPlaylistService->getSongs($playlist)
|
||||
? $this->smartPlaylistService->getSongs($playlist, $this->user)
|
||||
: $this->songRepository->getByStandardPlaylist($playlist, $this->user)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Services;
|
|||
use App\Exceptions\NonSmartPlaylistException;
|
||||
use App\Models\Playlist;
|
||||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use App\Values\SmartPlaylistRule;
|
||||
use App\Values\SmartPlaylistRuleGroup;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
|
@ -18,11 +19,11 @@ class SmartPlaylistService
|
|||
}
|
||||
|
||||
/** @return Collection|array<array-key, Song> */
|
||||
public function getSongs(Playlist $playlist): Collection
|
||||
public function getSongs(Playlist $playlist, ?User $user = null): Collection
|
||||
{
|
||||
throw_unless($playlist->is_smart, NonSmartPlaylistException::create($playlist));
|
||||
|
||||
$query = Song::withMeta($this->auth->user());
|
||||
$query = Song::withMeta($user ?? $this->auth->user());
|
||||
|
||||
$playlist->rule_groups->each(static function (SmartPlaylistRuleGroup $group, int $index) use ($query): void {
|
||||
$clause = $index === 0 ? 'where' : 'orWhere';
|
||||
|
|
Loading…
Reference in a new issue