Adds latest episode api endpoint and some other minor modifications.
This commit is contained in:
@@ -72,6 +72,7 @@ class ArtistController extends Controller
|
||||
$artworks = Artwork::where('artist_id', $artist->id)
|
||||
->with('episode')
|
||||
->with('podcast')
|
||||
->whereNotNull('approved_by')
|
||||
->orderBy('artworks.created_at', 'desc')
|
||||
->paginate($perPage = 92, $columns = ['*'], $pageName = 'artworks');
|
||||
$podcasts = Podcast::where('published', true)->with('episodes')->get();
|
||||
|
||||
@@ -26,7 +26,7 @@ class PasswordResetLinkController extends Controller
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'email' => ['required', 'email', 'exists:users,email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Podcast;
|
||||
use App\Models\Artworks;
|
||||
use App\Models\Episode;
|
||||
use App\Http\Resources\LatestEpisodeResource;
|
||||
|
||||
|
||||
class PodcastController extends Controller
|
||||
@@ -33,4 +34,26 @@ class PodcastController extends Controller
|
||||
'podcasts' => $podcasts,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the latest episode's chosen artwork for third party tools.
|
||||
*
|
||||
* @param $slug
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function latest_artwork(Request $request, $slug)
|
||||
{
|
||||
$podcast = Podcast::with('latestArtwork.artist')
|
||||
->where('slug', $slug)
|
||||
->where('published', true)
|
||||
->firstOrFail();
|
||||
$art = $podcast->latestArtwork;
|
||||
|
||||
return new LatestEpisodeResource($podcast);
|
||||
return response()->json([
|
||||
'episode_number' => optional($podcast->latestEpisode)->episode_number,
|
||||
'artwork' => $art,
|
||||
'artist' => optional($art)->artist,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
50
site/app/Http/Resources/LatestEpisodeResource.php
Normal file
50
site/app/Http/Resources/LatestEpisodeResource.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class LatestEpisodeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$podcast = $this->resource;
|
||||
$artwork = $podcast->latestArtwork;
|
||||
$episode = $artwork->episode;
|
||||
$artist = $artwork->artist;
|
||||
|
||||
$static = config('app.static_asset_url');
|
||||
$full = $static . '/artworks/' . $artwork->filename;
|
||||
$thumb = $static . '/thumbnails/' . $artwork->filename;
|
||||
$raw = (float) $episode->episode_number;
|
||||
if (fmod($raw, 1) === 0.0) {
|
||||
// no fractional part
|
||||
$episodeNumber = (int) $raw;
|
||||
} else {
|
||||
// keep one decimal place
|
||||
$episodeNumber = round($raw, 1);
|
||||
}
|
||||
return [
|
||||
'artist_name' => $artist->name,
|
||||
'artist_profile' => url('/artist/' . $artist->slug),
|
||||
'artist_avatar' => $artist->avatar(),
|
||||
|
||||
'artwork_full' => $full,
|
||||
'artwork_thumb' => $thumb,
|
||||
|
||||
'episode_title' => $episode->title,
|
||||
'episode_number' => $episodeNumber,
|
||||
'episode_date' => $episode->episode_date->format('Y-m-d'),
|
||||
'episode_mp3' => $episode->mp3,
|
||||
'podcast_title' => $podcast->name,
|
||||
'podcast_archive' => url('/podcasts/' . $podcast->slug),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user