update review api.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/// Data Model: Review Statistics
|
||||
///
|
||||
/// JSON serializable model for review statistics from API.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/reviews/domain/entities/review_statistics.dart';
|
||||
|
||||
/// Review statistics data model
|
||||
///
|
||||
/// Handles JSON serialization/deserialization for review statistics.
|
||||
///
|
||||
/// API Response format:
|
||||
/// ```json
|
||||
/// {
|
||||
/// "total_feedback": 2,
|
||||
/// "average_rating": 2.25
|
||||
/// }
|
||||
/// ```
|
||||
class ReviewStatisticsModel {
|
||||
const ReviewStatisticsModel({
|
||||
required this.totalFeedback,
|
||||
required this.averageRating,
|
||||
});
|
||||
|
||||
/// Total number of reviews/feedbacks
|
||||
final int totalFeedback;
|
||||
|
||||
/// Average rating (0-5 scale from API)
|
||||
final double averageRating;
|
||||
|
||||
/// Create model from JSON
|
||||
factory ReviewStatisticsModel.fromJson(Map<String, dynamic> json) {
|
||||
return ReviewStatisticsModel(
|
||||
totalFeedback: json['total_feedback'] as int? ?? 0,
|
||||
averageRating: (json['average_rating'] as num?)?.toDouble() ?? 0.0,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert model to JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'total_feedback': totalFeedback,
|
||||
'average_rating': averageRating,
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert to domain entity
|
||||
ReviewStatistics toEntity() {
|
||||
return ReviewStatistics(
|
||||
totalFeedback: totalFeedback,
|
||||
averageRating: averageRating,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create model from domain entity
|
||||
factory ReviewStatisticsModel.fromEntity(ReviewStatistics entity) {
|
||||
return ReviewStatisticsModel(
|
||||
totalFeedback: entity.totalFeedback,
|
||||
averageRating: entity.averageRating,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is ReviewStatisticsModel &&
|
||||
other.totalFeedback == totalFeedback &&
|
||||
other.averageRating == averageRating;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(totalFeedback, averageRating);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ReviewStatisticsModel(totalFeedback: $totalFeedback, averageRating: $averageRating)';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user