Skip to content

Commit

Permalink
Replaced get of persons with expand=person on affiliations and person…
Browse files Browse the repository at this point in the history
…nels.

Refactored merge framework.
Should solve #77.
  • Loading branch information
kengu committed Sep 5, 2020
1 parent a98ba50 commit 3e9f8ec
Show file tree
Hide file tree
Showing 48 changed files with 859 additions and 656 deletions.
8 changes: 5 additions & 3 deletions lib/core/data/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,18 @@ class Api {
StackTrace stackTrace,
}) {
final resolved = body ?? response.body;
final conflict = response.statusCode == HttpStatus.conflict
// Chopper will return body with conflict json in response.error
? ConflictModel.fromJson(jsonDecode(response.error))
: null;
return ServiceResponse<T>(
conflict: conflict,
stackTrace: stackTrace,
statusCode: response.statusCode,
reasonPhrase: '${response.base.reasonPhrase}',
page: resolved is PagedList ? resolved.page : null,
body: resolved is PagedList ? resolved.items : resolved,
error: response.statusCode == HttpStatus.conflict
? ConflictModel.fromJson(jsonDecode(response.error))
: response.error,
error: response.statusCode == HttpStatus.conflict ? conflict.error : response.error,
);
}
}
Expand Down
16 changes: 16 additions & 0 deletions lib/core/data/services/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class ServiceResponse<T> extends Equatable {
bool get is404 => statusCode == HttpStatus.notFound;
bool get is409 => statusCode == HttpStatus.conflict;
bool get is500 => statusCode == HttpStatus.internalServerError;
bool get is503 => statusCode == HttpStatus.serviceUnavailable;

@override
String toString() {
Expand All @@ -213,6 +214,21 @@ class ServiceException implements Exception {
final StackTrace stackTrace;
final ServiceResponse response;

bool get is200 => response.is200;
bool get is201 => response.is201;
bool get is202 => response.is202;
bool get is204 => response.is204;
bool get is206 => response.is206;
bool get is400 => response.is400;
bool get is401 => response.is401;
bool get is403 => response.is403;
bool get is404 => response.is404;
bool get is409 => response.is409;
bool get is500 => response.is500;
bool get is503 => response.is503;

ConflictModel get conflict => response.conflict;

@override
String toString() {
return '$runtimeType: $error, response: $response, stackTrace: $stackTrace';
Expand Down
9 changes: 6 additions & 3 deletions lib/core/data/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,16 @@ class StorageState<T> {
);

bool get isError => error != null;
bool get isConflict => error is ConflictModel;

bool get isCreated => StorageStatus.created == status;
bool get isChanged => StorageStatus.updated == status;
bool get isDeleted => StorageStatus.deleted == status;

bool get shouldLoad => !(isCreated && isLocal);

ConflictModel get conflict => isConflict ? error as ConflictModel : null;

StorageState<T> failed(Object error) => StorageState<T>(
value: value,
status: status,
Expand All @@ -301,12 +304,12 @@ class StorageState<T> {
error: null,
);

StorageState<T> apply(T value, {@required bool isRemote}) {
StorageState<T> apply(T value, {@required bool isRemote, Object error}) {
switch (status) {
case StorageStatus.created:
return StorageState(
value: value,
error: error,
error: error ?? this.error,
isRemote: isRemote ?? _isRemote,
status: _isRemote
// If current is remote,
Expand Down Expand Up @@ -356,7 +359,7 @@ class StorageTransition<T> {
bool get isRemote => to?.isRemote ?? false;
bool get isChanged => to?.isChanged ?? false;
bool get isDeleted => to?.isDeleted ?? false;
bool get isConflict => to?.error is ConflictModel;
bool get isConflict => to?.isConflict ?? false;

ConflictModel get conflict => isConflict ? to.error as ConflictModel : null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/domain/models/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JsonUtils {
}) {
assert(
!(retain?.isNotEmpty == true && remove?.isNotEmpty == true),
'only use retain or remove',
'Only use retain or remove',
);
final json = value.toJson();
if (retain?.isNotEmpty == true) {
Expand Down
Loading

0 comments on commit 3e9f8ec

Please sign in to comment.