mirror of
https://github.com/koel/koel
synced 2024-12-19 09:03:07 +00:00
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\Interaction;
|
|
use App\Models\User;
|
|
use App\Repositories\Traits\ByCurrentUser;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class InteractionRepository extends Repository
|
|
{
|
|
use ByCurrentUser;
|
|
|
|
/** @return Collection|array<Interaction> */
|
|
public function getUserFavorites(User $user): Collection
|
|
{
|
|
return $this->model
|
|
->newQuery()
|
|
->where([
|
|
'user_id' => $user->id,
|
|
'liked' => true,
|
|
])
|
|
->with('song')
|
|
->pluck('song');
|
|
}
|
|
|
|
/** @return array<Interaction> */
|
|
public function getRecentlyPlayed(User $user, ?int $count = null): array
|
|
{
|
|
return $this->model
|
|
->newQuery()
|
|
->where('user_id', $user->id)
|
|
->where('play_count', '>', 0)
|
|
->latest('last_played_at')
|
|
->when($count, static fn (Builder $query, int $count) => $query->take($count))
|
|
->pluck('song_id')
|
|
->all();
|
|
}
|
|
}
|