feat: complete sell
This commit is contained in:
parent
b4375fbaa2
commit
bee5e05296
5 changed files with 144 additions and 38 deletions
|
|
@ -23,4 +23,12 @@ class BookInstanceRepository {
|
|||
) async {
|
||||
return await _apiClient.sendBook(book, owner, bal, price);
|
||||
}
|
||||
|
||||
Future<Result<void>> sellBooks(List<BookInstance> books) async {
|
||||
Map<String, double?> res = {};
|
||||
for (BookInstance instance in books) {
|
||||
res[instance.id.toString()] = instance.soldPrice;
|
||||
}
|
||||
return await _apiClient.sellBooks(res);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,6 +310,31 @@ class ApiClient {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Result<void>> sellBooks(Map<String, double?> books) async {
|
||||
final client = Client();
|
||||
try {
|
||||
final headers = await _getHeaders({"Content-Type": "application/json"});
|
||||
debugPrint("\n\n\n\nMAP: $books\n\n\n\n");
|
||||
final body = jsonEncode(books);
|
||||
debugPrint("\n\n\n\nSENT: $body\n\n\n\n");
|
||||
final response = await client.post(
|
||||
Uri.parse("https://$apiBasePath/book_instance/sell/bulk"),
|
||||
headers: headers,
|
||||
body: body,
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
return Result.ok(response.statusCode);
|
||||
} else {
|
||||
throw "Unknown error";
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("\n\n\n\nERROR : ${e.toString()}\n\n\n\n");
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Result<BookInstance>> sendBook(
|
||||
Book book,
|
||||
Owner owner,
|
||||
|
|
|
|||
Reference in a new issue