Sheet model: adapt to reduced data model of server

This commit is contained in:
2026-02-06 16:47:04 +01:00
parent d0fd96a2f5
commit d01e1384d4

View File

@@ -5,36 +5,31 @@
class Sheet {
final String uuid;
String name;
String composerUuid;
String composerName;
String composer;
DateTime updatedAt;
Sheet({
required this.uuid,
required this.name,
required this.composerUuid,
required this.composerName,
required this.composer,
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(),
uuid: json['uuid'],
name: json['title'],
composerUuid: json['composer_uuid']?.toString() ?? '',
composerName: composer?['name'] ?? 'Unknown',
composer: json['composer'],
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(),
};
'uuid': uuid,
'title': name,
'composer': composer,
'updated_at': updatedAt.toIso8601String(),
};
}