mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-25 19:27:24 +02:00
client: Set sync status for works and recordings
This commit is contained in:
parent
d566e6c473
commit
6c7891de14
3 changed files with 67 additions and 22 deletions
|
|
@ -436,7 +436,7 @@ class MusicusClient {
|
|||
));
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
return json.map<WorkInfo>((j) => WorkInfo.fromJson(j)).toList();
|
||||
return json.map<WorkInfo>((j) => WorkInfo.fromJson(j, sync: true)).toList();
|
||||
}
|
||||
|
||||
/// Get a work by ID.
|
||||
|
|
@ -446,7 +446,7 @@ class MusicusClient {
|
|||
));
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
return WorkInfo.fromJson(json);
|
||||
return WorkInfo.fromJson(json, sync: true);
|
||||
}
|
||||
|
||||
/// Delete a work by ID.
|
||||
|
|
@ -475,7 +475,9 @@ class MusicusClient {
|
|||
));
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
return json.map<RecordingInfo>((j) => RecordingInfo.fromJson(j)).toList();
|
||||
return json
|
||||
.map<RecordingInfo>((j) => RecordingInfo.fromJson(j, sync: true))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Create or update a work.
|
||||
|
|
@ -570,7 +572,7 @@ class MusicusClient {
|
|||
));
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
return RecordingInfo.fromJson(json);
|
||||
return RecordingInfo.fromJson(json, sync: true);
|
||||
}
|
||||
|
||||
/// Create or update a recording.
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
|
||||
if (person.sync) {
|
||||
if (person.sync && !person.synced) {
|
||||
await client.putPerson(person);
|
||||
await updatePerson(person.copyWith(synced: true));
|
||||
}
|
||||
|
|
@ -164,7 +164,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
|
||||
if (instrument.sync) {
|
||||
if (instrument.sync && !instrument.synced) {
|
||||
await client.putInstrument(instrument);
|
||||
await updateInstrument(instrument.copyWith(synced: true));
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
if (workInfo.work.sync) {
|
||||
if (workInfo.work.sync && !workInfo.work.synced) {
|
||||
await client.putWork(workInfo);
|
||||
await into(works)
|
||||
.insertOnConflictUpdate(workInfo.work.copyWith(synced: true));
|
||||
|
|
@ -343,7 +343,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
|
||||
if (ensemble.sync) {
|
||||
if (ensemble.sync && !ensemble.synced) {
|
||||
await client.putEnsemble(ensemble);
|
||||
await updateEnsemble(ensemble.copyWith(synced: true));
|
||||
}
|
||||
|
|
@ -397,7 +397,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
|||
}
|
||||
});
|
||||
|
||||
if (recordingInfo.recording.sync) {
|
||||
if (recordingInfo.recording.sync && !recordingInfo.recording.synced) {
|
||||
await client.putRecording(recordingInfo);
|
||||
await into(recordings).insertOnConflictUpdate(
|
||||
recordingInfo.recording.copyWith(synced: true));
|
||||
|
|
|
|||
|
|
@ -67,13 +67,30 @@ class WorkInfo {
|
|||
this.sections,
|
||||
});
|
||||
|
||||
factory WorkInfo.fromJson(Map<String, dynamic> json) => WorkInfo(
|
||||
work: Work.fromJson(json['work']),
|
||||
/// Deserialize work info from JSON.
|
||||
///
|
||||
/// If [sync] is set to true, all contained items will have their sync
|
||||
/// property set to true.
|
||||
// TODO: Local versions should not be overriden, if their sync property is
|
||||
// set to false.
|
||||
factory WorkInfo.fromJson(Map<String, dynamic> json, {bool sync = false}) =>
|
||||
WorkInfo(
|
||||
work: Work.fromJson(json['work']).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
),
|
||||
instruments: json['instruments']
|
||||
.map<Instrument>((j) => Instrument.fromJson(j))
|
||||
.map<Instrument>((j) => Instrument.fromJson(j).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
))
|
||||
.toList(),
|
||||
composers: json['composers']
|
||||
.map<Person>((j) => Person.fromJson(j).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
))
|
||||
.toList(),
|
||||
composers:
|
||||
json['composers'].map<Person>((j) => Person.fromJson(j)).toList(),
|
||||
parts:
|
||||
json['parts'].map<PartInfo>((j) => PartInfo.fromJson(j)).toList(),
|
||||
sections: json['sections']
|
||||
|
|
@ -111,13 +128,27 @@ class PerformanceInfo {
|
|||
this.role,
|
||||
});
|
||||
|
||||
factory PerformanceInfo.fromJson(Map<String, dynamic> json) =>
|
||||
factory PerformanceInfo.fromJson(Map<String, dynamic> json,
|
||||
{bool sync = false}) =>
|
||||
PerformanceInfo(
|
||||
person: json['person'] != null ? Person.fromJson(json['person']) : null,
|
||||
ensemble: json['ensemble'] != null
|
||||
? Ensemble.fromJson(json['ensemble'])
|
||||
person: json['person'] != null
|
||||
? Person.fromJson(json['person']).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
)
|
||||
: null,
|
||||
ensemble: json['ensemble'] != null
|
||||
? Ensemble.fromJson(json['ensemble']).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
)
|
||||
: null,
|
||||
role: json['role'] != null
|
||||
? Instrument.fromJson(json['role']).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
)
|
||||
: null,
|
||||
role: json['role'] != null ? Instrument.fromJson(json['role']) : null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
|
|
@ -143,10 +174,22 @@ class RecordingInfo {
|
|||
this.performances,
|
||||
});
|
||||
|
||||
factory RecordingInfo.fromJson(Map<String, dynamic> json) => RecordingInfo(
|
||||
recording: Recording.fromJson(json['recording']),
|
||||
/// Deserialize recording info from JSON.
|
||||
///
|
||||
/// If [sync] is set to true, all contained items will have their sync
|
||||
/// property set to true.
|
||||
// TODO: Local versions should not be overriden, if their sync property is
|
||||
// set to false.
|
||||
factory RecordingInfo.fromJson(Map<String, dynamic> json,
|
||||
{bool sync = false}) =>
|
||||
RecordingInfo(
|
||||
recording: Recording.fromJson(json['recording']).copyWith(
|
||||
sync: sync,
|
||||
synced: sync,
|
||||
),
|
||||
performances: json['performances']
|
||||
.map<PerformanceInfo>((j) => PerformanceInfo.fromJson(j))
|
||||
.map<PerformanceInfo>(
|
||||
(j) => PerformanceInfo.fromJson(j, sync: sync))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue