feat: added authentification and redirection

This commit is contained in:
Alzalia 2025-08-08 01:03:48 +02:00
parent 1c9c5ce5fe
commit ef641d4023
24 changed files with 731 additions and 173 deletions

View file

@ -14,32 +14,42 @@ class OwnerRepository {
final ApiClient _apiClient;
final WebsocketClient _wsClient;
List<Owner>? _cachedData;
List<Owner>? _cachedOwners;
Future<Result<Owner>> postOwner(
String firstName,
String lastName,
String contact,
) async {
return Result.ok(
Owner(firstName: firstName, lastName: lastName, contact: contact, id: 50),
);
}
Future<Result<List<Owner>>> getOwners() async {
if (_cachedData == null) {
if (_cachedOwners == null) {
final result = await _apiClient.getOwners();
if (result is Ok<List<Owner>>) {
_cachedData = result.value;
_cachedOwners = result.value;
}
return result;
} else {
return Result.ok(_cachedData!);
return Result.ok(_cachedOwners!);
}
}
Stream<Owner> liveOwners() async* {
await for (String data in _wsClient.connect()) {
await for (String data in await _wsClient.connect()) {
Map<String, dynamic> decodedData = jsonDecode(
data,
).cast<Map<String, dynamic>>();
Owner owner = Owner.fromJSON(decodedData);
if (_cachedData == null) {
getOwners();
if (_cachedOwners == null) {
await getOwners();
} else {
_cachedData!.add(owner);
_cachedOwners!.add(owner);
yield* Stream.value(owner);
}
}