Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Removed nullable api entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlessenich committed Mar 14, 2024
1 parent 0557893 commit cfa4cb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions lib/src/api/restrr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ abstract class Restrr {
void on<T extends RestrrEvent>(Type type, void Function(T) func);

/// Retrieves the currently authenticated user.
Future<User?> retrieveSelf({bool forceRetrieve = false});
Future<User> retrieveSelf({bool forceRetrieve = false});

/// Deletes the current session, effectively logging out the user.
///
Future<bool> deleteCurrentSession();

Future<List<Currency>?> retrieveAllCurrencies({bool forceRetrieve = false});
Future<List<Currency>> retrieveAllCurrencies({bool forceRetrieve = false});

/* Sessions */

Future<Session?> retrieveCurrentSession({bool forceRetrieve = false});
Future<Session> retrieveCurrentSession({bool forceRetrieve = false});

Future<Session?> retrieveSessionById(Id id, {bool forceRetrieve = false});
Future<Session> retrieveSessionById(Id id, {bool forceRetrieve = false});

Future<bool> deleteAllSessions();

/* Currencies */

Future<Currency?> createCurrency(
Future<Currency> createCurrency(
{required String name, required String symbol, required String isoCode, required int decimalPlaces});

Future<Currency?> retrieveCurrencyById(Id id, {bool forceRetrieve = false});
Future<Currency> retrieveCurrencyById(Id id, {bool forceRetrieve = false});
}
19 changes: 10 additions & 9 deletions lib/src/internal/restrr_impl.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:restrr/src/api/events/session_delete_event.dart';
import 'package:restrr/src/internal/requests/responses/rest_response.dart';
import 'package:restrr/src/internal/requests/restrr_errors.dart';
import 'package:restrr/src/internal/utils/request_utils.dart';

import '../../restrr.dart';
Expand Down Expand Up @@ -63,7 +61,7 @@ class RestrrImpl implements Restrr {
/* Sessions */

@override
Future<Session?> retrieveCurrentSession({bool forceRetrieve = false}) async {
Future<Session> retrieveCurrentSession({bool forceRetrieve = false}) async {
return RequestUtils.getOrRetrieveSingle(
key: session.id,
cacheView: sessionCache,
Expand All @@ -73,7 +71,7 @@ class RestrrImpl implements Restrr {
}

@override
Future<Session?> retrieveSessionById(Id id, {bool forceRetrieve = false}) async {
Future<Session> retrieveSessionById(Id id, {bool forceRetrieve = false}) async {
return RequestUtils.getOrRetrieveSingle(
key: id,
cacheView: sessionCache,
Expand All @@ -91,7 +89,7 @@ class RestrrImpl implements Restrr {
/* Currencies */

@override
Future<List<Currency>?> retrieveAllCurrencies({bool forceRetrieve = false}) async {
Future<List<Currency>> retrieveAllCurrencies({bool forceRetrieve = false}) async {
return RequestUtils.getOrRetrieveMulti(
batchCache: currencyBatchCache,
compiledRoute: CurrencyRoutes.getAll.compile(),
Expand All @@ -100,20 +98,23 @@ class RestrrImpl implements Restrr {
}

@override
Future<Currency?> createCurrency(
Future<Currency> createCurrency(
{required String name, required String symbol, required String isoCode, required int decimalPlaces}) async {
final response = await requestHandler
final RestResponse<Currency> response = await requestHandler
.apiRequest(route: CurrencyRoutes.create.compile(), mapper: (json) => entityBuilder.buildCurrency(json), body: {
'name': name,
'symbol': symbol,
'iso_code': isoCode,
'decimal_places': decimalPlaces,
});
return response.data;
if (response.hasError) {
throw response.error!;
}
return response.data!;
}

@override
Future<Currency?> retrieveCurrencyById(Id id, {bool forceRetrieve = false}) async {
Future<Currency> retrieveCurrencyById(Id id, {bool forceRetrieve = false}) async {
return RequestUtils.getOrRetrieveSingle(
key: id,
cacheView: currencyCache,
Expand Down

0 comments on commit cfa4cb4

Please sign in to comment.