diff --git a/client/lib/src/client.dart b/client/lib/src/client.dart index a6eb17d..c139008 100644 --- a/client/lib/src/client.dart +++ b/client/lib/src/client.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'package:http/http.dart' as http; import 'package:musicus_database/musicus_database.dart'; @@ -27,12 +28,16 @@ class MusicusClient { } /// Create or update a person. - Future putPerson(Person person) async { - await _client.put( + /// + /// Returns true, if the operation was successful. + Future putPerson(Person person) async { + final response = await _client.put( '$host/persons/${person.id}', headers: {'Content-Type': 'application/json'}, body: jsonEncode(person.toJson()), ); + + return response.statusCode == HttpStatus.ok; } /// Get a list of all available instruments. @@ -50,12 +55,16 @@ class MusicusClient { } /// Create or update an instrument. - Future putInstrument(Instrument instrument) async { - await _client.put( + /// + /// Returns true, if the operation was successful. + Future putInstrument(Instrument instrument) async { + final response = await _client.put( '$host/instruments/${instrument.id}', headers: {'Content-Type': 'application/json'}, body: jsonEncode(instrument.toJson()), ); + + return response.statusCode == HttpStatus.ok; } /// Get all works composed by the person with the ID [personId]. @@ -80,14 +89,16 @@ class MusicusClient { } /// Create or update a work. - /// - /// The new or updated work is returned. - Future putWork(WorkInfo workInfo) async { - await _client.put( + /// + /// Returns true, if the operation was successful. + Future putWork(WorkInfo workInfo) async { + final response = await _client.put( '$host/works/${workInfo.work.id}', headers: {'Content-Type': 'application/json'}, body: jsonEncode(workInfo.toJson()), ); + + return response.statusCode == HttpStatus.ok; } /// Get a list of all ensembles. @@ -105,12 +116,16 @@ class MusicusClient { } /// Create or update an ensemble. - Future putEnsemble(Ensemble ensemble) async { - await _client.put( + /// + /// Returns true, if the operation was successful. + Future putEnsemble(Ensemble ensemble) async { + final response = await _client.put( '$host/ensembles/${ensemble.id}', headers: {'Content-Type': 'application/json'}, body: jsonEncode(ensemble.toJson()), ); + + return response.statusCode == HttpStatus.ok; } /// Get a recording by ID. @@ -121,12 +136,16 @@ class MusicusClient { } /// Create or update a recording. - Future putRecording(RecordingInfo recordingInfo) async { - await _client.put( + /// + /// Returns true, if the operation was successful. + Future putRecording(RecordingInfo recordingInfo) async { + final response = await _client.put( '$host/recordings/${recordingInfo.recording.id}', headers: {'Content-Type': 'application/json'}, body: jsonEncode(recordingInfo.toJson()), ); + + return response.statusCode == HttpStatus.ok; } /// Close the internal http client.