Created
June 11, 2021 05:22
-
-
Save locskot/c343d7a46845e9fc6973afa2dc8400e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:components/api/graphql_api.dart'; | |
import 'package:components/model/request_result_model.dart'; | |
import 'package:components/utils/log_service.dart'; | |
import 'notification.dart'; | |
abstract class NotificationsRepository { | |
NotificationsRepository(); | |
factory NotificationsRepository.create(GraphqlAPI graphqlAPI) { | |
return NotificationRepositoryImpl(graphqlAPI); | |
} | |
Future<RequestResultModel> loadNotifications(); | |
Future<RequestResultModel> markAsRead(List<String> data); | |
} | |
class NotificationRepositoryImpl extends NotificationsRepository { | |
GraphqlAPI graphqlAPI; | |
NotificationRepositoryImpl(this.graphqlAPI); | |
@override | |
Future<RequestResultModel> loadNotifications() async { | |
try { | |
final response = await Future.delayed(Duration(seconds: 2)); | |
return RequestResultModel(result: true, value: mockItems()); | |
} on Exception catch (e) { | |
LogService.log('Exception during loading notifications', exception: e); | |
return RequestResultModel(result: false, value: e); | |
} | |
} | |
@override | |
Future<RequestResultModel> markAsRead(List<String> data) async { | |
try { | |
final response = await Future.delayed(Duration(seconds: 2)); | |
return RequestResultModel(result: true, value: data); | |
} on Exception catch (e) { | |
LogService.log('Exception during marking notifications as read', exception: e); | |
return RequestResultModel(result: false, value: e); | |
} | |
} | |
} | |
List<MockNotification> mockItems() { | |
final list = <MockNotification>[]; | |
for (var i = 1; i < 100; i++) { | |
list.add( | |
MockNotification( | |
id: '$i', | |
label: 'Label $i', | |
dateTime: DateTime.now().subtract( | |
Duration(days: 1), | |
), | |
isRead: i % 2 == 0, | |
), | |
); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment