2016-05-30 05:50:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2020-09-13 22:04:07 +00:00
|
|
|
use App\Http\Requests\API\ScrobbleStoreRequest;
|
2020-04-27 18:55:12 +00:00
|
|
|
use App\Jobs\ScrobbleJob;
|
2016-05-30 05:50:59 +00:00
|
|
|
use App\Models\Song;
|
2020-09-13 22:04:07 +00:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
2016-05-30 05:50:59 +00:00
|
|
|
|
|
|
|
class ScrobbleController extends Controller
|
|
|
|
{
|
2020-09-13 22:04:07 +00:00
|
|
|
/** @var User */
|
2021-06-05 10:47:56 +00:00
|
|
|
private ?Authenticatable $currentUser;
|
2020-09-13 22:04:07 +00:00
|
|
|
|
2021-06-05 10:47:56 +00:00
|
|
|
public function __construct(?Authenticatable $currentUser)
|
2018-08-19 21:17:05 +00:00
|
|
|
{
|
2020-09-13 22:04:07 +00:00
|
|
|
$this->currentUser = $currentUser;
|
2018-08-19 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 22:04:07 +00:00
|
|
|
public function store(ScrobbleStoreRequest $request, Song $song)
|
2016-05-30 05:50:59 +00:00
|
|
|
{
|
2020-09-13 22:04:07 +00:00
|
|
|
if (!$song->artist->is_unknown && $this->currentUser->connectedToLastfm()) {
|
2021-06-04 15:19:33 +00:00
|
|
|
ScrobbleJob::dispatch($this->currentUser, $song, $request->timestamp);
|
2018-08-19 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 17:07:43 +00:00
|
|
|
return response()->noContent();
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|
|
|
|
}
|