Merge pull request 'Added notification logic and view api' (#152) from logic_notification into main

Reviewed-on: https://repo.ravanertebat.com/TM/tm_app/pulls/152
This commit is contained in:
a.ghabeli
2025-09-22 16:09:10 +03:30
22 changed files with 1944 additions and 151 deletions
@@ -0,0 +1,16 @@
class NotificationApi {
static const String notifications = '/api/v1/notifications';
static String getNotifications({required int limit, required int offset}) {
return '$notifications?limit=$limit&offset=$offset';
}
static const String feedback = '/api/v1/feedback';
static const String markAllAsRead = '/api/v1/notifications';
static const String markAsRead = '/api/v1/notifications/mark-as-read';
static const String tenderApprovalsTender = '/api/v1/notifications';
static String getTenderApprovalById({required String tenderId}) {
return '$tenderApprovalsTender/$tenderId';
}
}
@@ -0,0 +1,334 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// 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 'notification_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$NotificationModel {
bool? get success; String? get message; NotificationData? get data; ErrorModel? get error;
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$NotificationModelCopyWith<NotificationModel> get copyWith => _$NotificationModelCopyWithImpl<NotificationModel>(this as NotificationModel, _$identity);
/// Serializes this NotificationModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error);
@override
String toString() {
return 'NotificationModel(success: $success, message: $message, data: $data, error: $error)';
}
}
/// @nodoc
abstract mixin class $NotificationModelCopyWith<$Res> {
factory $NotificationModelCopyWith(NotificationModel value, $Res Function(NotificationModel) _then) = _$NotificationModelCopyWithImpl;
@useResult
$Res call({
bool? success, String? message, NotificationData? data, ErrorModel? error
});
$NotificationDataCopyWith<$Res>? get data;$ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class _$NotificationModelCopyWithImpl<$Res>
implements $NotificationModelCopyWith<$Res> {
_$NotificationModelCopyWithImpl(this._self, this._then);
final NotificationModel _self;
final $Res Function(NotificationModel) _then;
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? success = freezed,Object? message = freezed,Object? data = freezed,Object? error = freezed,}) {
return _then(_self.copyWith(
success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as NotificationData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,
));
}
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$NotificationDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $NotificationDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
/// Adds pattern-matching-related methods to [NotificationModel].
extension NotificationModelPatterns on NotificationModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _NotificationModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _NotificationModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _NotificationModel value) $default,){
final _that = this;
switch (_that) {
case _NotificationModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _NotificationModel value)? $default,){
final _that = this;
switch (_that) {
case _NotificationModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool? success, String? message, NotificationData? data, ErrorModel? error)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _NotificationModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool? success, String? message, NotificationData? data, ErrorModel? error) $default,) {final _that = this;
switch (_that) {
case _NotificationModel():
return $default(_that.success,_that.message,_that.data,_that.error);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool? success, String? message, NotificationData? data, ErrorModel? error)? $default,) {final _that = this;
switch (_that) {
case _NotificationModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _NotificationModel implements NotificationModel {
const _NotificationModel({required this.success, required this.message, required this.data, required this.error});
factory _NotificationModel.fromJson(Map<String, dynamic> json) => _$NotificationModelFromJson(json);
@override final bool? success;
@override final String? message;
@override final NotificationData? data;
@override final ErrorModel? error;
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$NotificationModelCopyWith<_NotificationModel> get copyWith => __$NotificationModelCopyWithImpl<_NotificationModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$NotificationModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NotificationModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error);
@override
String toString() {
return 'NotificationModel(success: $success, message: $message, data: $data, error: $error)';
}
}
/// @nodoc
abstract mixin class _$NotificationModelCopyWith<$Res> implements $NotificationModelCopyWith<$Res> {
factory _$NotificationModelCopyWith(_NotificationModel value, $Res Function(_NotificationModel) _then) = __$NotificationModelCopyWithImpl;
@override @useResult
$Res call({
bool? success, String? message, NotificationData? data, ErrorModel? error
});
@override $NotificationDataCopyWith<$Res>? get data;@override $ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class __$NotificationModelCopyWithImpl<$Res>
implements _$NotificationModelCopyWith<$Res> {
__$NotificationModelCopyWithImpl(this._self, this._then);
final _NotificationModel _self;
final $Res Function(_NotificationModel) _then;
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? success = freezed,Object? message = freezed,Object? data = freezed,Object? error = freezed,}) {
return _then(_NotificationModel(
success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as NotificationData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,
));
}
/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$NotificationDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $NotificationDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of NotificationModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
// dart format on
@@ -0,0 +1,29 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'notification_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_NotificationModel _$NotificationModelFromJson(Map<String, dynamic> json) =>
_NotificationModel(
success: json['success'] as bool?,
message: json['message'] as String?,
data:
json['data'] == null
? null
: NotificationData.fromJson(json['data'] as Map<String, dynamic>),
error:
json['error'] == null
? null
: ErrorModel.fromJson(json['error'] as Map<String, dynamic>),
);
Map<String, dynamic> _$NotificationModelToJson(_NotificationModel instance) =>
<String, dynamic>{
'success': instance.success,
'message': instance.message,
'data': instance.data,
'error': instance.error,
};
@@ -0,0 +1,21 @@
// ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:tm_app/data/services/model/error/error_model.dart';
import 'package:tm_app/data/services/model/notification_data/notification_data.dart';
part 'notification_response_model.freezed.dart';
part 'notification_response_model.g.dart';
@freezed
abstract class NotificationResponseModel with _$NotificationResponseModel {
const factory NotificationResponseModel({
required bool? success,
required String? message,
required NotificationData? data,
required ErrorModel? error,
}) = _NotificationResponseModel;
factory NotificationResponseModel.fromJson(Map<String, Object?> json) =>
_$NotificationResponseModelFromJson(json);
}
@@ -0,0 +1,334 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// 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 'notification_response_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$NotificationResponseModel {
bool? get success; String? get message; NotificationData? get data; ErrorModel? get error;
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$NotificationResponseModelCopyWith<NotificationResponseModel> get copyWith => _$NotificationResponseModelCopyWithImpl<NotificationResponseModel>(this as NotificationResponseModel, _$identity);
/// Serializes this NotificationResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error);
@override
String toString() {
return 'NotificationResponseModel(success: $success, message: $message, data: $data, error: $error)';
}
}
/// @nodoc
abstract mixin class $NotificationResponseModelCopyWith<$Res> {
factory $NotificationResponseModelCopyWith(NotificationResponseModel value, $Res Function(NotificationResponseModel) _then) = _$NotificationResponseModelCopyWithImpl;
@useResult
$Res call({
bool? success, String? message, NotificationData? data, ErrorModel? error
});
$NotificationDataCopyWith<$Res>? get data;$ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class _$NotificationResponseModelCopyWithImpl<$Res>
implements $NotificationResponseModelCopyWith<$Res> {
_$NotificationResponseModelCopyWithImpl(this._self, this._then);
final NotificationResponseModel _self;
final $Res Function(NotificationResponseModel) _then;
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? success = freezed,Object? message = freezed,Object? data = freezed,Object? error = freezed,}) {
return _then(_self.copyWith(
success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as NotificationData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,
));
}
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$NotificationDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $NotificationDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
/// Adds pattern-matching-related methods to [NotificationResponseModel].
extension NotificationResponseModelPatterns on NotificationResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _NotificationResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _NotificationResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _NotificationResponseModel value) $default,){
final _that = this;
switch (_that) {
case _NotificationResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _NotificationResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _NotificationResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool? success, String? message, NotificationData? data, ErrorModel? error)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _NotificationResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool? success, String? message, NotificationData? data, ErrorModel? error) $default,) {final _that = this;
switch (_that) {
case _NotificationResponseModel():
return $default(_that.success,_that.message,_that.data,_that.error);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool? success, String? message, NotificationData? data, ErrorModel? error)? $default,) {final _that = this;
switch (_that) {
case _NotificationResponseModel() when $default != null:
return $default(_that.success,_that.message,_that.data,_that.error);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _NotificationResponseModel implements NotificationResponseModel {
const _NotificationResponseModel({required this.success, required this.message, required this.data, required this.error});
factory _NotificationResponseModel.fromJson(Map<String, dynamic> json) => _$NotificationResponseModelFromJson(json);
@override final bool? success;
@override final String? message;
@override final NotificationData? data;
@override final ErrorModel? error;
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$NotificationResponseModelCopyWith<_NotificationResponseModel> get copyWith => __$NotificationResponseModelCopyWithImpl<_NotificationResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$NotificationResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NotificationResponseModel&&(identical(other.success, success) || other.success == success)&&(identical(other.message, message) || other.message == message)&&(identical(other.data, data) || other.data == data)&&(identical(other.error, error) || other.error == error));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,success,message,data,error);
@override
String toString() {
return 'NotificationResponseModel(success: $success, message: $message, data: $data, error: $error)';
}
}
/// @nodoc
abstract mixin class _$NotificationResponseModelCopyWith<$Res> implements $NotificationResponseModelCopyWith<$Res> {
factory _$NotificationResponseModelCopyWith(_NotificationResponseModel value, $Res Function(_NotificationResponseModel) _then) = __$NotificationResponseModelCopyWithImpl;
@override @useResult
$Res call({
bool? success, String? message, NotificationData? data, ErrorModel? error
});
@override $NotificationDataCopyWith<$Res>? get data;@override $ErrorModelCopyWith<$Res>? get error;
}
/// @nodoc
class __$NotificationResponseModelCopyWithImpl<$Res>
implements _$NotificationResponseModelCopyWith<$Res> {
__$NotificationResponseModelCopyWithImpl(this._self, this._then);
final _NotificationResponseModel _self;
final $Res Function(_NotificationResponseModel) _then;
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? success = freezed,Object? message = freezed,Object? data = freezed,Object? error = freezed,}) {
return _then(_NotificationResponseModel(
success: freezed == success ? _self.success : success // ignore: cast_nullable_to_non_nullable
as bool?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as NotificationData?,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
as ErrorModel?,
));
}
/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$NotificationDataCopyWith<$Res>? get data {
if (_self.data == null) {
return null;
}
return $NotificationDataCopyWith<$Res>(_self.data!, (value) {
return _then(_self.copyWith(data: value));
});
}/// Create a copy of NotificationResponseModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ErrorModelCopyWith<$Res>? get error {
if (_self.error == null) {
return null;
}
return $ErrorModelCopyWith<$Res>(_self.error!, (value) {
return _then(_self.copyWith(error: value));
});
}
}
// dart format on
@@ -0,0 +1,31 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'notification_response_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_NotificationResponseModel _$NotificationResponseModelFromJson(
Map<String, dynamic> json,
) => _NotificationResponseModel(
success: json['success'] as bool?,
message: json['message'] as String?,
data:
json['data'] == null
? null
: NotificationData.fromJson(json['data'] as Map<String, dynamic>),
error:
json['error'] == null
? null
: ErrorModel.fromJson(json['error'] as Map<String, dynamic>),
);
Map<String, dynamic> _$NotificationResponseModelToJson(
_NotificationResponseModel instance,
) => <String, dynamic>{
'success': instance.success,
'message': instance.message,
'data': instance.data,
'error': instance.error,
};
@@ -0,0 +1,46 @@
// ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:tm_app/data/services/model/meta/meta.dart';
part 'notification_data.freezed.dart';
part 'notification_data.g.dart';
@freezed
abstract class NotificationData with _$NotificationData {
const factory NotificationData({
required List<NotificationItem>? notifications,
required Meta? meta,
}) = _NotificationData;
factory NotificationData.fromJson(Map<String, Object?> json) =>
_$NotificationDataFromJson(json);
}
@freezed
abstract class NotificationItem with _$NotificationItem {
const factory NotificationItem({
required String? id,
@JsonKey(name: 'user_id') required String? userId,
required String? title,
required String? message,
required String? link,
required String? image,
required String? priority,
required String? type,
@JsonKey(name: 'event_type') required String? eventType,
required String? status,
required Map<String, dynamic>? methods,
required Map<String, dynamic>? metadata,
@JsonKey(name: 'schedule_at') required int? scheduleAt,
@JsonKey(name: 'created_at') required String? createdAt,
@JsonKey(name: 'updated_at') required String? updatedAt,
required bool? seen,
@JsonKey(name: 'seen_at') required int? seenAt,
@JsonKey(name: 'is_scheduled') required bool? isScheduled,
@JsonKey(name: 'scheduled_at') required int? scheduledAt,
}) = _NotificationItem;
factory NotificationItem.fromJson(Map<String, Object?> json) =>
_$NotificationItemFromJson(json);
}
@@ -0,0 +1,645 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// 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 'notification_data.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$NotificationData {
List<NotificationItem>? get notifications; Meta? get meta;
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$NotificationDataCopyWith<NotificationData> get copyWith => _$NotificationDataCopyWithImpl<NotificationData>(this as NotificationData, _$identity);
/// Serializes this NotificationData to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationData&&const DeepCollectionEquality().equals(other.notifications, notifications)&&(identical(other.meta, meta) || other.meta == meta));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(notifications),meta);
@override
String toString() {
return 'NotificationData(notifications: $notifications, meta: $meta)';
}
}
/// @nodoc
abstract mixin class $NotificationDataCopyWith<$Res> {
factory $NotificationDataCopyWith(NotificationData value, $Res Function(NotificationData) _then) = _$NotificationDataCopyWithImpl;
@useResult
$Res call({
List<NotificationItem>? notifications, Meta? meta
});
$MetaCopyWith<$Res>? get meta;
}
/// @nodoc
class _$NotificationDataCopyWithImpl<$Res>
implements $NotificationDataCopyWith<$Res> {
_$NotificationDataCopyWithImpl(this._self, this._then);
final NotificationData _self;
final $Res Function(NotificationData) _then;
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? notifications = freezed,Object? meta = freezed,}) {
return _then(_self.copyWith(
notifications: freezed == notifications ? _self.notifications : notifications // ignore: cast_nullable_to_non_nullable
as List<NotificationItem>?,meta: freezed == meta ? _self.meta : meta // ignore: cast_nullable_to_non_nullable
as Meta?,
));
}
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$MetaCopyWith<$Res>? get meta {
if (_self.meta == null) {
return null;
}
return $MetaCopyWith<$Res>(_self.meta!, (value) {
return _then(_self.copyWith(meta: value));
});
}
}
/// Adds pattern-matching-related methods to [NotificationData].
extension NotificationDataPatterns on NotificationData {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _NotificationData value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _NotificationData() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _NotificationData value) $default,){
final _that = this;
switch (_that) {
case _NotificationData():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _NotificationData value)? $default,){
final _that = this;
switch (_that) {
case _NotificationData() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<NotificationItem>? notifications, Meta? meta)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _NotificationData() when $default != null:
return $default(_that.notifications,_that.meta);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<NotificationItem>? notifications, Meta? meta) $default,) {final _that = this;
switch (_that) {
case _NotificationData():
return $default(_that.notifications,_that.meta);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<NotificationItem>? notifications, Meta? meta)? $default,) {final _that = this;
switch (_that) {
case _NotificationData() when $default != null:
return $default(_that.notifications,_that.meta);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _NotificationData implements NotificationData {
const _NotificationData({required final List<NotificationItem>? notifications, required this.meta}): _notifications = notifications;
factory _NotificationData.fromJson(Map<String, dynamic> json) => _$NotificationDataFromJson(json);
final List<NotificationItem>? _notifications;
@override List<NotificationItem>? get notifications {
final value = _notifications;
if (value == null) return null;
if (_notifications is EqualUnmodifiableListView) return _notifications;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override final Meta? meta;
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$NotificationDataCopyWith<_NotificationData> get copyWith => __$NotificationDataCopyWithImpl<_NotificationData>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$NotificationDataToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NotificationData&&const DeepCollectionEquality().equals(other._notifications, _notifications)&&(identical(other.meta, meta) || other.meta == meta));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_notifications),meta);
@override
String toString() {
return 'NotificationData(notifications: $notifications, meta: $meta)';
}
}
/// @nodoc
abstract mixin class _$NotificationDataCopyWith<$Res> implements $NotificationDataCopyWith<$Res> {
factory _$NotificationDataCopyWith(_NotificationData value, $Res Function(_NotificationData) _then) = __$NotificationDataCopyWithImpl;
@override @useResult
$Res call({
List<NotificationItem>? notifications, Meta? meta
});
@override $MetaCopyWith<$Res>? get meta;
}
/// @nodoc
class __$NotificationDataCopyWithImpl<$Res>
implements _$NotificationDataCopyWith<$Res> {
__$NotificationDataCopyWithImpl(this._self, this._then);
final _NotificationData _self;
final $Res Function(_NotificationData) _then;
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? notifications = freezed,Object? meta = freezed,}) {
return _then(_NotificationData(
notifications: freezed == notifications ? _self._notifications : notifications // ignore: cast_nullable_to_non_nullable
as List<NotificationItem>?,meta: freezed == meta ? _self.meta : meta // ignore: cast_nullable_to_non_nullable
as Meta?,
));
}
/// Create a copy of NotificationData
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$MetaCopyWith<$Res>? get meta {
if (_self.meta == null) {
return null;
}
return $MetaCopyWith<$Res>(_self.meta!, (value) {
return _then(_self.copyWith(meta: value));
});
}
}
/// @nodoc
mixin _$NotificationItem {
String? get id;@JsonKey(name: 'user_id') String? get userId; String? get title; String? get message; String? get link; String? get image; String? get priority; String? get type;@JsonKey(name: 'event_type') String? get eventType; String? get status; Map<String, dynamic>? get methods; Map<String, dynamic>? get metadata;@JsonKey(name: 'schedule_at') int? get scheduleAt;@JsonKey(name: 'created_at') String? get createdAt;@JsonKey(name: 'updated_at') String? get updatedAt; bool? get seen;@JsonKey(name: 'seen_at') int? get seenAt;@JsonKey(name: 'is_scheduled') bool? get isScheduled;@JsonKey(name: 'scheduled_at') int? get scheduledAt;
/// Create a copy of NotificationItem
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$NotificationItemCopyWith<NotificationItem> get copyWith => _$NotificationItemCopyWithImpl<NotificationItem>(this as NotificationItem, _$identity);
/// Serializes this NotificationItem to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is NotificationItem&&(identical(other.id, id) || other.id == id)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.title, title) || other.title == title)&&(identical(other.message, message) || other.message == message)&&(identical(other.link, link) || other.link == link)&&(identical(other.image, image) || other.image == image)&&(identical(other.priority, priority) || other.priority == priority)&&(identical(other.type, type) || other.type == type)&&(identical(other.eventType, eventType) || other.eventType == eventType)&&(identical(other.status, status) || other.status == status)&&const DeepCollectionEquality().equals(other.methods, methods)&&const DeepCollectionEquality().equals(other.metadata, metadata)&&(identical(other.scheduleAt, scheduleAt) || other.scheduleAt == scheduleAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.seen, seen) || other.seen == seen)&&(identical(other.seenAt, seenAt) || other.seenAt == seenAt)&&(identical(other.isScheduled, isScheduled) || other.isScheduled == isScheduled)&&(identical(other.scheduledAt, scheduledAt) || other.scheduledAt == scheduledAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hashAll([runtimeType,id,userId,title,message,link,image,priority,type,eventType,status,const DeepCollectionEquality().hash(methods),const DeepCollectionEquality().hash(metadata),scheduleAt,createdAt,updatedAt,seen,seenAt,isScheduled,scheduledAt]);
@override
String toString() {
return 'NotificationItem(id: $id, userId: $userId, title: $title, message: $message, link: $link, image: $image, priority: $priority, type: $type, eventType: $eventType, status: $status, methods: $methods, metadata: $metadata, scheduleAt: $scheduleAt, createdAt: $createdAt, updatedAt: $updatedAt, seen: $seen, seenAt: $seenAt, isScheduled: $isScheduled, scheduledAt: $scheduledAt)';
}
}
/// @nodoc
abstract mixin class $NotificationItemCopyWith<$Res> {
factory $NotificationItemCopyWith(NotificationItem value, $Res Function(NotificationItem) _then) = _$NotificationItemCopyWithImpl;
@useResult
$Res call({
String? id,@JsonKey(name: 'user_id') String? userId, String? title, String? message, String? link, String? image, String? priority, String? type,@JsonKey(name: 'event_type') String? eventType, String? status, Map<String, dynamic>? methods, Map<String, dynamic>? metadata,@JsonKey(name: 'schedule_at') int? scheduleAt,@JsonKey(name: 'created_at') String? createdAt,@JsonKey(name: 'updated_at') String? updatedAt, bool? seen,@JsonKey(name: 'seen_at') int? seenAt,@JsonKey(name: 'is_scheduled') bool? isScheduled,@JsonKey(name: 'scheduled_at') int? scheduledAt
});
}
/// @nodoc
class _$NotificationItemCopyWithImpl<$Res>
implements $NotificationItemCopyWith<$Res> {
_$NotificationItemCopyWithImpl(this._self, this._then);
final NotificationItem _self;
final $Res Function(NotificationItem) _then;
/// Create a copy of NotificationItem
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? userId = freezed,Object? title = freezed,Object? message = freezed,Object? link = freezed,Object? image = freezed,Object? priority = freezed,Object? type = freezed,Object? eventType = freezed,Object? status = freezed,Object? methods = freezed,Object? metadata = freezed,Object? scheduleAt = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? seen = freezed,Object? seenAt = freezed,Object? isScheduled = freezed,Object? scheduledAt = freezed,}) {
return _then(_self.copyWith(
id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
as String?,title: freezed == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
as String?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,link: freezed == link ? _self.link : link // ignore: cast_nullable_to_non_nullable
as String?,image: freezed == image ? _self.image : image // ignore: cast_nullable_to_non_nullable
as String?,priority: freezed == priority ? _self.priority : priority // ignore: cast_nullable_to_non_nullable
as String?,type: freezed == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String?,eventType: freezed == eventType ? _self.eventType : eventType // ignore: cast_nullable_to_non_nullable
as String?,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as String?,methods: freezed == methods ? _self.methods : methods // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,metadata: freezed == metadata ? _self.metadata : metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,scheduleAt: freezed == scheduleAt ? _self.scheduleAt : scheduleAt // ignore: cast_nullable_to_non_nullable
as int?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as String?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as String?,seen: freezed == seen ? _self.seen : seen // ignore: cast_nullable_to_non_nullable
as bool?,seenAt: freezed == seenAt ? _self.seenAt : seenAt // ignore: cast_nullable_to_non_nullable
as int?,isScheduled: freezed == isScheduled ? _self.isScheduled : isScheduled // ignore: cast_nullable_to_non_nullable
as bool?,scheduledAt: freezed == scheduledAt ? _self.scheduledAt : scheduledAt // ignore: cast_nullable_to_non_nullable
as int?,
));
}
}
/// Adds pattern-matching-related methods to [NotificationItem].
extension NotificationItemPatterns on NotificationItem {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _NotificationItem value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _NotificationItem() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _NotificationItem value) $default,){
final _that = this;
switch (_that) {
case _NotificationItem():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _NotificationItem value)? $default,){
final _that = this;
switch (_that) {
case _NotificationItem() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String? id, @JsonKey(name: 'user_id') String? userId, String? title, String? message, String? link, String? image, String? priority, String? type, @JsonKey(name: 'event_type') String? eventType, String? status, Map<String, dynamic>? methods, Map<String, dynamic>? metadata, @JsonKey(name: 'schedule_at') int? scheduleAt, @JsonKey(name: 'created_at') String? createdAt, @JsonKey(name: 'updated_at') String? updatedAt, bool? seen, @JsonKey(name: 'seen_at') int? seenAt, @JsonKey(name: 'is_scheduled') bool? isScheduled, @JsonKey(name: 'scheduled_at') int? scheduledAt)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _NotificationItem() when $default != null:
return $default(_that.id,_that.userId,_that.title,_that.message,_that.link,_that.image,_that.priority,_that.type,_that.eventType,_that.status,_that.methods,_that.metadata,_that.scheduleAt,_that.createdAt,_that.updatedAt,_that.seen,_that.seenAt,_that.isScheduled,_that.scheduledAt);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String? id, @JsonKey(name: 'user_id') String? userId, String? title, String? message, String? link, String? image, String? priority, String? type, @JsonKey(name: 'event_type') String? eventType, String? status, Map<String, dynamic>? methods, Map<String, dynamic>? metadata, @JsonKey(name: 'schedule_at') int? scheduleAt, @JsonKey(name: 'created_at') String? createdAt, @JsonKey(name: 'updated_at') String? updatedAt, bool? seen, @JsonKey(name: 'seen_at') int? seenAt, @JsonKey(name: 'is_scheduled') bool? isScheduled, @JsonKey(name: 'scheduled_at') int? scheduledAt) $default,) {final _that = this;
switch (_that) {
case _NotificationItem():
return $default(_that.id,_that.userId,_that.title,_that.message,_that.link,_that.image,_that.priority,_that.type,_that.eventType,_that.status,_that.methods,_that.metadata,_that.scheduleAt,_that.createdAt,_that.updatedAt,_that.seen,_that.seenAt,_that.isScheduled,_that.scheduledAt);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String? id, @JsonKey(name: 'user_id') String? userId, String? title, String? message, String? link, String? image, String? priority, String? type, @JsonKey(name: 'event_type') String? eventType, String? status, Map<String, dynamic>? methods, Map<String, dynamic>? metadata, @JsonKey(name: 'schedule_at') int? scheduleAt, @JsonKey(name: 'created_at') String? createdAt, @JsonKey(name: 'updated_at') String? updatedAt, bool? seen, @JsonKey(name: 'seen_at') int? seenAt, @JsonKey(name: 'is_scheduled') bool? isScheduled, @JsonKey(name: 'scheduled_at') int? scheduledAt)? $default,) {final _that = this;
switch (_that) {
case _NotificationItem() when $default != null:
return $default(_that.id,_that.userId,_that.title,_that.message,_that.link,_that.image,_that.priority,_that.type,_that.eventType,_that.status,_that.methods,_that.metadata,_that.scheduleAt,_that.createdAt,_that.updatedAt,_that.seen,_that.seenAt,_that.isScheduled,_that.scheduledAt);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _NotificationItem implements NotificationItem {
const _NotificationItem({required this.id, @JsonKey(name: 'user_id') required this.userId, required this.title, required this.message, required this.link, required this.image, required this.priority, required this.type, @JsonKey(name: 'event_type') required this.eventType, required this.status, required final Map<String, dynamic>? methods, required final Map<String, dynamic>? metadata, @JsonKey(name: 'schedule_at') required this.scheduleAt, @JsonKey(name: 'created_at') required this.createdAt, @JsonKey(name: 'updated_at') required this.updatedAt, required this.seen, @JsonKey(name: 'seen_at') required this.seenAt, @JsonKey(name: 'is_scheduled') required this.isScheduled, @JsonKey(name: 'scheduled_at') required this.scheduledAt}): _methods = methods,_metadata = metadata;
factory _NotificationItem.fromJson(Map<String, dynamic> json) => _$NotificationItemFromJson(json);
@override final String? id;
@override@JsonKey(name: 'user_id') final String? userId;
@override final String? title;
@override final String? message;
@override final String? link;
@override final String? image;
@override final String? priority;
@override final String? type;
@override@JsonKey(name: 'event_type') final String? eventType;
@override final String? status;
final Map<String, dynamic>? _methods;
@override Map<String, dynamic>? get methods {
final value = _methods;
if (value == null) return null;
if (_methods is EqualUnmodifiableMapView) return _methods;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
final Map<String, dynamic>? _metadata;
@override Map<String, dynamic>? get metadata {
final value = _metadata;
if (value == null) return null;
if (_metadata is EqualUnmodifiableMapView) return _metadata;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override@JsonKey(name: 'schedule_at') final int? scheduleAt;
@override@JsonKey(name: 'created_at') final String? createdAt;
@override@JsonKey(name: 'updated_at') final String? updatedAt;
@override final bool? seen;
@override@JsonKey(name: 'seen_at') final int? seenAt;
@override@JsonKey(name: 'is_scheduled') final bool? isScheduled;
@override@JsonKey(name: 'scheduled_at') final int? scheduledAt;
/// Create a copy of NotificationItem
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$NotificationItemCopyWith<_NotificationItem> get copyWith => __$NotificationItemCopyWithImpl<_NotificationItem>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$NotificationItemToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _NotificationItem&&(identical(other.id, id) || other.id == id)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.title, title) || other.title == title)&&(identical(other.message, message) || other.message == message)&&(identical(other.link, link) || other.link == link)&&(identical(other.image, image) || other.image == image)&&(identical(other.priority, priority) || other.priority == priority)&&(identical(other.type, type) || other.type == type)&&(identical(other.eventType, eventType) || other.eventType == eventType)&&(identical(other.status, status) || other.status == status)&&const DeepCollectionEquality().equals(other._methods, _methods)&&const DeepCollectionEquality().equals(other._metadata, _metadata)&&(identical(other.scheduleAt, scheduleAt) || other.scheduleAt == scheduleAt)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.seen, seen) || other.seen == seen)&&(identical(other.seenAt, seenAt) || other.seenAt == seenAt)&&(identical(other.isScheduled, isScheduled) || other.isScheduled == isScheduled)&&(identical(other.scheduledAt, scheduledAt) || other.scheduledAt == scheduledAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hashAll([runtimeType,id,userId,title,message,link,image,priority,type,eventType,status,const DeepCollectionEquality().hash(_methods),const DeepCollectionEquality().hash(_metadata),scheduleAt,createdAt,updatedAt,seen,seenAt,isScheduled,scheduledAt]);
@override
String toString() {
return 'NotificationItem(id: $id, userId: $userId, title: $title, message: $message, link: $link, image: $image, priority: $priority, type: $type, eventType: $eventType, status: $status, methods: $methods, metadata: $metadata, scheduleAt: $scheduleAt, createdAt: $createdAt, updatedAt: $updatedAt, seen: $seen, seenAt: $seenAt, isScheduled: $isScheduled, scheduledAt: $scheduledAt)';
}
}
/// @nodoc
abstract mixin class _$NotificationItemCopyWith<$Res> implements $NotificationItemCopyWith<$Res> {
factory _$NotificationItemCopyWith(_NotificationItem value, $Res Function(_NotificationItem) _then) = __$NotificationItemCopyWithImpl;
@override @useResult
$Res call({
String? id,@JsonKey(name: 'user_id') String? userId, String? title, String? message, String? link, String? image, String? priority, String? type,@JsonKey(name: 'event_type') String? eventType, String? status, Map<String, dynamic>? methods, Map<String, dynamic>? metadata,@JsonKey(name: 'schedule_at') int? scheduleAt,@JsonKey(name: 'created_at') String? createdAt,@JsonKey(name: 'updated_at') String? updatedAt, bool? seen,@JsonKey(name: 'seen_at') int? seenAt,@JsonKey(name: 'is_scheduled') bool? isScheduled,@JsonKey(name: 'scheduled_at') int? scheduledAt
});
}
/// @nodoc
class __$NotificationItemCopyWithImpl<$Res>
implements _$NotificationItemCopyWith<$Res> {
__$NotificationItemCopyWithImpl(this._self, this._then);
final _NotificationItem _self;
final $Res Function(_NotificationItem) _then;
/// Create a copy of NotificationItem
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = freezed,Object? userId = freezed,Object? title = freezed,Object? message = freezed,Object? link = freezed,Object? image = freezed,Object? priority = freezed,Object? type = freezed,Object? eventType = freezed,Object? status = freezed,Object? methods = freezed,Object? metadata = freezed,Object? scheduleAt = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? seen = freezed,Object? seenAt = freezed,Object? isScheduled = freezed,Object? scheduledAt = freezed,}) {
return _then(_NotificationItem(
id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
as String?,title: freezed == title ? _self.title : title // ignore: cast_nullable_to_non_nullable
as String?,message: freezed == message ? _self.message : message // ignore: cast_nullable_to_non_nullable
as String?,link: freezed == link ? _self.link : link // ignore: cast_nullable_to_non_nullable
as String?,image: freezed == image ? _self.image : image // ignore: cast_nullable_to_non_nullable
as String?,priority: freezed == priority ? _self.priority : priority // ignore: cast_nullable_to_non_nullable
as String?,type: freezed == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String?,eventType: freezed == eventType ? _self.eventType : eventType // ignore: cast_nullable_to_non_nullable
as String?,status: freezed == status ? _self.status : status // ignore: cast_nullable_to_non_nullable
as String?,methods: freezed == methods ? _self._methods : methods // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,metadata: freezed == metadata ? _self._metadata : metadata // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,scheduleAt: freezed == scheduleAt ? _self.scheduleAt : scheduleAt // ignore: cast_nullable_to_non_nullable
as int?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as String?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as String?,seen: freezed == seen ? _self.seen : seen // ignore: cast_nullable_to_non_nullable
as bool?,seenAt: freezed == seenAt ? _self.seenAt : seenAt // ignore: cast_nullable_to_non_nullable
as int?,isScheduled: freezed == isScheduled ? _self.isScheduled : isScheduled // ignore: cast_nullable_to_non_nullable
as bool?,scheduledAt: freezed == scheduledAt ? _self.scheduledAt : scheduledAt // ignore: cast_nullable_to_non_nullable
as int?,
));
}
}
// dart format on
@@ -0,0 +1,71 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'notification_data.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_NotificationData _$NotificationDataFromJson(Map<String, dynamic> json) =>
_NotificationData(
notifications:
(json['notifications'] as List<dynamic>?)
?.map((e) => NotificationItem.fromJson(e as Map<String, dynamic>))
.toList(),
meta:
json['meta'] == null
? null
: Meta.fromJson(json['meta'] as Map<String, dynamic>),
);
Map<String, dynamic> _$NotificationDataToJson(_NotificationData instance) =>
<String, dynamic>{
'notifications': instance.notifications,
'meta': instance.meta,
};
_NotificationItem _$NotificationItemFromJson(Map<String, dynamic> json) =>
_NotificationItem(
id: json['id'] as String?,
userId: json['user_id'] as String?,
title: json['title'] as String?,
message: json['message'] as String?,
link: json['link'] as String?,
image: json['image'] as String?,
priority: json['priority'] as String?,
type: json['type'] as String?,
eventType: json['event_type'] as String?,
status: json['status'] as String?,
methods: json['methods'] as Map<String, dynamic>?,
metadata: json['metadata'] as Map<String, dynamic>?,
scheduleAt: (json['schedule_at'] as num?)?.toInt(),
createdAt: json['created_at'] as String?,
updatedAt: json['updated_at'] as String?,
seen: json['seen'] as bool?,
seenAt: (json['seen_at'] as num?)?.toInt(),
isScheduled: json['is_scheduled'] as bool?,
scheduledAt: (json['scheduled_at'] as num?)?.toInt(),
);
Map<String, dynamic> _$NotificationItemToJson(_NotificationItem instance) =>
<String, dynamic>{
'id': instance.id,
'user_id': instance.userId,
'title': instance.title,
'message': instance.message,
'link': instance.link,
'image': instance.image,
'priority': instance.priority,
'type': instance.type,
'event_type': instance.eventType,
'status': instance.status,
'methods': instance.methods,
'metadata': instance.metadata,
'schedule_at': instance.scheduleAt,
'created_at': instance.createdAt,
'updated_at': instance.updatedAt,
'seen': instance.seen,
'seen_at': instance.seenAt,
'is_scheduled': instance.isScheduled,
'scheduled_at': instance.scheduledAt,
};
@@ -0,0 +1,48 @@
// notification_service.dart
import 'dart:convert';
import 'package:tm_app/data/services/api/notification_api.dart';
import 'package:tm_app/data/services/model/notification__response/notification_response_model.dart';
import 'package:tm_app/core/utils/result.dart';
import '../../core/network/network_manager.dart';
class NotificationsService {
NotificationsService({required NetworkManager networkManager})
: _networkManager = networkManager;
final NetworkManager _networkManager;
Future<Result<NotificationResponseModel>> getNotifications({
required int limit,
required int offset,
}) async {
final result = await _networkManager.makeRequest(
NotificationApi.getNotifications(limit: limit, offset: offset),
//NotificationApi.notifications,
method: 'GET',
(json) => NotificationResponseModel.fromJson(json),
);
return result;
}
Future<Result<NotificationResponseModel>> markAllAsRead() async {
final result = await _networkManager.makeRequest(
NotificationApi.markAllAsRead,
method: 'POST',
(json) => NotificationResponseModel.fromJson(json),
);
return result;
}
Future<Result<NotificationResponseModel>> markAsRead({
required String notificationId,
}) async {
final data = jsonEncode({'notification_id': notificationId});
final result = await _networkManager.makeRequest(
NotificationApi.markAsRead,
method: 'POST',
(json) => NotificationResponseModel.fromJson(json),
data: data,
);
return result;
}
}