mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01: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);
|
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.
|
/// Get a work by ID.
|
||||||
|
|
@ -446,7 +446,7 @@ class MusicusClient {
|
||||||
));
|
));
|
||||||
|
|
||||||
final json = jsonDecode(response.body);
|
final json = jsonDecode(response.body);
|
||||||
return WorkInfo.fromJson(json);
|
return WorkInfo.fromJson(json, sync: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a work by ID.
|
/// Delete a work by ID.
|
||||||
|
|
@ -475,7 +475,9 @@ class MusicusClient {
|
||||||
));
|
));
|
||||||
|
|
||||||
final json = jsonDecode(response.body);
|
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.
|
/// Create or update a work.
|
||||||
|
|
@ -570,7 +572,7 @@ class MusicusClient {
|
||||||
));
|
));
|
||||||
|
|
||||||
final json = jsonDecode(response.body);
|
final json = jsonDecode(response.body);
|
||||||
return RecordingInfo.fromJson(json);
|
return RecordingInfo.fromJson(json, sync: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update a recording.
|
/// Create or update a recording.
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrReplace,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (person.sync) {
|
if (person.sync && !person.synced) {
|
||||||
await client.putPerson(person);
|
await client.putPerson(person);
|
||||||
await updatePerson(person.copyWith(synced: true));
|
await updatePerson(person.copyWith(synced: true));
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +164,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrReplace,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (instrument.sync) {
|
if (instrument.sync && !instrument.synced) {
|
||||||
await client.putInstrument(instrument);
|
await client.putInstrument(instrument);
|
||||||
await updateInstrument(instrument.copyWith(synced: true));
|
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 client.putWork(workInfo);
|
||||||
await into(works)
|
await into(works)
|
||||||
.insertOnConflictUpdate(workInfo.work.copyWith(synced: true));
|
.insertOnConflictUpdate(workInfo.work.copyWith(synced: true));
|
||||||
|
|
@ -343,7 +343,7 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrReplace,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ensemble.sync) {
|
if (ensemble.sync && !ensemble.synced) {
|
||||||
await client.putEnsemble(ensemble);
|
await client.putEnsemble(ensemble);
|
||||||
await updateEnsemble(ensemble.copyWith(synced: true));
|
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 client.putRecording(recordingInfo);
|
||||||
await into(recordings).insertOnConflictUpdate(
|
await into(recordings).insertOnConflictUpdate(
|
||||||
recordingInfo.recording.copyWith(synced: true));
|
recordingInfo.recording.copyWith(synced: true));
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,30 @@ class WorkInfo {
|
||||||
this.sections,
|
this.sections,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory WorkInfo.fromJson(Map<String, dynamic> json) => WorkInfo(
|
/// Deserialize work info from JSON.
|
||||||
work: Work.fromJson(json['work']),
|
///
|
||||||
|
/// 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']
|
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(),
|
.toList(),
|
||||||
composers:
|
|
||||||
json['composers'].map<Person>((j) => Person.fromJson(j)).toList(),
|
|
||||||
parts:
|
parts:
|
||||||
json['parts'].map<PartInfo>((j) => PartInfo.fromJson(j)).toList(),
|
json['parts'].map<PartInfo>((j) => PartInfo.fromJson(j)).toList(),
|
||||||
sections: json['sections']
|
sections: json['sections']
|
||||||
|
|
@ -111,13 +128,27 @@ class PerformanceInfo {
|
||||||
this.role,
|
this.role,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory PerformanceInfo.fromJson(Map<String, dynamic> json) =>
|
factory PerformanceInfo.fromJson(Map<String, dynamic> json,
|
||||||
|
{bool sync = false}) =>
|
||||||
PerformanceInfo(
|
PerformanceInfo(
|
||||||
person: json['person'] != null ? Person.fromJson(json['person']) : null,
|
person: json['person'] != null
|
||||||
ensemble: json['ensemble'] != null
|
? Person.fromJson(json['person']).copyWith(
|
||||||
? Ensemble.fromJson(json['ensemble'])
|
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,
|
: null,
|
||||||
role: json['role'] != null ? Instrument.fromJson(json['role']) : null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
|
@ -143,10 +174,22 @@ class RecordingInfo {
|
||||||
this.performances,
|
this.performances,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory RecordingInfo.fromJson(Map<String, dynamic> json) => RecordingInfo(
|
/// Deserialize recording info from JSON.
|
||||||
recording: Recording.fromJson(json['recording']),
|
///
|
||||||
|
/// 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']
|
performances: json['performances']
|
||||||
.map<PerformanceInfo>((j) => PerformanceInfo.fromJson(j))
|
.map<PerformanceInfo>(
|
||||||
|
(j) => PerformanceInfo.fromJson(j, sync: sync))
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue