feat(flutter/models): User, ArtistRef, AlbumRef, TrackRef, HomeData
Field names mirror web/src/lib/api/types.ts and the server JSON shape (internal/api/types.go's HomePayload). Hand-written DTOs per spec section 10 -- codegen revisits at ~30 models. Adopts server contract over plan-body mock: - cover_url (not cover_art_url) for artist/album refs - duration_sec (not duration_ms) for albums and tracks - stream_url, disc_number on TrackRef - sort_name/album_count on ArtistRef; sort_title/year/track_count on AlbumRef HomeData section keys match server: recently_added_albums, rediscover_albums, rediscover_artists, most_played_tracks, last_played_artists.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Mirrors internal/api/types.go AlbumRef and web/src/lib/api/types.ts.
|
||||
//
|
||||
// `cover_url` (NOT cover_art_url) and `duration_sec` (NOT duration_ms) match
|
||||
// the server contract. `year` is omitempty on the server so we keep it
|
||||
// nullable. CoverURL is non-null but may be "" — UI branches on isEmpty.
|
||||
class AlbumRef {
|
||||
const AlbumRef({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.artistId,
|
||||
this.sortTitle = '',
|
||||
this.artistName = '',
|
||||
this.year,
|
||||
this.trackCount = 0,
|
||||
this.durationSec = 0,
|
||||
this.coverUrl = '',
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String sortTitle;
|
||||
final String artistId;
|
||||
final String artistName;
|
||||
final int? year;
|
||||
final int trackCount;
|
||||
final int durationSec;
|
||||
final String coverUrl;
|
||||
|
||||
factory AlbumRef.fromJson(Map<String, dynamic> j) => AlbumRef(
|
||||
id: j['id'] as String,
|
||||
title: j['title'] as String,
|
||||
sortTitle: j['sort_title'] as String? ?? '',
|
||||
artistId: j['artist_id'] as String,
|
||||
artistName: j['artist_name'] as String? ?? '',
|
||||
year: (j['year'] as num?)?.toInt(),
|
||||
trackCount: (j['track_count'] as num?)?.toInt() ?? 0,
|
||||
durationSec: (j['duration_sec'] as num?)?.toInt() ?? 0,
|
||||
coverUrl: j['cover_url'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user