mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
database: Unify work and recording API
This commit is contained in:
parent
c93ebf17a0
commit
0fc0c933ac
7 changed files with 116 additions and 201 deletions
|
|
@ -98,31 +98,24 @@ class _RecordingEditorState extends State<RecordingEditor> {
|
|||
FlatButton(
|
||||
child: Text('DONE'),
|
||||
onPressed: () async {
|
||||
final recording = Recording(
|
||||
id: widget.recording?.id ?? generateId(),
|
||||
work: workInfo.work.id,
|
||||
comment: commentController.text,
|
||||
final recordingInfo = RecordingInfo(
|
||||
recording: Recording(
|
||||
id: widget.recording?.id ?? generateId(),
|
||||
work: workInfo.work.id,
|
||||
comment: commentController.text,
|
||||
),
|
||||
performances: performanceInfos,
|
||||
);
|
||||
|
||||
final performances = performanceInfos
|
||||
.map((m) => Performance(
|
||||
recording: recording.id,
|
||||
person: m.person?.id,
|
||||
ensemble: m.ensemble?.id,
|
||||
role: m.role?.id,
|
||||
))
|
||||
.toList();
|
||||
await backend.client.putRecording(recordingInfo);
|
||||
|
||||
final recordingInfo =
|
||||
await backend.client.putRecording(RecordingData(
|
||||
recording: recording,
|
||||
performances: performances,
|
||||
));
|
||||
|
||||
Navigator.pop(context, RecordingSelectorResult(
|
||||
workInfo: workInfo,
|
||||
recordingInfo: recordingInfo,
|
||||
));
|
||||
Navigator.pop(
|
||||
context,
|
||||
RecordingSelectorResult(
|
||||
workInfo: workInfo,
|
||||
recordingInfo: recordingInfo,
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
|
|
|||
|
|
@ -54,62 +54,8 @@ class _TracksEditorState extends State<TracksEditor> {
|
|||
// We need to copy all information associated with this track we
|
||||
// got by asking the server to our local database. For now, we
|
||||
// will just override everything that we already had previously.
|
||||
|
||||
// TODO: Think about efficiency.
|
||||
backend.db.transaction(() async {
|
||||
for (final composer in workInfo.composers) {
|
||||
await backend.db.updatePerson(composer);
|
||||
}
|
||||
|
||||
for (final instrument in workInfo.instruments) {
|
||||
await backend.db.updateInstrument(instrument);
|
||||
}
|
||||
|
||||
for (final partInfo in workInfo.parts) {
|
||||
for (final instrument in partInfo.instruments) {
|
||||
await backend.db.updateInstrument(instrument);
|
||||
}
|
||||
}
|
||||
|
||||
await backend.db.updateWork(WorkData(
|
||||
data: WorkPartData(
|
||||
work: workInfo.work,
|
||||
instrumentIds:
|
||||
workInfo.instruments.map((i) => i.id).toList(),
|
||||
),
|
||||
partData: workInfo.parts
|
||||
.map((p) => WorkPartData(
|
||||
work: p.work,
|
||||
instrumentIds:
|
||||
p.instruments.map((i) => i.id).toList(),
|
||||
))
|
||||
.toList(),
|
||||
));
|
||||
|
||||
for (final performance in recordingInfo.performances) {
|
||||
if (performance.person != null) {
|
||||
await backend.db.updatePerson(performance.person);
|
||||
}
|
||||
if (performance.ensemble != null) {
|
||||
await backend.db.updateEnsemble(performance.ensemble);
|
||||
}
|
||||
if (performance.role != null) {
|
||||
await backend.db.updateInstrument(performance.role);
|
||||
}
|
||||
}
|
||||
|
||||
await backend.db.updateRecording(RecordingData(
|
||||
recording: recordingInfo.recording,
|
||||
performances: recordingInfo.performances
|
||||
.map((p) => Performance(
|
||||
recording: recordingInfo.recording.id,
|
||||
person: p.person?.id,
|
||||
ensemble: p.ensemble?.id,
|
||||
role: p.role?.id,
|
||||
))
|
||||
.toList(),
|
||||
));
|
||||
});
|
||||
backend.db.updateWork(workInfo);
|
||||
backend.db.updateRecording(recordingInfo);
|
||||
|
||||
backend.ml.addTracks(parentId, tracks);
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class _PartTileState extends State<PartTile> {
|
|||
}
|
||||
|
||||
/// Screen for editing a work.
|
||||
///
|
||||
///
|
||||
/// If the user is finished editing, the result will be returned as a [WorkInfo]
|
||||
/// object.
|
||||
class WorkEditor extends StatefulWidget {
|
||||
|
|
@ -299,19 +299,10 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
onPressed: () async {
|
||||
final workId = widget.work?.id ?? generateId();
|
||||
|
||||
final data = WorkPartData(
|
||||
work: Work(
|
||||
id: workId,
|
||||
title: titleController.text,
|
||||
composer: composer?.id,
|
||||
),
|
||||
instrumentIds: instruments.map((i) => i.id).toList(),
|
||||
);
|
||||
|
||||
final List<WorkPartData> partData = [];
|
||||
List<PartInfo> partInfos = [];
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
final part = parts[i];
|
||||
partData.add(WorkPartData(
|
||||
partInfos.add(PartInfo(
|
||||
work: Work(
|
||||
id: generateId(),
|
||||
title: part.titleController.text,
|
||||
|
|
@ -319,14 +310,25 @@ class _WorkEditorState extends State<WorkEditor> {
|
|||
partOf: workId,
|
||||
partIndex: i,
|
||||
),
|
||||
instrumentIds: part.instruments.map((i) => i.id).toList(),
|
||||
instruments: part.instruments,
|
||||
composer: part.composer,
|
||||
));
|
||||
}
|
||||
|
||||
final workInfo = await backend.client.putWork(WorkData(
|
||||
data: data,
|
||||
partData: partData,
|
||||
));
|
||||
final workInfo = WorkInfo(
|
||||
work: Work(
|
||||
id: workId,
|
||||
title: titleController.text,
|
||||
composer: composer?.id,
|
||||
),
|
||||
instruments: instruments,
|
||||
// TODO: Theoretically, this should include all composers from
|
||||
// the parts.
|
||||
composers: [composer],
|
||||
parts: partInfos,
|
||||
);
|
||||
|
||||
await backend.client.putWork(workInfo);
|
||||
|
||||
Navigator.pop(context, workInfo);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue