fix: continuing error managment and documentation
This commit is contained in:
parent
59e1c2558c
commit
dad000a1b9
24 changed files with 389 additions and 182 deletions
|
|
@ -5,6 +5,7 @@ import 'package:seshat/data/services/websocket_client.dart';
|
|||
import 'package:seshat/domain/models/owner.dart';
|
||||
import 'package:seshat/utils/result.dart';
|
||||
|
||||
/// Repository to manage [Owner]
|
||||
class OwnerRepository {
|
||||
OwnerRepository({
|
||||
required ApiClient apiClient,
|
||||
|
|
@ -14,18 +15,25 @@ class OwnerRepository {
|
|||
|
||||
final ApiClient _apiClient;
|
||||
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!);
|
||||
/// [StreamSubscription] to the [Stream<Owner>] for [_wsClient]
|
||||
late final StreamSubscription sub;
|
||||
|
||||
/// [List<Owner>] of owners, updated by [_wsClient]
|
||||
List<Owner>? _cachedOwners;
|
||||
|
||||
/// [Owner] of the current user
|
||||
Owner? _ownerOfUser;
|
||||
|
||||
/// [Owner] of the current user
|
||||
Future<Result<Owner>> get ownerOfUser async {
|
||||
if (_ownerOfUser != null) {
|
||||
return Result.ok(_ownerOfUser!);
|
||||
}
|
||||
final result = await _apiClient.getSectionOwner();
|
||||
final result = await _apiClient.getOwnerOfUser();
|
||||
switch (result) {
|
||||
case Ok():
|
||||
_sectionOwner = result.value;
|
||||
_ownerOfUser = result.value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -33,16 +41,17 @@ class OwnerRepository {
|
|||
return result;
|
||||
}
|
||||
|
||||
Future<Result<Owner>> getOwnerById(int id) async {
|
||||
/// Gets an [Owner] from its [ownerId]
|
||||
Future<Result<Owner>> getOwnerById(int ownerId) async {
|
||||
if (_cachedOwners != null) {
|
||||
final result1 = _cachedOwners!
|
||||
.where((owner) => owner.id == id)
|
||||
.where((owner) => owner.id == ownerId)
|
||||
.firstOrNull;
|
||||
if (result1 != null) {
|
||||
return Result.ok(result1);
|
||||
}
|
||||
}
|
||||
return await _apiClient.getOwnerById(id);
|
||||
return await _apiClient.getOwnerById(ownerId);
|
||||
}
|
||||
|
||||
/// Adds an [Owner] to the database, and gets the resulting [Owner].
|
||||
|
|
|
|||
Reference in a new issue