diff --git a/modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource.dart b/modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource.dart deleted file mode 100644 index f94cf672..00000000 --- a/modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource.dart +++ /dev/null @@ -1,9 +0,0 @@ -import '../../domain/entities/alert_entity.dart'; - -abstract class AlertsRemoteDatasource { - Future<(List, int totalPages)> getAlerts({ - required int page, - int pageSize, - String? type, - }); -} diff --git a/modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource.dart b/modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource.dart new file mode 100644 index 00000000..f8112c60 --- /dev/null +++ b/modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource.dart @@ -0,0 +1,9 @@ +import '../../domain/entities/notification_entity.dart'; + +abstract class NotificationsRemoteDatasource { + Future<(List, int totalPages)> getNotifications({ + required int page, + int pageSize, + String? type, + }); +} diff --git a/modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource_impl.dart b/modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource_impl.dart similarity index 60% rename from modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource_impl.dart rename to modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource_impl.dart index d711c66a..c25ac402 100644 --- a/modules/legacy/modules/settings/lib/src/core/data/datasource/alerts_remote_datasource_impl.dart +++ b/modules/legacy/modules/settings/lib/src/core/data/datasource/notifications_remote_datasource_impl.dart @@ -1,17 +1,17 @@ import 'package:sf_infrastructure/sf_infrastructure.dart'; import 'package:utils/utils.dart'; -import '../../domain/entities/alert_entity.dart'; -import '../models/alerts_response_dto.dart'; -import 'alerts_remote_datasource.dart'; +import '../../domain/entities/notification_entity.dart'; +import '../models/notifications_response_dto.dart'; +import 'notifications_remote_datasource.dart'; -class AlertsRemoteDatasourceImpl implements AlertsRemoteDatasource { - AlertsRemoteDatasourceImpl(this._repository); +class NotificationsRemoteDatasourceImpl implements NotificationsRemoteDatasource { + NotificationsRemoteDatasourceImpl(this._repository); final SaveFamilyRepository _repository; @override - Future<(List, int totalPages)> getAlerts({ + Future<(List, int totalPages)> getNotifications({ required int page, int pageSize = 20, String? type, @@ -36,9 +36,9 @@ class AlertsRemoteDatasourceImpl implements AlertsRemoteDatasource { ); final data = response.data; - if (data == null || data.isEmpty) return ([], 1); + if (data == null || data.isEmpty) return ([], 1); - final model = AlertsResponseDto.fromJson(data); + final model = NotificationsResponseDto.fromJson(data); return (model.toEntities(), model.pages); } } diff --git a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.dart b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.dart similarity index 56% rename from modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.dart rename to modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.dart index 9c46c88a..b8d98298 100644 --- a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.dart +++ b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.dart @@ -1,56 +1,56 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import '../../domain/entities/alert_entity.dart'; +import '../../domain/entities/notification_entity.dart'; -part 'alerts_response_dto.freezed.dart'; -part 'alerts_response_dto.g.dart'; +part 'notifications_response_dto.freezed.dart'; +part 'notifications_response_dto.g.dart'; @freezed -abstract class AlertsResponseDto with _$AlertsResponseDto { - const factory AlertsResponseDto({ +abstract class NotificationsResponseDto with _$NotificationsResponseDto { + const factory NotificationsResponseDto({ @Default(0) int total, - @Default([]) List items, + @Default([]) List items, @Default(1) int page, @Default(1) int pages, }) = _AlertsResponseDto; - factory AlertsResponseDto.fromJson(Map json) => + factory NotificationsResponseDto.fromJson(Map json) => _$AlertsResponseDtoFromJson(json); } @freezed -abstract class AlertItemDto with _$AlertItemDto { - const factory AlertItemDto({ +abstract class NotificationItemDto with _$NotificationItemDto { + const factory NotificationItemDto({ required String id, @Default('') String deviceIdentificator, @Default('') String deviceName, @Default('') String type, - AlertGeofenceDto? geofenceAlert, + NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, @Default(0) int createdAt, }) = _AlertItemDto; - factory AlertItemDto.fromJson(Map json) => + factory NotificationItemDto.fromJson(Map json) => _$AlertItemDtoFromJson(json); } @freezed -abstract class AlertGeofenceDto with _$AlertGeofenceDto { - const factory AlertGeofenceDto({ +abstract class NotificationGeofenceDto with _$NotificationGeofenceDto { + const factory NotificationGeofenceDto({ required String id, required String name, }) = _AlertGeofenceDto; - factory AlertGeofenceDto.fromJson(Map json) => + factory NotificationGeofenceDto.fromJson(Map json) => _$AlertGeofenceDtoFromJson(json); } -extension AlertsResponseDtoMapper on AlertsResponseDto { - List toEntities() { +extension NotificationsResponseDtoMapper on NotificationsResponseDto { + List toEntities() { return items .map( - (item) => AlertEntity( + (item) => NotificationEntity( id: item.id, deviceIdentificator: item.deviceIdentificator, deviceName: item.deviceName, diff --git a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.freezed.dart b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.freezed.dart similarity index 72% rename from modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.freezed.dart rename to modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.freezed.dart index e2be8ac4..7bdd3b8e 100644 --- a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.freezed.dart +++ b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'alerts_response_dto.dart'; +part of 'notifications_response_dto.dart'; // ************************************************************************** // FreezedGenerator @@ -11,24 +11,31 @@ part of 'alerts_response_dto.dart'; // dart format off T _$identity(T value) => value; +NotificationsResponseDto _$NotificationsResponseDtoFromJson( + Map json +) { + return _AlertsResponseDto.fromJson( + json + ); +} /// @nodoc -mixin _$AlertsResponseDto { +mixin _$NotificationsResponseDto { - int get total; List get items; int get page; int get pages; -/// Create a copy of AlertsResponseDto + int get total; List get items; int get page; int get pages; +/// Create a copy of NotificationsResponseDto /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$AlertsResponseDtoCopyWith get copyWith => _$AlertsResponseDtoCopyWithImpl(this as AlertsResponseDto, _$identity); +$NotificationsResponseDtoCopyWith get copyWith => _$NotificationsResponseDtoCopyWithImpl(this as NotificationsResponseDto, _$identity); - /// Serializes this AlertsResponseDto to a JSON map. + /// Serializes this NotificationsResponseDto to a JSON map. Map toJson(); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is AlertsResponseDto&&(identical(other.total, total) || other.total == total)&&const DeepCollectionEquality().equals(other.items, items)&&(identical(other.page, page) || other.page == page)&&(identical(other.pages, pages) || other.pages == pages)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationsResponseDto&&(identical(other.total, total) || other.total == total)&&const DeepCollectionEquality().equals(other.items, items)&&(identical(other.page, page) || other.page == page)&&(identical(other.pages, pages) || other.pages == pages)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -37,18 +44,18 @@ int get hashCode => Object.hash(runtimeType,total,const DeepCollectionEquality() @override String toString() { - return 'AlertsResponseDto(total: $total, items: $items, page: $page, pages: $pages)'; + return 'NotificationsResponseDto(total: $total, items: $items, page: $page, pages: $pages)'; } } /// @nodoc -abstract mixin class $AlertsResponseDtoCopyWith<$Res> { - factory $AlertsResponseDtoCopyWith(AlertsResponseDto value, $Res Function(AlertsResponseDto) _then) = _$AlertsResponseDtoCopyWithImpl; +abstract mixin class $NotificationsResponseDtoCopyWith<$Res> { + factory $NotificationsResponseDtoCopyWith(NotificationsResponseDto value, $Res Function(NotificationsResponseDto) _then) = _$NotificationsResponseDtoCopyWithImpl; @useResult $Res call({ - int total, List items, int page, int pages + int total, List items, int page, int pages }); @@ -56,20 +63,20 @@ $Res call({ } /// @nodoc -class _$AlertsResponseDtoCopyWithImpl<$Res> - implements $AlertsResponseDtoCopyWith<$Res> { - _$AlertsResponseDtoCopyWithImpl(this._self, this._then); +class _$NotificationsResponseDtoCopyWithImpl<$Res> + implements $NotificationsResponseDtoCopyWith<$Res> { + _$NotificationsResponseDtoCopyWithImpl(this._self, this._then); - final AlertsResponseDto _self; - final $Res Function(AlertsResponseDto) _then; + final NotificationsResponseDto _self; + final $Res Function(NotificationsResponseDto) _then; -/// Create a copy of AlertsResponseDto +/// Create a copy of NotificationsResponseDto /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? total = null,Object? items = null,Object? page = null,Object? pages = null,}) { return _then(_self.copyWith( total: null == total ? _self.total : total // ignore: cast_nullable_to_non_nullable as int,items: null == items ? _self.items : items // ignore: cast_nullable_to_non_nullable -as List,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable +as List,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable as int,pages: null == pages ? _self.pages : pages // ignore: cast_nullable_to_non_nullable as int, )); @@ -78,8 +85,8 @@ as int, } -/// Adds pattern-matching-related methods to [AlertsResponseDto]. -extension AlertsResponseDtoPatterns on AlertsResponseDto { +/// Adds pattern-matching-related methods to [NotificationsResponseDto]. +extension NotificationsResponseDtoPatterns on NotificationsResponseDto { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -156,7 +163,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( int total, List items, int page, int pages)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( int total, List items, int page, int pages)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _AlertsResponseDto() when $default != null: return $default(_that.total,_that.items,_that.page,_that.pages);case _: @@ -177,7 +184,7 @@ return $default(_that.total,_that.items,_that.page,_that.pages);case _: /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( int total, List items, int page, int pages) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( int total, List items, int page, int pages) $default,) {final _that = this; switch (_that) { case _AlertsResponseDto(): return $default(_that.total,_that.items,_that.page,_that.pages);case _: @@ -197,7 +204,7 @@ return $default(_that.total,_that.items,_that.page,_that.pages);case _: /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( int total, List items, int page, int pages)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( int total, List items, int page, int pages)? $default,) {final _that = this; switch (_that) { case _AlertsResponseDto() when $default != null: return $default(_that.total,_that.items,_that.page,_that.pages);case _: @@ -211,13 +218,13 @@ return $default(_that.total,_that.items,_that.page,_that.pages);case _: /// @nodoc @JsonSerializable() -class _AlertsResponseDto implements AlertsResponseDto { - const _AlertsResponseDto({this.total = 0, final List items = const [], this.page = 1, this.pages = 1}): _items = items; +class _AlertsResponseDto implements NotificationsResponseDto { + const _AlertsResponseDto({this.total = 0, final List items = const [], this.page = 1, this.pages = 1}): _items = items; factory _AlertsResponseDto.fromJson(Map json) => _$AlertsResponseDtoFromJson(json); @override@JsonKey() final int total; - final List _items; -@override@JsonKey() List get items { + final List _items; +@override@JsonKey() List get items { if (_items is EqualUnmodifiableListView) return _items; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_items); @@ -226,7 +233,7 @@ class _AlertsResponseDto implements AlertsResponseDto { @override@JsonKey() final int page; @override@JsonKey() final int pages; -/// Create a copy of AlertsResponseDto +/// Create a copy of NotificationsResponseDto /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') @@ -248,18 +255,18 @@ int get hashCode => Object.hash(runtimeType,total,const DeepCollectionEquality() @override String toString() { - return 'AlertsResponseDto(total: $total, items: $items, page: $page, pages: $pages)'; + return 'NotificationsResponseDto(total: $total, items: $items, page: $page, pages: $pages)'; } } /// @nodoc -abstract mixin class _$AlertsResponseDtoCopyWith<$Res> implements $AlertsResponseDtoCopyWith<$Res> { +abstract mixin class _$AlertsResponseDtoCopyWith<$Res> implements $NotificationsResponseDtoCopyWith<$Res> { factory _$AlertsResponseDtoCopyWith(_AlertsResponseDto value, $Res Function(_AlertsResponseDto) _then) = __$AlertsResponseDtoCopyWithImpl; @override @useResult $Res call({ - int total, List items, int page, int pages + int total, List items, int page, int pages }); @@ -274,13 +281,13 @@ class __$AlertsResponseDtoCopyWithImpl<$Res> final _AlertsResponseDto _self; final $Res Function(_AlertsResponseDto) _then; -/// Create a copy of AlertsResponseDto +/// Create a copy of NotificationsResponseDto /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? total = null,Object? items = null,Object? page = null,Object? pages = null,}) { return _then(_AlertsResponseDto( total: null == total ? _self.total : total // ignore: cast_nullable_to_non_nullable as int,items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable -as List,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable +as List,page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable as int,pages: null == pages ? _self.pages : pages // ignore: cast_nullable_to_non_nullable as int, )); @@ -289,24 +296,31 @@ as int, } +NotificationItemDto _$NotificationItemDtoFromJson( + Map json +) { + return _AlertItemDto.fromJson( + json + ); +} /// @nodoc -mixin _$AlertItemDto { +mixin _$NotificationItemDto { - String get id; String get deviceIdentificator; String get deviceName; String get type; AlertGeofenceDto? get geofenceAlert; String? get delegationId; String? get userId; int get createdAt; -/// Create a copy of AlertItemDto + String get id; String get deviceIdentificator; String get deviceName; String get type; NotificationGeofenceDto? get geofenceAlert; String? get delegationId; String? get userId; int get createdAt; +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$AlertItemDtoCopyWith get copyWith => _$AlertItemDtoCopyWithImpl(this as AlertItemDto, _$identity); +$NotificationItemDtoCopyWith get copyWith => _$NotificationItemDtoCopyWithImpl(this as NotificationItemDto, _$identity); - /// Serializes this AlertItemDto to a JSON map. + /// Serializes this NotificationItemDto to a JSON map. Map toJson(); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is AlertItemDto&&(identical(other.id, id) || other.id == id)&&(identical(other.deviceIdentificator, deviceIdentificator) || other.deviceIdentificator == deviceIdentificator)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.type, type) || other.type == type)&&(identical(other.geofenceAlert, geofenceAlert) || other.geofenceAlert == geofenceAlert)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationItemDto&&(identical(other.id, id) || other.id == id)&&(identical(other.deviceIdentificator, deviceIdentificator) || other.deviceIdentificator == deviceIdentificator)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.type, type) || other.type == type)&&(identical(other.geofenceAlert, geofenceAlert) || other.geofenceAlert == geofenceAlert)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -315,33 +329,33 @@ int get hashCode => Object.hash(runtimeType,id,deviceIdentificator,deviceName,ty @override String toString() { - return 'AlertItemDto(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; + return 'NotificationItemDto(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; } } /// @nodoc -abstract mixin class $AlertItemDtoCopyWith<$Res> { - factory $AlertItemDtoCopyWith(AlertItemDto value, $Res Function(AlertItemDto) _then) = _$AlertItemDtoCopyWithImpl; +abstract mixin class $NotificationItemDtoCopyWith<$Res> { + factory $NotificationItemDtoCopyWith(NotificationItemDto value, $Res Function(NotificationItemDto) _then) = _$NotificationItemDtoCopyWithImpl; @useResult $Res call({ - String id, String deviceIdentificator, String deviceName, String type, AlertGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt + String id, String deviceIdentificator, String deviceName, String type, NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt }); -$AlertGeofenceDtoCopyWith<$Res>? get geofenceAlert; +$NotificationGeofenceDtoCopyWith<$Res>? get geofenceAlert; } /// @nodoc -class _$AlertItemDtoCopyWithImpl<$Res> - implements $AlertItemDtoCopyWith<$Res> { - _$AlertItemDtoCopyWithImpl(this._self, this._then); +class _$NotificationItemDtoCopyWithImpl<$Res> + implements $NotificationItemDtoCopyWith<$Res> { + _$NotificationItemDtoCopyWithImpl(this._self, this._then); - final AlertItemDto _self; - final $Res Function(AlertItemDto) _then; + final NotificationItemDto _self; + final $Res Function(NotificationItemDto) _then; -/// Create a copy of AlertItemDto +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? deviceIdentificator = null,Object? deviceName = null,Object? type = null,Object? geofenceAlert = freezed,Object? delegationId = freezed,Object? userId = freezed,Object? createdAt = null,}) { return _then(_self.copyWith( @@ -350,30 +364,30 @@ as String,deviceIdentificator: null == deviceIdentificator ? _self.deviceIdentif as String,deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,geofenceAlert: freezed == geofenceAlert ? _self.geofenceAlert : geofenceAlert // ignore: cast_nullable_to_non_nullable -as AlertGeofenceDto?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable +as NotificationGeofenceDto?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable as String?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as int, )); } -/// Create a copy of AlertItemDto +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$AlertGeofenceDtoCopyWith<$Res>? get geofenceAlert { +$NotificationGeofenceDtoCopyWith<$Res>? get geofenceAlert { if (_self.geofenceAlert == null) { return null; } - return $AlertGeofenceDtoCopyWith<$Res>(_self.geofenceAlert!, (value) { + return $NotificationGeofenceDtoCopyWith<$Res>(_self.geofenceAlert!, (value) { return _then(_self.copyWith(geofenceAlert: value)); }); } } -/// Adds pattern-matching-related methods to [AlertItemDto]. -extension AlertItemDtoPatterns on AlertItemDto { +/// Adds pattern-matching-related methods to [NotificationItemDto]. +extension NotificationItemDtoPatterns on NotificationItemDto { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -450,7 +464,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String deviceIdentificator, String deviceName, String type, AlertGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String deviceIdentificator, String deviceName, String type, NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _AlertItemDto() when $default != null: return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_that.geofenceAlert,_that.delegationId,_that.userId,_that.createdAt);case _: @@ -471,7 +485,7 @@ return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_ /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, String deviceIdentificator, String deviceName, String type, AlertGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, String deviceIdentificator, String deviceName, String type, NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt) $default,) {final _that = this; switch (_that) { case _AlertItemDto(): return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_that.geofenceAlert,_that.delegationId,_that.userId,_that.createdAt);case _: @@ -491,7 +505,7 @@ return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_ /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String deviceIdentificator, String deviceName, String type, AlertGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String deviceIdentificator, String deviceName, String type, NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt)? $default,) {final _that = this; switch (_that) { case _AlertItemDto() when $default != null: return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_that.geofenceAlert,_that.delegationId,_that.userId,_that.createdAt);case _: @@ -505,7 +519,7 @@ return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_ /// @nodoc @JsonSerializable() -class _AlertItemDto implements AlertItemDto { +class _AlertItemDto implements NotificationItemDto { const _AlertItemDto({required this.id, this.deviceIdentificator = '', this.deviceName = '', this.type = '', this.geofenceAlert, this.delegationId, this.userId, this.createdAt = 0}); factory _AlertItemDto.fromJson(Map json) => _$AlertItemDtoFromJson(json); @@ -513,12 +527,12 @@ class _AlertItemDto implements AlertItemDto { @override@JsonKey() final String deviceIdentificator; @override@JsonKey() final String deviceName; @override@JsonKey() final String type; -@override final AlertGeofenceDto? geofenceAlert; +@override final NotificationGeofenceDto? geofenceAlert; @override final String? delegationId; @override final String? userId; @override@JsonKey() final int createdAt; -/// Create a copy of AlertItemDto +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') @@ -540,22 +554,22 @@ int get hashCode => Object.hash(runtimeType,id,deviceIdentificator,deviceName,ty @override String toString() { - return 'AlertItemDto(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; + return 'NotificationItemDto(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; } } /// @nodoc -abstract mixin class _$AlertItemDtoCopyWith<$Res> implements $AlertItemDtoCopyWith<$Res> { +abstract mixin class _$AlertItemDtoCopyWith<$Res> implements $NotificationItemDtoCopyWith<$Res> { factory _$AlertItemDtoCopyWith(_AlertItemDto value, $Res Function(_AlertItemDto) _then) = __$AlertItemDtoCopyWithImpl; @override @useResult $Res call({ - String id, String deviceIdentificator, String deviceName, String type, AlertGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt + String id, String deviceIdentificator, String deviceName, String type, NotificationGeofenceDto? geofenceAlert, String? delegationId, String? userId, int createdAt }); -@override $AlertGeofenceDtoCopyWith<$Res>? get geofenceAlert; +@override $NotificationGeofenceDtoCopyWith<$Res>? get geofenceAlert; } /// @nodoc @@ -566,7 +580,7 @@ class __$AlertItemDtoCopyWithImpl<$Res> final _AlertItemDto _self; final $Res Function(_AlertItemDto) _then; -/// Create a copy of AlertItemDto +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? deviceIdentificator = null,Object? deviceName = null,Object? type = null,Object? geofenceAlert = freezed,Object? delegationId = freezed,Object? userId = freezed,Object? createdAt = null,}) { return _then(_AlertItemDto( @@ -575,46 +589,53 @@ as String,deviceIdentificator: null == deviceIdentificator ? _self.deviceIdentif as String,deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,geofenceAlert: freezed == geofenceAlert ? _self.geofenceAlert : geofenceAlert // ignore: cast_nullable_to_non_nullable -as AlertGeofenceDto?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable +as NotificationGeofenceDto?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable as String?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as int, )); } -/// Create a copy of AlertItemDto +/// Create a copy of NotificationItemDto /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$AlertGeofenceDtoCopyWith<$Res>? get geofenceAlert { +$NotificationGeofenceDtoCopyWith<$Res>? get geofenceAlert { if (_self.geofenceAlert == null) { return null; } - return $AlertGeofenceDtoCopyWith<$Res>(_self.geofenceAlert!, (value) { + return $NotificationGeofenceDtoCopyWith<$Res>(_self.geofenceAlert!, (value) { return _then(_self.copyWith(geofenceAlert: value)); }); } } +NotificationGeofenceDto _$NotificationGeofenceDtoFromJson( + Map json +) { + return _AlertGeofenceDto.fromJson( + json + ); +} /// @nodoc -mixin _$AlertGeofenceDto { +mixin _$NotificationGeofenceDto { String get id; String get name; -/// Create a copy of AlertGeofenceDto +/// Create a copy of NotificationGeofenceDto /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$AlertGeofenceDtoCopyWith get copyWith => _$AlertGeofenceDtoCopyWithImpl(this as AlertGeofenceDto, _$identity); +$NotificationGeofenceDtoCopyWith get copyWith => _$NotificationGeofenceDtoCopyWithImpl(this as NotificationGeofenceDto, _$identity); - /// Serializes this AlertGeofenceDto to a JSON map. + /// Serializes this NotificationGeofenceDto to a JSON map. Map toJson(); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is AlertGeofenceDto&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationGeofenceDto&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -623,15 +644,15 @@ int get hashCode => Object.hash(runtimeType,id,name); @override String toString() { - return 'AlertGeofenceDto(id: $id, name: $name)'; + return 'NotificationGeofenceDto(id: $id, name: $name)'; } } /// @nodoc -abstract mixin class $AlertGeofenceDtoCopyWith<$Res> { - factory $AlertGeofenceDtoCopyWith(AlertGeofenceDto value, $Res Function(AlertGeofenceDto) _then) = _$AlertGeofenceDtoCopyWithImpl; +abstract mixin class $NotificationGeofenceDtoCopyWith<$Res> { + factory $NotificationGeofenceDtoCopyWith(NotificationGeofenceDto value, $Res Function(NotificationGeofenceDto) _then) = _$NotificationGeofenceDtoCopyWithImpl; @useResult $Res call({ String id, String name @@ -642,14 +663,14 @@ $Res call({ } /// @nodoc -class _$AlertGeofenceDtoCopyWithImpl<$Res> - implements $AlertGeofenceDtoCopyWith<$Res> { - _$AlertGeofenceDtoCopyWithImpl(this._self, this._then); +class _$NotificationGeofenceDtoCopyWithImpl<$Res> + implements $NotificationGeofenceDtoCopyWith<$Res> { + _$NotificationGeofenceDtoCopyWithImpl(this._self, this._then); - final AlertGeofenceDto _self; - final $Res Function(AlertGeofenceDto) _then; + final NotificationGeofenceDto _self; + final $Res Function(NotificationGeofenceDto) _then; -/// Create a copy of AlertGeofenceDto +/// Create a copy of NotificationGeofenceDto /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,}) { return _then(_self.copyWith( @@ -662,8 +683,8 @@ as String, } -/// Adds pattern-matching-related methods to [AlertGeofenceDto]. -extension AlertGeofenceDtoPatterns on AlertGeofenceDto { +/// Adds pattern-matching-related methods to [NotificationGeofenceDto]. +extension NotificationGeofenceDtoPatterns on NotificationGeofenceDto { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -795,14 +816,14 @@ return $default(_that.id,_that.name);case _: /// @nodoc @JsonSerializable() -class _AlertGeofenceDto implements AlertGeofenceDto { +class _AlertGeofenceDto implements NotificationGeofenceDto { const _AlertGeofenceDto({required this.id, required this.name}); factory _AlertGeofenceDto.fromJson(Map json) => _$AlertGeofenceDtoFromJson(json); @override final String id; @override final String name; -/// Create a copy of AlertGeofenceDto +/// Create a copy of NotificationGeofenceDto /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') @@ -824,14 +845,14 @@ int get hashCode => Object.hash(runtimeType,id,name); @override String toString() { - return 'AlertGeofenceDto(id: $id, name: $name)'; + return 'NotificationGeofenceDto(id: $id, name: $name)'; } } /// @nodoc -abstract mixin class _$AlertGeofenceDtoCopyWith<$Res> implements $AlertGeofenceDtoCopyWith<$Res> { +abstract mixin class _$AlertGeofenceDtoCopyWith<$Res> implements $NotificationGeofenceDtoCopyWith<$Res> { factory _$AlertGeofenceDtoCopyWith(_AlertGeofenceDto value, $Res Function(_AlertGeofenceDto) _then) = __$AlertGeofenceDtoCopyWithImpl; @override @useResult $Res call({ @@ -850,7 +871,7 @@ class __$AlertGeofenceDtoCopyWithImpl<$Res> final _AlertGeofenceDto _self; final $Res Function(_AlertGeofenceDto) _then; -/// Create a copy of AlertGeofenceDto +/// Create a copy of NotificationGeofenceDto /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,}) { return _then(_AlertGeofenceDto( diff --git a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.g.dart b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.g.dart similarity index 91% rename from modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.g.dart rename to modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.g.dart index 0f70b1ae..31f786e6 100644 --- a/modules/legacy/modules/settings/lib/src/core/data/models/alerts_response_dto.g.dart +++ b/modules/legacy/modules/settings/lib/src/core/data/models/notifications_response_dto.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'alerts_response_dto.dart'; +part of 'notifications_response_dto.dart'; // ************************************************************************** // JsonSerializableGenerator @@ -11,7 +11,9 @@ _AlertsResponseDto _$AlertsResponseDtoFromJson(Map json) => total: (json['total'] as num?)?.toInt() ?? 0, items: (json['items'] as List?) - ?.map((e) => AlertItemDto.fromJson(e as Map)) + ?.map( + (e) => NotificationItemDto.fromJson(e as Map), + ) .toList() ?? const [], page: (json['page'] as num?)?.toInt() ?? 1, @@ -34,7 +36,7 @@ _AlertItemDto _$AlertItemDtoFromJson(Map json) => type: json['type'] as String? ?? '', geofenceAlert: json['geofenceAlert'] == null ? null - : AlertGeofenceDto.fromJson( + : NotificationGeofenceDto.fromJson( json['geofenceAlert'] as Map, ), delegationId: json['delegationId'] as String?, diff --git a/modules/legacy/modules/settings/lib/src/core/data/repositories/alerts_repository_impl.dart b/modules/legacy/modules/settings/lib/src/core/data/repositories/alerts_repository_impl.dart deleted file mode 100644 index 3e0d18f5..00000000 --- a/modules/legacy/modules/settings/lib/src/core/data/repositories/alerts_repository_impl.dart +++ /dev/null @@ -1,30 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:sf_infrastructure/sf_infrastructure.dart'; - -import '../../domain/entities/alert_entity.dart'; -import '../../domain/repositories/alerts_repository.dart'; -import '../datasource/alerts_remote_datasource.dart'; - -class AlertsRepositoryImpl implements AlertsRepository { - AlertsRepositoryImpl(this._datasource); - - final AlertsRemoteDatasource _datasource; - - @override - Future<(List, int totalPages)> getAlerts({ - required int page, - int pageSize = 20, - String? type, - }) async { - try { - return await _datasource.getAlerts( - page: page, - pageSize: pageSize, - type: type, - ); - } on DioException catch (error) { - if (error.response?.statusCode == 404) return ([], 1); - throw mapDioError(error, defaultMessage: 'Error getting alerts'); - } - } -} diff --git a/modules/legacy/modules/settings/lib/src/core/data/repositories/notifications_repository_impl.dart b/modules/legacy/modules/settings/lib/src/core/data/repositories/notifications_repository_impl.dart new file mode 100644 index 00000000..84ca4419 --- /dev/null +++ b/modules/legacy/modules/settings/lib/src/core/data/repositories/notifications_repository_impl.dart @@ -0,0 +1,30 @@ +import 'package:dio/dio.dart'; +import 'package:sf_infrastructure/sf_infrastructure.dart'; + +import '../../domain/entities/notification_entity.dart'; +import '../../domain/repositories/notifications_repository.dart'; +import '../datasource/notifications_remote_datasource.dart'; + +class NotificationsRepositoryImpl implements NotificationsRepository { + NotificationsRepositoryImpl(this._datasource); + + final NotificationsRemoteDatasource _datasource; + + @override + Future<(List, int totalPages)> getNotifications({ + required int page, + int pageSize = 20, + String? type, + }) async { + try { + return await _datasource.getNotifications( + page: page, + pageSize: pageSize, + type: type, + ); + } on DioException catch (error) { + if (error.response?.statusCode == 404) return ([], 1); + throw mapDioError(error, defaultMessage: 'Error getting alerts'); + } + } +} diff --git a/modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.dart b/modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.dart similarity index 78% rename from modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.dart rename to modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.dart index 89d0a721..ad0c3905 100644 --- a/modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.dart +++ b/modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.dart @@ -1,10 +1,10 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -part 'alert_entity.freezed.dart'; +part 'notification_entity.freezed.dart'; @freezed -abstract class AlertEntity with _$AlertEntity { - const factory AlertEntity({ +abstract class NotificationEntity with _$NotificationEntity { + const factory NotificationEntity({ required String id, required String deviceIdentificator, required String deviceName, diff --git a/modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.freezed.dart b/modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.freezed.dart similarity index 89% rename from modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.freezed.dart rename to modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.freezed.dart index 85b1d20d..d2536a57 100644 --- a/modules/legacy/modules/settings/lib/src/core/domain/entities/alert_entity.freezed.dart +++ b/modules/legacy/modules/settings/lib/src/core/domain/entities/notification_entity.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'alert_entity.dart'; +part of 'notification_entity.dart'; // ************************************************************************** // FreezedGenerator @@ -12,20 +12,20 @@ part of 'alert_entity.dart'; // dart format off T _$identity(T value) => value; /// @nodoc -mixin _$AlertEntity { +mixin _$NotificationEntity { String get id; String get deviceIdentificator; String get deviceName; String get type; GeofenceAlertEntity? get geofenceAlert; String? get delegationId; String? get userId; int get createdAt; -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$AlertEntityCopyWith get copyWith => _$AlertEntityCopyWithImpl(this as AlertEntity, _$identity); +$NotificationEntityCopyWith get copyWith => _$NotificationEntityCopyWithImpl(this as NotificationEntity, _$identity); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is AlertEntity&&(identical(other.id, id) || other.id == id)&&(identical(other.deviceIdentificator, deviceIdentificator) || other.deviceIdentificator == deviceIdentificator)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.type, type) || other.type == type)&&(identical(other.geofenceAlert, geofenceAlert) || other.geofenceAlert == geofenceAlert)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationEntity&&(identical(other.id, id) || other.id == id)&&(identical(other.deviceIdentificator, deviceIdentificator) || other.deviceIdentificator == deviceIdentificator)&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.type, type) || other.type == type)&&(identical(other.geofenceAlert, geofenceAlert) || other.geofenceAlert == geofenceAlert)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)); } @@ -34,15 +34,15 @@ int get hashCode => Object.hash(runtimeType,id,deviceIdentificator,deviceName,ty @override String toString() { - return 'AlertEntity(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; + return 'NotificationEntity(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; } } /// @nodoc -abstract mixin class $AlertEntityCopyWith<$Res> { - factory $AlertEntityCopyWith(AlertEntity value, $Res Function(AlertEntity) _then) = _$AlertEntityCopyWithImpl; +abstract mixin class $NotificationEntityCopyWith<$Res> { + factory $NotificationEntityCopyWith(NotificationEntity value, $Res Function(NotificationEntity) _then) = _$NotificationEntityCopyWithImpl; @useResult $Res call({ String id, String deviceIdentificator, String deviceName, String type, GeofenceAlertEntity? geofenceAlert, String? delegationId, String? userId, int createdAt @@ -53,14 +53,14 @@ $GeofenceAlertEntityCopyWith<$Res>? get geofenceAlert; } /// @nodoc -class _$AlertEntityCopyWithImpl<$Res> - implements $AlertEntityCopyWith<$Res> { - _$AlertEntityCopyWithImpl(this._self, this._then); +class _$NotificationEntityCopyWithImpl<$Res> + implements $NotificationEntityCopyWith<$Res> { + _$NotificationEntityCopyWithImpl(this._self, this._then); - final AlertEntity _self; - final $Res Function(AlertEntity) _then; + final NotificationEntity _self; + final $Res Function(NotificationEntity) _then; -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? deviceIdentificator = null,Object? deviceName = null,Object? type = null,Object? geofenceAlert = freezed,Object? delegationId = freezed,Object? userId = freezed,Object? createdAt = null,}) { return _then(_self.copyWith( @@ -75,7 +75,7 @@ as String?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: as int, )); } -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') @@ -91,8 +91,8 @@ $GeofenceAlertEntityCopyWith<$Res>? get geofenceAlert { } -/// Adds pattern-matching-related methods to [AlertEntity]. -extension AlertEntityPatterns on AlertEntity { +/// Adds pattern-matching-related methods to [NotificationEntity]. +extension NotificationEntityPatterns on NotificationEntity { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -224,7 +224,7 @@ return $default(_that.id,_that.deviceIdentificator,_that.deviceName,_that.type,_ /// @nodoc -class _AlertEntity implements AlertEntity { +class _AlertEntity implements NotificationEntity { const _AlertEntity({required this.id, required this.deviceIdentificator, required this.deviceName, required this.type, this.geofenceAlert, this.delegationId, this.userId, required this.createdAt}); @@ -237,7 +237,7 @@ class _AlertEntity implements AlertEntity { @override final String? userId; @override final int createdAt; -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') @@ -256,14 +256,14 @@ int get hashCode => Object.hash(runtimeType,id,deviceIdentificator,deviceName,ty @override String toString() { - return 'AlertEntity(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; + return 'NotificationEntity(id: $id, deviceIdentificator: $deviceIdentificator, deviceName: $deviceName, type: $type, geofenceAlert: $geofenceAlert, delegationId: $delegationId, userId: $userId, createdAt: $createdAt)'; } } /// @nodoc -abstract mixin class _$AlertEntityCopyWith<$Res> implements $AlertEntityCopyWith<$Res> { +abstract mixin class _$AlertEntityCopyWith<$Res> implements $NotificationEntityCopyWith<$Res> { factory _$AlertEntityCopyWith(_AlertEntity value, $Res Function(_AlertEntity) _then) = __$AlertEntityCopyWithImpl; @override @useResult $Res call({ @@ -282,7 +282,7 @@ class __$AlertEntityCopyWithImpl<$Res> final _AlertEntity _self; final $Res Function(_AlertEntity) _then; -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? deviceIdentificator = null,Object? deviceName = null,Object? type = null,Object? geofenceAlert = freezed,Object? delegationId = freezed,Object? userId = freezed,Object? createdAt = null,}) { return _then(_AlertEntity( @@ -298,7 +298,7 @@ as int, )); } -/// Create a copy of AlertEntity +/// Create a copy of NotificationEntity /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') diff --git a/modules/legacy/modules/settings/lib/src/core/domain/repositories/alerts_repository.dart b/modules/legacy/modules/settings/lib/src/core/domain/repositories/alerts_repository.dart deleted file mode 100644 index 2dcc1ccf..00000000 --- a/modules/legacy/modules/settings/lib/src/core/domain/repositories/alerts_repository.dart +++ /dev/null @@ -1,9 +0,0 @@ -import '../entities/alert_entity.dart'; - -abstract class AlertsRepository { - Future<(List, int totalPages)> getAlerts({ - required int page, - int pageSize, - String? type, - }); -} diff --git a/modules/legacy/modules/settings/lib/src/core/domain/repositories/notifications_repository.dart b/modules/legacy/modules/settings/lib/src/core/domain/repositories/notifications_repository.dart new file mode 100644 index 00000000..77c96764 --- /dev/null +++ b/modules/legacy/modules/settings/lib/src/core/domain/repositories/notifications_repository.dart @@ -0,0 +1,9 @@ +import '../entities/notification_entity.dart'; + +abstract class NotificationsRepository { + Future<(List, int totalPages)> getNotifications({ + required int page, + int pageSize, + String? type, + }); +} diff --git a/modules/legacy/modules/settings/lib/src/core/providers/alerts_repository_provider.dart b/modules/legacy/modules/settings/lib/src/core/providers/alerts_repository_provider.dart deleted file mode 100644 index 409d1c54..00000000 --- a/modules/legacy/modules/settings/lib/src/core/providers/alerts_repository_provider.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:get_it/get_it.dart'; -import 'package:sf_infrastructure/sf_infrastructure.dart'; - -import '../data/datasource/alerts_remote_datasource.dart'; -import '../data/datasource/alerts_remote_datasource_impl.dart'; -import '../data/repositories/alerts_repository_impl.dart'; -import '../domain/repositories/alerts_repository.dart'; - -final alertsRemoteDatasourceProvider = Provider( - (_) => AlertsRemoteDatasourceImpl(GetIt.I()), -); - -final alertsRepositoryProvider = Provider( - (ref) => AlertsRepositoryImpl(ref.read(alertsRemoteDatasourceProvider)), -); diff --git a/modules/legacy/modules/settings/lib/src/core/providers/notifications_repository_provider.dart b/modules/legacy/modules/settings/lib/src/core/providers/notifications_repository_provider.dart new file mode 100644 index 00000000..fb4d5b8e --- /dev/null +++ b/modules/legacy/modules/settings/lib/src/core/providers/notifications_repository_provider.dart @@ -0,0 +1,16 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:get_it/get_it.dart'; +import 'package:sf_infrastructure/sf_infrastructure.dart'; + +import '../data/datasource/notifications_remote_datasource.dart'; +import '../data/datasource/notifications_remote_datasource_impl.dart'; +import '../data/repositories/notifications_repository_impl.dart'; +import '../domain/repositories/notifications_repository.dart'; + +final notificationsRemoteDatasourceProvider = Provider( + (_) => NotificationsRemoteDatasourceImpl(GetIt.I()), +); + +final notificationsRepositoryProvider = Provider( + (ref) => NotificationsRepositoryImpl(ref.read(notificationsRemoteDatasourceProvider)), +); diff --git a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/notifications_screen.dart b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/notifications_screen.dart index 9a0ba045..1cf354ca 100644 --- a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/notifications_screen.dart +++ b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/notifications_screen.dart @@ -1,4 +1,4 @@ -import 'package:settings/src/core/domain/entities/alert_entity.dart'; +import 'package:settings/src/core/domain/entities/notification_entity.dart'; import 'package:settings/src/features/notifications/presentation/providers/notifications_feed_provider.dart'; import 'package:settings/src/features/notifications/presentation/providers/notifications_filter_provider.dart'; import 'package:settings/src/features/notifications/presentation/widgets/notification_card.dart'; @@ -231,7 +231,7 @@ class _FilteredNotificationsScreen extends ConsumerWidget { } class _NotificationsList extends ConsumerStatefulWidget { - final List notifications; + final List notifications; final bool isLoadingMore; const _NotificationsList({ diff --git a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.dart b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.dart index 0f3ce546..aede7424 100644 --- a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.dart +++ b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.dart @@ -1,7 +1,7 @@ import 'dart:async'; -import 'package:settings/src/core/domain/entities/alert_entity.dart'; -import 'package:settings/src/core/providers/alerts_repository_provider.dart'; +import 'package:settings/src/core/domain/entities/notification_entity.dart'; +import 'package:settings/src/core/providers/notifications_repository_provider.dart'; import 'package:settings/src/features/notifications/presentation/providers/notifications_filter_provider.dart'; import 'package:legacy_device_state/legacy_device_state.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -19,13 +19,13 @@ class NotificationsFeedState { this.isLoadingMore = false, }); - final List notifications; + final List notifications; final int currentPage; final bool hasMore; final bool isLoadingMore; NotificationsFeedState copyWith({ - List? notifications, + List? notifications, int? currentPage, bool? hasMore, bool? isLoadingMore, @@ -53,8 +53,8 @@ class NotificationsFeed extends _$NotificationsFeed { ref.onDispose(() => _subscription?.cancel()); final (notifications, totalPages) = await ref - .read(alertsRepositoryProvider) - .getAlerts(page: 1, pageSize: _pageSize, type: filter); + .read(notificationsRepositoryProvider) + .getNotifications(page: 1, pageSize: _pageSize, type: filter); return NotificationsFeedState( notifications: notifications, @@ -72,7 +72,7 @@ class NotificationsFeed extends _$NotificationsFeed { final filter = ref.read(notificationsFilterProvider); if (filter != null && filter != event.type) return; - final newNotification = AlertEntity( + final newNotification = NotificationEntity( id: '', deviceIdentificator: event.deviceIdentificator, deviceName: '', @@ -98,8 +98,8 @@ class NotificationsFeed extends _$NotificationsFeed { final filter = ref.read(notificationsFilterProvider); final nextPage = current.currentPage + 1; final (notifications, totalPages) = await ref - .read(alertsRepositoryProvider) - .getAlerts(page: nextPage, pageSize: _pageSize, type: filter); + .read(notificationsRepositoryProvider) + .getNotifications(page: nextPage, pageSize: _pageSize, type: filter); state = AsyncData( current.copyWith( diff --git a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.g.dart b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.g.dart index 52e87356..ea17ffe6 100644 --- a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.g.dart +++ b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/providers/notifications_feed_provider.g.dart @@ -33,7 +33,7 @@ final class NotificationsFeedProvider NotificationsFeed create() => NotificationsFeed(); } -String _$notificationsFeedHash() => r'bb7878198548338c17db4b9ac51e3f88a24115d6'; +String _$notificationsFeedHash() => r'907cd9e444a625ff38206809797a006321e1ed99'; abstract class _$NotificationsFeed extends $AsyncNotifier { diff --git a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/widgets/notification_card.dart b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/widgets/notification_card.dart index e8666600..2e6de4c4 100644 --- a/modules/legacy/modules/settings/lib/src/features/notifications/presentation/widgets/notification_card.dart +++ b/modules/legacy/modules/settings/lib/src/features/notifications/presentation/widgets/notification_card.dart @@ -4,10 +4,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:sf_localizations/sf_localizations.dart'; import 'package:utils/utils.dart'; -import '../../../../core/domain/entities/alert_entity.dart'; +import '../../../../core/domain/entities/notification_entity.dart'; class NotificationCard extends ConsumerWidget { - final AlertEntity notification; + final NotificationEntity notification; const NotificationCard({super.key, required this.notification}); diff --git a/modules/legacy/modules/settings/test/features/notifications/notifications_feed_test.dart b/modules/legacy/modules/settings/test/features/notifications/notifications_feed_test.dart index e7fb04f8..ade0ede0 100644 --- a/modules/legacy/modules/settings/test/features/notifications/notifications_feed_test.dart +++ b/modules/legacy/modules/settings/test/features/notifications/notifications_feed_test.dart @@ -1,8 +1,8 @@ import 'dart:async'; -import 'package:settings/src/core/domain/entities/alert_entity.dart'; -import 'package:settings/src/core/domain/repositories/alerts_repository.dart'; -import 'package:settings/src/core/providers/alerts_repository_provider.dart'; +import 'package:settings/src/core/domain/entities/notification_entity.dart'; +import 'package:settings/src/core/domain/repositories/notifications_repository.dart'; +import 'package:settings/src/core/providers/notifications_repository_provider.dart'; import 'package:settings/src/features/notifications/presentation/providers/notifications_feed_provider.dart'; import 'package:settings/src/features/notifications/presentation/providers/notifications_filter_provider.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -12,7 +12,7 @@ import 'package:mocktail/mocktail.dart'; import 'package:sf_infrastructure/sf_infrastructure.dart'; import 'package:sf_shared/testing.dart'; -class MockAlertsRepository extends Mock implements AlertsRepository {} +class MockAlertsRepository extends Mock implements NotificationsRepository {} class FakeWebSocketService implements WebSocketService { final _controller = StreamController.broadcast(); @@ -26,14 +26,14 @@ class FakeWebSocketService implements WebSocketService { dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } -final _alert1 = AlertEntity( +final _alert1 = NotificationEntity( id: '1', deviceIdentificator: 'd1', deviceName: 'Watch', type: 'sos', createdAt: 1, ); -final _alert2 = AlertEntity( +final _alert2 = NotificationEntity( id: '2', deviceIdentificator: 'd1', deviceName: 'Watch', @@ -43,12 +43,12 @@ final _alert2 = AlertEntity( void main() { ProviderContainer buildContainer({ - required AlertsRepository repo, + required NotificationsRepository repo, required FakeWebSocketService ws, }) { return makeContainer( overrides: [ - alertsRepositoryProvider.overrideWithValue(repo), + notificationsRepositoryProvider.overrideWithValue(repo), webSocketServiceProvider.overrideWithValue(ws), ], ); @@ -59,7 +59,7 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: any(named: 'page'), pageSize: any(named: 'pageSize'), type: any(named: 'type'), @@ -76,7 +76,7 @@ void main() { expect(state.notifications, [_alert1, _alert2]); expect(state.currentPage, 1); expect(state.hasMore, isTrue); - verify(() => repo.getAlerts(page: 1, pageSize: 20, type: null)) + verify(() => repo.getNotifications(page: 1, pageSize: 20, type: null)) .called(1); }); @@ -84,7 +84,7 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: any(named: 'page'), pageSize: any(named: 'pageSize'), type: any(named: 'type'), @@ -100,7 +100,7 @@ void main() { container.read(notificationsFilterProvider.notifier).select('sos'); await container.read(notificationsFeedProvider.future); - verify(() => repo.getAlerts(page: 1, pageSize: 20, type: 'sos')) + verify(() => repo.getNotifications(page: 1, pageSize: 20, type: 'sos')) .called(1); }); }); @@ -110,14 +110,14 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: 1, pageSize: any(named: 'pageSize'), type: any(named: 'type'), ), ).thenAnswer((_) async => ([_alert1], 2)); when( - () => repo.getAlerts( + () => repo.getNotifications( page: 2, pageSize: any(named: 'pageSize'), type: any(named: 'type'), @@ -141,7 +141,7 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: any(named: 'page'), pageSize: any(named: 'pageSize'), type: any(named: 'type'), @@ -155,9 +155,9 @@ void main() { await container.read(notificationsFeedProvider.future); await container.read(notificationsFeedProvider.notifier).loadMore(); - verify(() => repo.getAlerts(page: 1, pageSize: 20, type: null)) + verify(() => repo.getNotifications(page: 1, pageSize: 20, type: null)) .called(1); - verifyNever(() => repo.getAlerts(page: 2, pageSize: 20, type: null)); + verifyNever(() => repo.getNotifications(page: 2, pageSize: 20, type: null)); }); }); @@ -166,7 +166,7 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: any(named: 'page'), pageSize: any(named: 'pageSize'), type: any(named: 'type'), @@ -195,7 +195,7 @@ void main() { final repo = MockAlertsRepository(); final ws = FakeWebSocketService(); when( - () => repo.getAlerts( + () => repo.getNotifications( page: any(named: 'page'), pageSize: any(named: 'pageSize'), type: any(named: 'type'),