Sheet model: adapt to reduced data model of server
This commit is contained in:
@@ -5,36 +5,31 @@
|
|||||||
class Sheet {
|
class Sheet {
|
||||||
final String uuid;
|
final String uuid;
|
||||||
String name;
|
String name;
|
||||||
String composerUuid;
|
String composer;
|
||||||
String composerName;
|
|
||||||
DateTime updatedAt;
|
DateTime updatedAt;
|
||||||
|
|
||||||
Sheet({
|
Sheet({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.composerUuid,
|
required this.composer,
|
||||||
required this.composerName,
|
|
||||||
required this.updatedAt,
|
required this.updatedAt,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates a [Sheet] from a JSON map returned by the API.
|
/// Creates a [Sheet] from a JSON map returned by the API.
|
||||||
factory Sheet.fromJson(Map<String, dynamic> json) {
|
factory Sheet.fromJson(Map<String, dynamic> json) {
|
||||||
final composer = json['composer'] as Map<String, dynamic>?;
|
|
||||||
return Sheet(
|
return Sheet(
|
||||||
uuid: json['uuid'].toString(),
|
uuid: json['uuid'],
|
||||||
name: json['title'],
|
name: json['title'],
|
||||||
composerUuid: json['composer_uuid']?.toString() ?? '',
|
composer: json['composer'],
|
||||||
composerName: composer?['name'] ?? 'Unknown',
|
|
||||||
updatedAt: DateTime.parse(json['updated_at']),
|
updatedAt: DateTime.parse(json['updated_at']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts this sheet to a JSON map for API requests.
|
/// Converts this sheet to a JSON map for API requests.
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
'title': name,
|
'title': name,
|
||||||
'composer_uuid': composerUuid,
|
'composer': composer,
|
||||||
'composer_name': composerName,
|
'updated_at': updatedAt.toIso8601String(),
|
||||||
'updated_at': updatedAt.toIso8601String(),
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user