Split AlbumApplicationResponse into a Local/External hierarchy

AlbumApplicationResponse used to carry YouTubeAlbumId/ThumbnailUrl as
two always-present-but-usually-null fields for the sake of a single
flat shape. Since one of these fields IS genuinely exclusive to
external albums, an inheritance split reads better than the flattened
shape: AlbumApplicationResponse now holds only the fields shared by
every album, and ExternalAlbumApplicationResponse adds ExternalId
(renamed from YouTubeAlbumId, matching the source-generalized naming
used everywhere else) and ThumbnailUrl.

[JsonPolymorphic]/[JsonDerivedType] are required here, not optional:
without them System.Text.Json serializes strictly by the declared CLR
type at each call site (both the bare return type and nested inside
AlbumSearchItemResponse.Album), so an ExternalAlbumApplicationResponse
instance would silently lose its extra fields on the wire. This also
gives every response a "source" discriminator field for free,
consistent with AlbumSearchItemResponse.Source, and the generated
OpenAPI schema now models it as a proper oneOf/discriminator instead
of nullable fields.
This commit is contained in:
2026-09-10 19:19:31 +02:00
parent 478b90d75c
commit 7ae6c0a7a2
4 changed files with 71 additions and 24 deletions
+6 -4
View File
@@ -155,7 +155,9 @@
></div>
<div class="animate-enter relative flex flex-col gap-2 sm:gap-2.5">
<p class="text-sm tracking-[0.14em] text-fg-2 uppercase sm:text-base">{data.greeting}</p>
<h1 class="font-display text-3xl leading-[1.05] font-semibold tracking-tight text-fg sm:text-6xl">
<h1
class="font-display text-3xl leading-[1.05] font-semibold tracking-tight text-fg sm:text-6xl"
>
Tu música. Sin límites.
</h1>
</div>
@@ -214,15 +216,15 @@
<Rail>
{#each albums as album, i (album.id)}
<a
href={album.youTubeAlbumId
? `/albums/external/youtube/${album.youTubeAlbumId}`
href={album.source === 'YouTube'
? `/albums/external/youtube/${album.externalId}`
: `/albums/${album.id}`}
class="group/card animate-enter block w-42 shrink-0 rounded-art focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-bg focus-visible:outline-none"
style="animation-delay:{Math.min(i, 10) * 45}ms"
oncontextmenu={(e) => openAlbumMenu(e, album.id)}
>
<div class="relative">
{#if album.thumbnailUrl}
{#if album.source === 'YouTube' && album.thumbnailUrl}
<Cover
trackId={album.id}
src={album.thumbnailUrl}