feat(wip): implement trip persistence through a local repository. Include loaded trips in the start page UI
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import 'package:anyway/data/datasources/trip_local_datasource.dart';
|
||||
import 'package:anyway/data/datasources/trip_remote_datasource.dart';
|
||||
import 'package:anyway/domain/entities/landmark.dart';
|
||||
import 'package:anyway/domain/entities/preferences.dart';
|
||||
import 'package:anyway/domain/entities/trip.dart';
|
||||
import 'package:anyway/domain/repositories/trip_repository.dart';
|
||||
import 'package:anyway/data/datasources/trip_remote_datasource.dart';
|
||||
|
||||
class BackendTripRepository implements TripRepository {
|
||||
final TripRemoteDataSource remote;
|
||||
final TripLocalDataSource local;
|
||||
|
||||
BackendTripRepository({required this.remote});
|
||||
BackendTripRepository({required this.remote, required this.local});
|
||||
|
||||
@override
|
||||
Future<Trip> getTrip({Preferences? preferences, String? tripUUID, List<Landmark>? landmarks}) async {
|
||||
@@ -86,4 +88,27 @@ class BackendTripRepository implements TripRepository {
|
||||
prefsPayload['max_time_minute'] = preferences.maxTimeMinutes;
|
||||
return prefsPayload;
|
||||
}
|
||||
|
||||
// TODO - should this be moved to a separate local repository?
|
||||
@override
|
||||
Future<List<Trip>> getSavedTrips() async {
|
||||
final rawTrips = await local.loadTrips();
|
||||
return rawTrips.map(Trip.fromJson).toList(growable: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Trip?> getSavedTrip(String uuid) async {
|
||||
final json = await local.getTrip(uuid);
|
||||
return json == null ? null : Trip.fromJson(json);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveTrip(Trip trip) async {
|
||||
await local.upsertTrip(trip.toJson());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSavedTrip(String uuid) async {
|
||||
await local.deleteTrip(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user