2015-12-20 12:17:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
2017-12-09 18:34:27 +00:00
|
|
|
use App\Http\Requests\API\LastfmSetSessionKeyRequest;
|
2020-09-06 18:21:39 +00:00
|
|
|
use App\Models\User;
|
2021-06-04 16:19:34 +00:00
|
|
|
use App\Services\LastfmService;
|
2020-09-06 18:21:39 +00:00
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
2020-09-13 22:04:07 +00:00
|
|
|
use Illuminate\Http\Response;
|
2015-12-20 12:17:35 +00:00
|
|
|
|
|
|
|
class LastfmController extends Controller
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
private LastfmService $lastfm;
|
2021-06-04 16:19:34 +00:00
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
/** @var User */
|
2021-06-05 10:47:56 +00:00
|
|
|
private ?Authenticatable $currentUser;
|
2020-09-06 18:21:39 +00:00
|
|
|
|
2021-06-04 16:19:34 +00:00
|
|
|
public function __construct(LastfmService $lastfm, ?Authenticatable $currentUser)
|
2018-09-04 06:25:24 +00:00
|
|
|
{
|
2021-06-04 16:19:34 +00:00
|
|
|
$this->lastfm = $lastfm;
|
2020-09-06 18:21:39 +00:00
|
|
|
$this->currentUser = $currentUser;
|
2015-12-20 12:17:35 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 18:34:27 +00:00
|
|
|
public function setSessionKey(LastfmSetSessionKeyRequest $request)
|
2016-01-26 06:32:29 +00:00
|
|
|
{
|
2021-06-04 16:19:34 +00:00
|
|
|
$this->lastfm->setUserSessionKey($this->currentUser, trim($request->key));
|
2016-01-26 06:32:29 +00:00
|
|
|
|
2020-09-13 22:04:07 +00:00
|
|
|
return response()->json(null, Response::HTTP_NO_CONTENT);
|
2016-01-26 06:32:29 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 12:17:35 +00:00
|
|
|
public function disconnect()
|
|
|
|
{
|
2021-06-04 16:19:34 +00:00
|
|
|
$this->lastfm->setUserSessionKey($this->currentUser, null);
|
2018-09-04 02:25:34 +00:00
|
|
|
|
2020-09-13 22:04:07 +00:00
|
|
|
return response()->json(null, Response::HTTP_NO_CONTENT);
|
2015-12-20 12:17:35 +00:00
|
|
|
}
|
|
|
|
}
|