mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
client: Catch exceptions in put methods
This commit is contained in:
parent
9d4554b67f
commit
37a1353297
1 changed files with 55 additions and 35 deletions
|
|
@ -28,16 +28,20 @@ class MusicusClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update a person.
|
/// Create or update a person.
|
||||||
///
|
///
|
||||||
/// Returns true, if the operation was successful.
|
/// Returns true, if the operation was successful.
|
||||||
Future<bool> putPerson(Person person) async {
|
Future<bool> putPerson(Person person) async {
|
||||||
final response = await _client.put(
|
try {
|
||||||
'$host/persons/${person.id}',
|
final response = await _client.put(
|
||||||
headers: {'Content-Type': 'application/json'},
|
'$host/persons/${person.id}',
|
||||||
body: jsonEncode(person.toJson()),
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
body: jsonEncode(person.toJson()),
|
||||||
|
);
|
||||||
|
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
|
} on Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a list of all available instruments.
|
/// Get a list of all available instruments.
|
||||||
|
|
@ -55,16 +59,20 @@ class MusicusClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update an instrument.
|
/// Create or update an instrument.
|
||||||
///
|
///
|
||||||
/// Returns true, if the operation was successful.
|
/// Returns true, if the operation was successful.
|
||||||
Future<bool> putInstrument(Instrument instrument) async {
|
Future<bool> putInstrument(Instrument instrument) async {
|
||||||
final response = await _client.put(
|
try {
|
||||||
'$host/instruments/${instrument.id}',
|
final response = await _client.put(
|
||||||
headers: {'Content-Type': 'application/json'},
|
'$host/instruments/${instrument.id}',
|
||||||
body: jsonEncode(instrument.toJson()),
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
body: jsonEncode(instrument.toJson()),
|
||||||
|
);
|
||||||
|
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
|
} on Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all works composed by the person with the ID [personId].
|
/// Get all works composed by the person with the ID [personId].
|
||||||
|
|
@ -89,16 +97,20 @@ class MusicusClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update a work.
|
/// Create or update a work.
|
||||||
///
|
///
|
||||||
/// Returns true, if the operation was successful.
|
/// Returns true, if the operation was successful.
|
||||||
Future<bool> putWork(WorkInfo workInfo) async {
|
Future<bool> putWork(WorkInfo workInfo) async {
|
||||||
final response = await _client.put(
|
try {
|
||||||
'$host/works/${workInfo.work.id}',
|
final response = await _client.put(
|
||||||
headers: {'Content-Type': 'application/json'},
|
'$host/works/${workInfo.work.id}',
|
||||||
body: jsonEncode(workInfo.toJson()),
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
body: jsonEncode(workInfo.toJson()),
|
||||||
|
);
|
||||||
|
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
|
} on Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a list of all ensembles.
|
/// Get a list of all ensembles.
|
||||||
|
|
@ -116,16 +128,20 @@ class MusicusClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update an ensemble.
|
/// Create or update an ensemble.
|
||||||
///
|
///
|
||||||
/// Returns true, if the operation was successful.
|
/// Returns true, if the operation was successful.
|
||||||
Future<bool> putEnsemble(Ensemble ensemble) async {
|
Future<bool> putEnsemble(Ensemble ensemble) async {
|
||||||
final response = await _client.put(
|
try {
|
||||||
'$host/ensembles/${ensemble.id}',
|
final response = await _client.put(
|
||||||
headers: {'Content-Type': 'application/json'},
|
'$host/ensembles/${ensemble.id}',
|
||||||
body: jsonEncode(ensemble.toJson()),
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
body: jsonEncode(ensemble.toJson()),
|
||||||
|
);
|
||||||
|
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
|
} on Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a recording by ID.
|
/// Get a recording by ID.
|
||||||
|
|
@ -136,16 +152,20 @@ class MusicusClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create or update a recording.
|
/// Create or update a recording.
|
||||||
///
|
///
|
||||||
/// Returns true, if the operation was successful.
|
/// Returns true, if the operation was successful.
|
||||||
Future<bool> putRecording(RecordingInfo recordingInfo) async {
|
Future<bool> putRecording(RecordingInfo recordingInfo) async {
|
||||||
final response = await _client.put(
|
try {
|
||||||
'$host/recordings/${recordingInfo.recording.id}',
|
final response = await _client.put(
|
||||||
headers: {'Content-Type': 'application/json'},
|
'$host/recordings/${recordingInfo.recording.id}',
|
||||||
body: jsonEncode(recordingInfo.toJson()),
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
body: jsonEncode(recordingInfo.toJson()),
|
||||||
|
);
|
||||||
|
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
|
} on Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the internal http client.
|
/// Close the internal http client.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue