LCOV - code coverage report
Current view: top level - lib/data/repositories/mobility - sncf_route_repository_impl.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 41 0.0 %
Date: 2020-06-26 11:36:11 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:app_pym/core/error/exceptions.dart';
       2             : import 'package:app_pym/core/network/network_info.dart';
       3             : import 'package:app_pym/core/constants/mobility.dart';
       4             : import 'package:app_pym/data/datasources/sncf_local_data_source.dart';
       5             : import 'package:app_pym/data/datasources/sncf_remote_data_source.dart';
       6             : import 'package:app_pym/data/models/mobility/calendar_model.dart';
       7             : import 'package:app_pym/data/models/mobility/route_model.dart';
       8             : import 'package:app_pym/data/models/mobility/stop_model.dart';
       9             : import 'package:app_pym/data/models/mobility/stop_time_model.dart';
      10             : import 'package:app_pym/data/models/mobility/trip_model.dart';
      11             : import 'package:app_pym/domain/entities/mobility/route.dart';
      12             : import 'package:app_pym/domain/repositories/mobility/route_repository.dart';
      13             : import 'package:connectivity/connectivity.dart';
      14             : import 'package:flutter/foundation.dart';
      15             : import 'package:injectable/injectable.dart';
      16             : 
      17             : @prod
      18             : @LazySingleton(as: SNCFRouteRepository)
      19             : class SNCFRouteRepositoryImpl implements SNCFRouteRepository {
      20             :   final SNCFRemoteDataSource remoteDataSource;
      21             :   final SNCFLocalDataSource localDataSource;
      22             :   final NetworkInfo networkInfo;
      23             : 
      24           0 :   const SNCFRouteRepositoryImpl({
      25             :     @required this.localDataSource,
      26             :     @required this.remoteDataSource,
      27             :     @required this.networkInfo,
      28             :   });
      29             : 
      30           0 :   @override
      31             :   Stream<Route> fetchRoutes() {
      32           0 :     return _fetchRoute();
      33             :   }
      34             : 
      35           0 :   Stream<Route> _fetchRoute() async* {
      36           0 :     if (await networkInfo.result != ConnectivityResult.none) {
      37           0 :       final timestamp = await remoteDataSource.timestamp;
      38           0 :       if (timestamp != await localDataSource.timestamp) {
      39           0 :         await localDataSource.setTimestamp(timestamp);
      40           0 :         final stream = remoteDataSource.download();
      41           0 :         await localDataSource.writeFile(stream);
      42             :       }
      43           0 :     } else if (!(await localDataSource.fileExists)) {
      44           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      45             :     }
      46             : 
      47             :     List<RouteModel> routeModels;
      48             :     List<TripModel> tripModels;
      49             :     List<CalendarModel> calendarModels;
      50             :     List<StopTimeModel> stopTimeModels;
      51             :     List<StopModel> stopModels;
      52             :     try {
      53           0 :       routeModels = await localDataSource.fetchRoutes();
      54           0 :     } on CacheException catch (_) {
      55           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      56           0 :       await localDataSource.setTimestamp(DateTime(2019));
      57           0 :       routeModels = await localDataSource.fetchRoutes();
      58             :     }
      59             :     try {
      60           0 :       tripModels = await localDataSource.fetchTrips();
      61           0 :     } on CacheException catch (_) {
      62           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      63           0 :       await localDataSource.setTimestamp(DateTime(2019));
      64           0 :       tripModels = await localDataSource.fetchTrips();
      65             :     }
      66             :     try {
      67           0 :       calendarModels = await localDataSource.fetchCalendars();
      68           0 :     } on CacheException catch (_) {
      69           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      70           0 :       await localDataSource.setTimestamp(DateTime(2019));
      71           0 :       calendarModels = await localDataSource.fetchCalendars();
      72             :     }
      73             :     try {
      74           0 :       stopTimeModels = await localDataSource.fetchStopTimes();
      75           0 :     } on CacheException catch (_) {
      76           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      77           0 :       await localDataSource.setTimestamp(DateTime(2019));
      78           0 :       stopTimeModels = await localDataSource.fetchStopTimes();
      79             :     }
      80             :     try {
      81           0 :       stopModels = await localDataSource.fetchStops();
      82           0 :     } on CacheException catch (_) {
      83           0 :       await localDataSource.writeFile(localDataSource.useAsset());
      84           0 :       await localDataSource.setTimestamp(DateTime(2019));
      85           0 :       stopModels = await localDataSource.fetchStops();
      86             :     }
      87             : 
      88             :     //la seule route qui nous intéresse
      89           0 :     final routeModel = routeModels.firstWhere(
      90           0 :         (routeModel) => routeModel.route_id == MobilityConstants.trainLine);
      91           0 :     final route = routeModel.toEntity(
      92             :       calendarModels: calendarModels,
      93             :       stopModels: stopModels,
      94             :       stopTimeModels: stopTimeModels,
      95             :       tripModels: tripModels,
      96             :     );
      97           0 :     yield route;
      98             :   }
      99             : }

Generated by: LCOV version 1.13