Complete refactor to clean up project
This commit is contained in:
40
lib/core/models/sheet.dart
Normal file
40
lib/core/models/sheet.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
/// Data model representing a sheet music document.
|
||||
///
|
||||
/// A [Sheet] contains metadata about a piece of sheet music,
|
||||
/// including its title, composer information, and timestamps.
|
||||
class Sheet {
|
||||
final String uuid;
|
||||
String name;
|
||||
String composerUuid;
|
||||
String composerName;
|
||||
DateTime updatedAt;
|
||||
|
||||
Sheet({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.composerUuid,
|
||||
required this.composerName,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
/// Creates a [Sheet] from a JSON map returned by the API.
|
||||
factory Sheet.fromJson(Map<String, dynamic> json) {
|
||||
final composer = json['composer'] as Map<String, dynamic>?;
|
||||
return Sheet(
|
||||
uuid: json['uuid'].toString(),
|
||||
name: json['title'],
|
||||
composerUuid: json['composer_uuid']?.toString() ?? '',
|
||||
composerName: composer?['name'] ?? 'Unknown',
|
||||
updatedAt: DateTime.parse(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
/// Converts this sheet to a JSON map for API requests.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'uuid': uuid,
|
||||
'title': name,
|
||||
'composer_uuid': composerUuid,
|
||||
'composer_name': composerName,
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user