feat: start working on sell
This commit is contained in:
parent
f378c8c0be
commit
1803a2b119
8 changed files with 94 additions and 31 deletions
|
|
@ -16,6 +16,22 @@ class OwnerRepository {
|
|||
final WebsocketClient _wsClient;
|
||||
late final StreamSubscription sub;
|
||||
List<Owner>? _cachedOwners;
|
||||
Owner? _sectionOwner;
|
||||
|
||||
Future<Result<Owner>> get sectionOwner async {
|
||||
if (_sectionOwner != null) {
|
||||
return Result.ok(_sectionOwner!);
|
||||
}
|
||||
final result = await _apiClient.getSectionOwner();
|
||||
switch (result) {
|
||||
case Ok():
|
||||
_sectionOwner = result.value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Adds an [Owner] to the database, and gets the resulting [Owner].
|
||||
Future<Result<Owner>> addOwner(
|
||||
|
|
|
|||
|
|
@ -304,6 +304,27 @@ class ApiClient {
|
|||
* ====================
|
||||
*/
|
||||
|
||||
Future<Result<Owner>> getSectionOwner() async {
|
||||
final client = Client();
|
||||
try {
|
||||
final headers = await _getHeaders();
|
||||
final response = await client.get(
|
||||
Uri.parse("https://$apiBasePath/owner/self"),
|
||||
headers: headers,
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body);
|
||||
return Result.ok(Owner.fromJSON(json));
|
||||
} else {
|
||||
throw "Unknown error";
|
||||
}
|
||||
} catch (e) {
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Call on `/owners` to get a list of all [Owner]s
|
||||
Future<Result<List<Owner>>> getOwners() async {
|
||||
final client = Client();
|
||||
|
|
|
|||
Reference in a new issue