Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ coverage:
status:
project:
default:
target: 59%
target: 50%
threshold: 1%
48 changes: 48 additions & 0 deletions lib/data/network/data_source/cores_network_data_source.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter_bloc_app_template/data/network/api_result.dart';
import 'package:flutter_bloc_app_template/data/network/model/core/network_core_model.dart';
import 'package:flutter_bloc_app_template/data/network/service/cores/cores_service.dart';

abstract class CoresDataSource {
Future<ApiResult<List<NetworkCoreModel>>> getCores({
bool? hasId = true,
int? limit,
int? offset,
});

Future<ApiResult<NetworkCoreModel>> getCore(String coreSerial);
}

class CoresNetworkDataSource implements CoresDataSource {
CoresNetworkDataSource(this._service);

final CoresService _service;

@override
Future<ApiResult<List<NetworkCoreModel>>> getCores({
bool? hasId = true,
int? limit,
int? offset,
}) async {
try {
final list = await _service.fetchCores(
hasId: hasId,
limit: limit,
offset: offset,
);

return ApiResult.success(list);
} catch (e) {
return Future.value(ApiResult.error(e.toString()));
}
}

@override
Future<ApiResult<NetworkCoreModel>> getCore(String coreSerial) async {
try {
final result = await _service.fetchCore(coreSerial);
return ApiResult.success(result);
} catch (e) {
return Future.value(ApiResult.error(e.toString()));
}
}
}
32 changes: 24 additions & 8 deletions lib/data/network/model/core/network_core_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@ part 'network_core_model.g.dart';
abstract class NetworkCoreModel with _$NetworkCoreModel {
const factory NetworkCoreModel({
@JsonKey(name: 'core_serial') String? coreSerial,
int? flight,
int? block,
bool? gridfins,
bool? legs,
bool? reused,
@JsonKey(name: 'land_success') bool? landSuccess,
@JsonKey(name: 'landing_intent') bool? landingIntent,
@JsonKey(name: 'landing_type') String? landingType,
@JsonKey(name: 'landing_vehicle') String? landingVehicle,
String? status,
@JsonKey(name: 'original_launch') String? originalLaunch,
@JsonKey(name: 'original_launch_unix') int? originalLaunchUnix,
List<NetworkMission>? missions,
@JsonKey(name: 'reuse_count') int? reuseCount,
@JsonKey(name: 'rtls_attempts') int? rtlsAttempts,
@JsonKey(name: 'rtls_landings') int? rtlsLandings,
@JsonKey(name: 'asds_attempts') int? asdsAttempts,
@JsonKey(name: 'asds_landings') int? asdsLandings,
@JsonKey(name: 'water_landing') bool? waterLanding,
String? details,
}) = _NetworkCoreModel;

const NetworkCoreModel._();

factory NetworkCoreModel.fromJson(Map<String, dynamic> json) =>
_$NetworkCoreModelFromJson(json);
}

@freezed
abstract class NetworkMission with _$NetworkMission {
const factory NetworkMission({
String? name,
int? flight,
}) = _NetworkMission;

const NetworkMission._();

factory NetworkMission.fromJson(Map<String, dynamic> json) =>
_$NetworkMissionFromJson(json);
}
Loading