feedback response model changes

This commit is contained in:
amirrezaghabeli
2025-09-25 09:01:10 +03:30
parent 9a0a74af97
commit eee1d9cdd8
4 changed files with 77 additions and 38 deletions
@@ -2,6 +2,8 @@
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import '../tender_data/tender_data.dart';
part 'feedback_data.freezed.dart'; part 'feedback_data.freezed.dart';
part 'feedback_data.g.dart'; part 'feedback_data.g.dart';
@@ -13,7 +15,8 @@ abstract class FeedbackData with _$FeedbackData {
@JsonKey(name: 'customer_id') required String? customerId, @JsonKey(name: 'customer_id') required String? customerId,
@JsonKey(name: 'feedback_type') required String? feedbackType, @JsonKey(name: 'feedback_type') required String? feedbackType,
@JsonKey(name: 'id') required String? id, @JsonKey(name: 'id') required String? id,
@JsonKey(name: 'tender') required String? tender, @JsonKey(name: 'tender_id') required String? tenderId,
@JsonKey(name: 'tender') required TenderData? tender,
@JsonKey(name: 'updated_at') required int? updatedAt, @JsonKey(name: 'updated_at') required int? updatedAt,
}) = _FeedbackData; }) = _FeedbackData;
@@ -15,7 +15,7 @@ T _$identity<T>(T value) => value;
/// @nodoc /// @nodoc
mixin _$FeedbackData { mixin _$FeedbackData {
@JsonKey(name: 'company_id') String? get companyId;@JsonKey(name: 'created_at') int? get createdAt;@JsonKey(name: 'customer_id') String? get customerId;@JsonKey(name: 'feedback_type') String? get feedbackType;@JsonKey(name: 'id') String? get id;@JsonKey(name: 'tender') String? get tender;@JsonKey(name: 'updated_at') int? get updatedAt; @JsonKey(name: 'company_id') String? get companyId;@JsonKey(name: 'created_at') int? get createdAt;@JsonKey(name: 'customer_id') String? get customerId;@JsonKey(name: 'feedback_type') String? get feedbackType;@JsonKey(name: 'id') String? get id;@JsonKey(name: 'tender_id') String? get tenderId;@JsonKey(name: 'tender') TenderData? get tender;@JsonKey(name: 'updated_at') int? get updatedAt;
/// Create a copy of FeedbackData /// Create a copy of FeedbackData
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@@ -28,16 +28,16 @@ $FeedbackDataCopyWith<FeedbackData> get copyWith => _$FeedbackDataCopyWithImpl<F
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is FeedbackData&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.customerId, customerId) || other.customerId == customerId)&&(identical(other.feedbackType, feedbackType) || other.feedbackType == feedbackType)&&(identical(other.id, id) || other.id == id)&&(identical(other.tender, tender) || other.tender == tender)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)); return identical(this, other) || (other.runtimeType == runtimeType&&other is FeedbackData&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.customerId, customerId) || other.customerId == customerId)&&(identical(other.feedbackType, feedbackType) || other.feedbackType == feedbackType)&&(identical(other.id, id) || other.id == id)&&(identical(other.tenderId, tenderId) || other.tenderId == tenderId)&&(identical(other.tender, tender) || other.tender == tender)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@override @override
int get hashCode => Object.hash(runtimeType,companyId,createdAt,customerId,feedbackType,id,tender,updatedAt); int get hashCode => Object.hash(runtimeType,companyId,createdAt,customerId,feedbackType,id,tenderId,tender,updatedAt);
@override @override
String toString() { String toString() {
return 'FeedbackData(companyId: $companyId, createdAt: $createdAt, customerId: $customerId, feedbackType: $feedbackType, id: $id, tender: $tender, updatedAt: $updatedAt)'; return 'FeedbackData(companyId: $companyId, createdAt: $createdAt, customerId: $customerId, feedbackType: $feedbackType, id: $id, tenderId: $tenderId, tender: $tender, updatedAt: $updatedAt)';
} }
@@ -48,11 +48,11 @@ abstract mixin class $FeedbackDataCopyWith<$Res> {
factory $FeedbackDataCopyWith(FeedbackData value, $Res Function(FeedbackData) _then) = _$FeedbackDataCopyWithImpl; factory $FeedbackDataCopyWith(FeedbackData value, $Res Function(FeedbackData) _then) = _$FeedbackDataCopyWithImpl;
@useResult @useResult
$Res call({ $Res call({
@JsonKey(name: 'company_id') String? companyId,@JsonKey(name: 'created_at') int? createdAt,@JsonKey(name: 'customer_id') String? customerId,@JsonKey(name: 'feedback_type') String? feedbackType,@JsonKey(name: 'id') String? id,@JsonKey(name: 'tender') String? tender,@JsonKey(name: 'updated_at') int? updatedAt @JsonKey(name: 'company_id') String? companyId,@JsonKey(name: 'created_at') int? createdAt,@JsonKey(name: 'customer_id') String? customerId,@JsonKey(name: 'feedback_type') String? feedbackType,@JsonKey(name: 'id') String? id,@JsonKey(name: 'tender_id') String? tenderId,@JsonKey(name: 'tender') TenderData? tender,@JsonKey(name: 'updated_at') int? updatedAt
}); });
$TenderDataCopyWith<$Res>? get tender;
} }
/// @nodoc /// @nodoc
@@ -65,19 +65,32 @@ class _$FeedbackDataCopyWithImpl<$Res>
/// Create a copy of FeedbackData /// Create a copy of FeedbackData
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? companyId = freezed,Object? createdAt = freezed,Object? customerId = freezed,Object? feedbackType = freezed,Object? id = freezed,Object? tender = freezed,Object? updatedAt = freezed,}) { @pragma('vm:prefer-inline') @override $Res call({Object? companyId = freezed,Object? createdAt = freezed,Object? customerId = freezed,Object? feedbackType = freezed,Object? id = freezed,Object? tenderId = freezed,Object? tender = freezed,Object? updatedAt = freezed,}) {
return _then(_self.copyWith( return _then(_self.copyWith(
companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable
as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as int?,customerId: freezed == customerId ? _self.customerId : customerId // ignore: cast_nullable_to_non_nullable as int?,customerId: freezed == customerId ? _self.customerId : customerId // ignore: cast_nullable_to_non_nullable
as String?,feedbackType: freezed == feedbackType ? _self.feedbackType : feedbackType // ignore: cast_nullable_to_non_nullable as String?,feedbackType: freezed == feedbackType ? _self.feedbackType : feedbackType // ignore: cast_nullable_to_non_nullable
as String?,id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String?,id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String?,tenderId: freezed == tenderId ? _self.tenderId : tenderId // ignore: cast_nullable_to_non_nullable
as String?,tender: freezed == tender ? _self.tender : tender // ignore: cast_nullable_to_non_nullable as String?,tender: freezed == tender ? _self.tender : tender // ignore: cast_nullable_to_non_nullable
as String?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as TenderData?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as int?, as int?,
)); ));
} }
/// Create a copy of FeedbackData
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TenderDataCopyWith<$Res>? get tender {
if (_self.tender == null) {
return null;
}
return $TenderDataCopyWith<$Res>(_self.tender!, (value) {
return _then(_self.copyWith(tender: value));
});
}
} }
@@ -159,10 +172,10 @@ return $default(_that);case _:
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender') String? tender, @JsonKey(name: 'updated_at') int? updatedAt)? $default,{required TResult orElse(),}) {final _that = this; @optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender_id') String? tenderId, @JsonKey(name: 'tender') TenderData? tender, @JsonKey(name: 'updated_at') int? updatedAt)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) { switch (_that) {
case _FeedbackData() when $default != null: case _FeedbackData() when $default != null:
return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tender,_that.updatedAt);case _: return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tenderId,_that.tender,_that.updatedAt);case _:
return orElse(); return orElse();
} }
@@ -180,10 +193,10 @@ return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackT
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender') String? tender, @JsonKey(name: 'updated_at') int? updatedAt) $default,) {final _that = this; @optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender_id') String? tenderId, @JsonKey(name: 'tender') TenderData? tender, @JsonKey(name: 'updated_at') int? updatedAt) $default,) {final _that = this;
switch (_that) { switch (_that) {
case _FeedbackData(): case _FeedbackData():
return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tender,_that.updatedAt);case _: return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tenderId,_that.tender,_that.updatedAt);case _:
throw StateError('Unexpected subclass'); throw StateError('Unexpected subclass');
} }
@@ -200,10 +213,10 @@ return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackT
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender') String? tender, @JsonKey(name: 'updated_at') int? updatedAt)? $default,) {final _that = this; @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'company_id') String? companyId, @JsonKey(name: 'created_at') int? createdAt, @JsonKey(name: 'customer_id') String? customerId, @JsonKey(name: 'feedback_type') String? feedbackType, @JsonKey(name: 'id') String? id, @JsonKey(name: 'tender_id') String? tenderId, @JsonKey(name: 'tender') TenderData? tender, @JsonKey(name: 'updated_at') int? updatedAt)? $default,) {final _that = this;
switch (_that) { switch (_that) {
case _FeedbackData() when $default != null: case _FeedbackData() when $default != null:
return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tender,_that.updatedAt);case _: return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackType,_that.id,_that.tenderId,_that.tender,_that.updatedAt);case _:
return null; return null;
} }
@@ -215,7 +228,7 @@ return $default(_that.companyId,_that.createdAt,_that.customerId,_that.feedbackT
@JsonSerializable() @JsonSerializable()
class _FeedbackData implements FeedbackData { class _FeedbackData implements FeedbackData {
const _FeedbackData({@JsonKey(name: 'company_id') required this.companyId, @JsonKey(name: 'created_at') required this.createdAt, @JsonKey(name: 'customer_id') required this.customerId, @JsonKey(name: 'feedback_type') required this.feedbackType, @JsonKey(name: 'id') required this.id, @JsonKey(name: 'tender') required this.tender, @JsonKey(name: 'updated_at') required this.updatedAt}); const _FeedbackData({@JsonKey(name: 'company_id') required this.companyId, @JsonKey(name: 'created_at') required this.createdAt, @JsonKey(name: 'customer_id') required this.customerId, @JsonKey(name: 'feedback_type') required this.feedbackType, @JsonKey(name: 'id') required this.id, @JsonKey(name: 'tender_id') required this.tenderId, @JsonKey(name: 'tender') required this.tender, @JsonKey(name: 'updated_at') required this.updatedAt});
factory _FeedbackData.fromJson(Map<String, dynamic> json) => _$FeedbackDataFromJson(json); factory _FeedbackData.fromJson(Map<String, dynamic> json) => _$FeedbackDataFromJson(json);
@override@JsonKey(name: 'company_id') final String? companyId; @override@JsonKey(name: 'company_id') final String? companyId;
@@ -223,7 +236,8 @@ class _FeedbackData implements FeedbackData {
@override@JsonKey(name: 'customer_id') final String? customerId; @override@JsonKey(name: 'customer_id') final String? customerId;
@override@JsonKey(name: 'feedback_type') final String? feedbackType; @override@JsonKey(name: 'feedback_type') final String? feedbackType;
@override@JsonKey(name: 'id') final String? id; @override@JsonKey(name: 'id') final String? id;
@override@JsonKey(name: 'tender') final String? tender; @override@JsonKey(name: 'tender_id') final String? tenderId;
@override@JsonKey(name: 'tender') final TenderData? tender;
@override@JsonKey(name: 'updated_at') final int? updatedAt; @override@JsonKey(name: 'updated_at') final int? updatedAt;
/// Create a copy of FeedbackData /// Create a copy of FeedbackData
@@ -239,16 +253,16 @@ Map<String, dynamic> toJson() {
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _FeedbackData&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.customerId, customerId) || other.customerId == customerId)&&(identical(other.feedbackType, feedbackType) || other.feedbackType == feedbackType)&&(identical(other.id, id) || other.id == id)&&(identical(other.tender, tender) || other.tender == tender)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)); return identical(this, other) || (other.runtimeType == runtimeType&&other is _FeedbackData&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.customerId, customerId) || other.customerId == customerId)&&(identical(other.feedbackType, feedbackType) || other.feedbackType == feedbackType)&&(identical(other.id, id) || other.id == id)&&(identical(other.tenderId, tenderId) || other.tenderId == tenderId)&&(identical(other.tender, tender) || other.tender == tender)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@override @override
int get hashCode => Object.hash(runtimeType,companyId,createdAt,customerId,feedbackType,id,tender,updatedAt); int get hashCode => Object.hash(runtimeType,companyId,createdAt,customerId,feedbackType,id,tenderId,tender,updatedAt);
@override @override
String toString() { String toString() {
return 'FeedbackData(companyId: $companyId, createdAt: $createdAt, customerId: $customerId, feedbackType: $feedbackType, id: $id, tender: $tender, updatedAt: $updatedAt)'; return 'FeedbackData(companyId: $companyId, createdAt: $createdAt, customerId: $customerId, feedbackType: $feedbackType, id: $id, tenderId: $tenderId, tender: $tender, updatedAt: $updatedAt)';
} }
@@ -259,11 +273,11 @@ abstract mixin class _$FeedbackDataCopyWith<$Res> implements $FeedbackDataCopyWi
factory _$FeedbackDataCopyWith(_FeedbackData value, $Res Function(_FeedbackData) _then) = __$FeedbackDataCopyWithImpl; factory _$FeedbackDataCopyWith(_FeedbackData value, $Res Function(_FeedbackData) _then) = __$FeedbackDataCopyWithImpl;
@override @useResult @override @useResult
$Res call({ $Res call({
@JsonKey(name: 'company_id') String? companyId,@JsonKey(name: 'created_at') int? createdAt,@JsonKey(name: 'customer_id') String? customerId,@JsonKey(name: 'feedback_type') String? feedbackType,@JsonKey(name: 'id') String? id,@JsonKey(name: 'tender') String? tender,@JsonKey(name: 'updated_at') int? updatedAt @JsonKey(name: 'company_id') String? companyId,@JsonKey(name: 'created_at') int? createdAt,@JsonKey(name: 'customer_id') String? customerId,@JsonKey(name: 'feedback_type') String? feedbackType,@JsonKey(name: 'id') String? id,@JsonKey(name: 'tender_id') String? tenderId,@JsonKey(name: 'tender') TenderData? tender,@JsonKey(name: 'updated_at') int? updatedAt
}); });
@override $TenderDataCopyWith<$Res>? get tender;
} }
/// @nodoc /// @nodoc
@@ -276,20 +290,33 @@ class __$FeedbackDataCopyWithImpl<$Res>
/// Create a copy of FeedbackData /// Create a copy of FeedbackData
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? companyId = freezed,Object? createdAt = freezed,Object? customerId = freezed,Object? feedbackType = freezed,Object? id = freezed,Object? tender = freezed,Object? updatedAt = freezed,}) { @override @pragma('vm:prefer-inline') $Res call({Object? companyId = freezed,Object? createdAt = freezed,Object? customerId = freezed,Object? feedbackType = freezed,Object? id = freezed,Object? tenderId = freezed,Object? tender = freezed,Object? updatedAt = freezed,}) {
return _then(_FeedbackData( return _then(_FeedbackData(
companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable
as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as int?,customerId: freezed == customerId ? _self.customerId : customerId // ignore: cast_nullable_to_non_nullable as int?,customerId: freezed == customerId ? _self.customerId : customerId // ignore: cast_nullable_to_non_nullable
as String?,feedbackType: freezed == feedbackType ? _self.feedbackType : feedbackType // ignore: cast_nullable_to_non_nullable as String?,feedbackType: freezed == feedbackType ? _self.feedbackType : feedbackType // ignore: cast_nullable_to_non_nullable
as String?,id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String?,id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String?,tenderId: freezed == tenderId ? _self.tenderId : tenderId // ignore: cast_nullable_to_non_nullable
as String?,tender: freezed == tender ? _self.tender : tender // ignore: cast_nullable_to_non_nullable as String?,tender: freezed == tender ? _self.tender : tender // ignore: cast_nullable_to_non_nullable
as String?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as TenderData?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as int?, as int?,
)); ));
} }
/// Create a copy of FeedbackData
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$TenderDataCopyWith<$Res>? get tender {
if (_self.tender == null) {
return null;
}
return $TenderDataCopyWith<$Res>(_self.tender!, (value) {
return _then(_self.copyWith(tender: value));
});
}
} }
// dart format on // dart format on
@@ -13,7 +13,11 @@ _FeedbackData _$FeedbackDataFromJson(Map<String, dynamic> json) =>
customerId: json['customer_id'] as String?, customerId: json['customer_id'] as String?,
feedbackType: json['feedback_type'] as String?, feedbackType: json['feedback_type'] as String?,
id: json['id'] as String?, id: json['id'] as String?,
tender: json['tender'] as String?, tenderId: json['tender_id'] as String?,
tender:
json['tender'] == null
? null
: TenderData.fromJson(json['tender'] as Map<String, dynamic>),
updatedAt: (json['updated_at'] as num?)?.toInt(), updatedAt: (json['updated_at'] as num?)?.toInt(),
); );
@@ -24,6 +28,7 @@ Map<String, dynamic> _$FeedbackDataToJson(_FeedbackData instance) =>
'customer_id': instance.customerId, 'customer_id': instance.customerId,
'feedback_type': instance.feedbackType, 'feedback_type': instance.feedbackType,
'id': instance.id, 'id': instance.id,
'tender_id': instance.tenderId,
'tender': instance.tender, 'tender': instance.tender,
'updated_at': instance.updatedAt, 'updated_at': instance.updatedAt,
}; };
+17 -13
View File
@@ -1,8 +1,7 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:tm_app/core/utils/device_utils.dart'; import 'package:tm_app/core/utils/device_utils.dart';
import 'package:tm_app/core/utils/logger.dart';
import 'package:tm_app/data/repositories/tenders_repository.dart'; import 'package:tm_app/data/repositories/tenders_repository.dart';
import 'package:tm_app/data/services/model/feedback_data/feedback_data.dart'; import 'package:tm_app/data/services/model/feedback_data/feedback_data.dart';
import 'package:tm_app/data/services/model/feedback_response/feedback_response.dart'; import 'package:tm_app/data/services/model/feedback_response/feedback_response.dart';
@@ -134,7 +133,7 @@ class TendersViewModel with ChangeNotifier {
/// Get feedback for a specific tender /// Get feedback for a specific tender
FeedbackData? getFeedbackForTender(String tenderId) { FeedbackData? getFeedbackForTender(String tenderId) {
try { try {
return feedbacks.firstWhere((f) => f.tender == tenderId); return feedbacks.firstWhere((f) => f.tenderId == tenderId);
} catch (e) { } catch (e) {
return null; return null;
} }
@@ -142,7 +141,7 @@ class TendersViewModel with ChangeNotifier {
/// Check if feedback exists for a specific tender /// Check if feedback exists for a specific tender
bool hasFeedbackForTender(String tenderId) { bool hasFeedbackForTender(String tenderId) {
return feedbacks.any((f) => f.tender == tenderId); return feedbacks.any((f) => f.tenderId == tenderId);
} }
Future<void> getTenders({ Future<void> getTenders({
@@ -319,16 +318,20 @@ class TendersViewModel with ChangeNotifier {
// Add or update _feedbackData in feedbacks list by tender id // Add or update _feedbackData in feedbacks list by tender id
if (_feedbackData != null) { if (_feedbackData != null) {
final index = feedbacks.indexWhere( final index = feedbacks.indexWhere(
(f) => f.tender == _feedbackData!.tender, (f) => f.tenderId == _feedbackData!.tenderId,
); );
if (index != -1) { if (index != -1) {
feedbacks[index] = _feedbackData!; feedbacks[index] = _feedbackData!;
log('Updated feedback for tender: ${_feedbackData!.tender}'); AppLogger().info(
'Updated feedback for tender: ${_feedbackData!.tenderId}',
);
} else { } else {
feedbacks.add(_feedbackData!); feedbacks.add(_feedbackData!);
log('Added new feedback for tender: ${_feedbackData!.tender}'); AppLogger().info(
'Added new feedback for tender: ${_feedbackData!.tenderId}',
);
} }
log('Total feedbacks: ${feedbacks.length}'); AppLogger().info('Total feedbacks: ${feedbacks.length}');
} }
break; break;
case Error<FeedbackResponse>(): case Error<FeedbackResponse>():
@@ -350,7 +353,7 @@ class TendersViewModel with ChangeNotifier {
// Get current feedback for this tender // Get current feedback for this tender
final existingFeedback = getFeedbackForTender(tenderId); final existingFeedback = getFeedbackForTender(tenderId);
final existingFeedbackIndex = feedbacks.indexWhere( final existingFeedbackIndex = feedbacks.indexWhere(
(f) => f.tender == tenderId, (f) => f.tenderId == tenderId,
); );
// Create optimistic feedback data // Create optimistic feedback data
@@ -364,7 +367,8 @@ class TendersViewModel with ChangeNotifier {
customerId: null, // Will be filled by server customerId: null, // Will be filled by server
feedbackType: feedbackType, feedbackType: feedbackType,
id: null, // Will be filled by server id: null, // Will be filled by server
tender: tenderId, tenderId: tenderId,
tender: null,
updatedAt: DateTime.now().millisecondsSinceEpoch, updatedAt: DateTime.now().millisecondsSinceEpoch,
); );
feedbacks.add(optimisticFeedback); feedbacks.add(optimisticFeedback);
@@ -412,18 +416,18 @@ class TendersViewModel with ChangeNotifier {
} }
} else { } else {
// Server returned null data - remove feedback // Server returned null data - remove feedback
feedbacks.removeWhere((f) => f.tender == tenderId); feedbacks.removeWhere((f) => f.tenderId == tenderId);
} }
break; break;
case Error<FeedbackResponse>(): case Error<FeedbackResponse>():
// Revert optimistic update on error // Revert optimistic update on error
if (existingFeedback == null) { if (existingFeedback == null) {
// Remove the optimistic feedback we added // Remove the optimistic feedback we added
feedbacks.removeWhere((f) => f.tender == tenderId); feedbacks.removeWhere((f) => f.tenderId == tenderId);
} else { } else {
// Restore the original feedback - find current index and update, or add if not found // Restore the original feedback - find current index and update, or add if not found
final currentIndex = feedbacks.indexWhere( final currentIndex = feedbacks.indexWhere(
(f) => f.tender == tenderId, (f) => f.tenderId == tenderId,
); );
if (currentIndex != -1) { if (currentIndex != -1) {
feedbacks[currentIndex] = existingFeedback; feedbacks[currentIndex] = existingFeedback;