-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: prefer invokeable controllers
- Loading branch information
Showing
30 changed files
with
325 additions
and
336 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
app/Http/Controllers/API/DisconnectFromLastfmController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\User; | ||
use App\Services\LastfmService; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class DisconnectFromLastfmController extends Controller | ||
{ | ||
/** @param User $user */ | ||
public function __invoke(LastfmService $lastfm, Authenticatable $user) | ||
{ | ||
$lastfm->setUserSessionKey($user, null); | ||
|
||
return response()->noContent(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
app/Http/Controllers/API/FetchAlbumThumbnailController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Album; | ||
use App\Services\MediaMetadataService; | ||
|
||
class FetchAlbumThumbnailController extends Controller | ||
{ | ||
public function __invoke(Album $album, MediaMetadataService $mediaMetadataService) | ||
{ | ||
return response()->json(['thumbnailUrl' => $mediaMetadataService->getAlbumThumbnailUrl($album)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\SongResource; | ||
use App\Models\User; | ||
use App\Repositories\SongRepository; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class FetchFavoriteSongsController extends Controller | ||
{ | ||
/** @param User $user */ | ||
public function __invoke(SongRepository $repository, Authenticatable $user) | ||
{ | ||
return SongResource::collection($repository->getFavorites($user)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\AlbumResource; | ||
use App\Http\Resources\ArtistResource; | ||
use App\Http\Resources\SongResource; | ||
use App\Repositories\AlbumRepository; | ||
use App\Repositories\ArtistRepository; | ||
use App\Repositories\SongRepository; | ||
|
||
class FetchOverviewController extends Controller | ||
{ | ||
public function __invoke( | ||
SongRepository $songRepository, | ||
AlbumRepository $albumRepository, | ||
ArtistRepository $artistRepository | ||
) { | ||
|
||
return response()->json([ | ||
'most_played_songs' => SongResource::collection($songRepository->getMostPlayed()), | ||
'recently_played_songs' => SongResource::collection($songRepository->getRecentlyPlayed()), | ||
'recently_added_albums' => AlbumResource::collection($albumRepository->getRecentlyAdded()), | ||
'recently_added_songs' => SongResource::collection($songRepository->getRecentlyAdded()), | ||
'most_played_artists' => ArtistResource::collection($artistRepository->getMostPlayed()), | ||
'most_played_albums' => AlbumResource::collection($albumRepository->getMostPlayed()), | ||
]); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/Http/Controllers/API/FetchRecentlyPlayedSongController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\SongResource; | ||
use App\Models\User; | ||
use App\Repositories\SongRepository; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class FetchRecentlyPlayedSongController extends Controller | ||
{ | ||
private const MAX_ITEM_COUNT = 128; | ||
|
||
/** @param User $user */ | ||
public function __invoke(SongRepository $repository, ?Authenticatable $user) | ||
{ | ||
return SongResource::collection($repository->getRecentlyPlayed(self::MAX_ITEM_COUNT, $user)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\API\FetchSongsForQueueRequest; | ||
use App\Http\Resources\SongResource; | ||
use App\Models\User; | ||
use App\Repositories\SongRepository; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class FetchSongsForQueueController extends Controller | ||
{ | ||
/** @param User $user */ | ||
public function __invoke(FetchSongsForQueueRequest $request, SongRepository $repository, Authenticatable $user) | ||
{ | ||
return SongResource::collection( | ||
$request->order === 'rand' | ||
? $repository->getRandom($request->limit, $user) | ||
: $repository->getForQueue($request->sort, $request->order, $request->limit, $user) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.