diff --git a/packages/app_center/lib/ratings/ratings_data.freezed.dart b/packages/app_center/lib/ratings/ratings_data.freezed.dart index 4bf2b91ae..b917d81a5 100644 --- a/packages/app_center/lib/ratings/ratings_data.freezed.dart +++ b/packages/app_center/lib/ratings/ratings_data.freezed.dart @@ -37,6 +37,8 @@ abstract class $RatingsDataCopyWith<$Res> { int snapRevision, Rating? rating, VoteStatus? voteStatus}); + + $RatingCopyWith<$Res>? get rating; } /// @nodoc @@ -76,6 +78,18 @@ class _$RatingsDataCopyWithImpl<$Res, $Val extends RatingsData> as VoteStatus?, ) as $Val); } + + @override + @pragma('vm:prefer-inline') + $RatingCopyWith<$Res>? get rating { + if (_value.rating == null) { + return null; + } + + return $RatingCopyWith<$Res>(_value.rating!, (value) { + return _then(_value.copyWith(rating: value) as $Val); + }); + } } /// @nodoc @@ -91,6 +105,9 @@ abstract class _$$RatingsDataImplCopyWith<$Res> int snapRevision, Rating? rating, VoteStatus? voteStatus}); + + @override + $RatingCopyWith<$Res>? get rating; } /// @nodoc diff --git a/packages/app_center_ratings_client/lib/src/chart.dart b/packages/app_center_ratings_client/lib/src/chart.dart index f433339cc..56cfe05d4 100644 --- a/packages/app_center_ratings_client/lib/src/chart.dart +++ b/packages/app_center_ratings_client/lib/src/chart.dart @@ -1,6 +1,6 @@ import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pb.dart' as pb; -import 'package:app_center_ratings_client/src/ratings.dart' as common; +import 'package:app_center_ratings_client/src/ratings.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'chart.freezed.dart'; @@ -9,14 +9,22 @@ part 'chart.freezed.dart'; class ChartData with _$ChartData { const factory ChartData({ required double rawRating, - required common.Rating rating, + required Rating rating, }) = _ChartData; } enum Timeframe { unspecified, week, - month, + month; + + pb.Timeframe toDTO() { + return switch (this) { + Timeframe.unspecified => pb.Timeframe.TIMEFRAME_UNSPECIFIED, + Timeframe.week => pb.Timeframe.TIMEFRAME_WEEK, + Timeframe.month => pb.Timeframe.TIMEFRAME_MONTH, + }; + } } extension ChartDataFromDTO on pb.ChartData { @@ -38,13 +46,3 @@ extension TimeframeFromDTO on pb.Timeframe { }; } } - -extension TimeframeToDTO on Timeframe { - pb.Timeframe toDTO() { - return switch (this) { - Timeframe.unspecified => pb.Timeframe.TIMEFRAME_UNSPECIFIED, - Timeframe.week => pb.Timeframe.TIMEFRAME_WEEK, - Timeframe.month => pb.Timeframe.TIMEFRAME_MONTH, - }; - } -} diff --git a/packages/app_center_ratings_client/lib/src/chart.freezed.dart b/packages/app_center_ratings_client/lib/src/chart.freezed.dart index 7ceeba0f3..855afcd59 100644 --- a/packages/app_center_ratings_client/lib/src/chart.freezed.dart +++ b/packages/app_center_ratings_client/lib/src/chart.freezed.dart @@ -17,7 +17,7 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$ChartData { double get rawRating => throw _privateConstructorUsedError; - common.Rating get rating => throw _privateConstructorUsedError; + Rating get rating => throw _privateConstructorUsedError; @JsonKey(ignore: true) $ChartDataCopyWith get copyWith => @@ -29,7 +29,9 @@ abstract class $ChartDataCopyWith<$Res> { factory $ChartDataCopyWith(ChartData value, $Res Function(ChartData) then) = _$ChartDataCopyWithImpl<$Res, ChartData>; @useResult - $Res call({double rawRating, common.Rating rating}); + $Res call({double rawRating, Rating rating}); + + $RatingCopyWith<$Res> get rating; } /// @nodoc @@ -56,9 +58,17 @@ class _$ChartDataCopyWithImpl<$Res, $Val extends ChartData> rating: null == rating ? _value.rating : rating // ignore: cast_nullable_to_non_nullable - as common.Rating, + as Rating, ) as $Val); } + + @override + @pragma('vm:prefer-inline') + $RatingCopyWith<$Res> get rating { + return $RatingCopyWith<$Res>(_value.rating, (value) { + return _then(_value.copyWith(rating: value) as $Val); + }); + } } /// @nodoc @@ -69,7 +79,10 @@ abstract class _$$ChartDataImplCopyWith<$Res> __$$ChartDataImplCopyWithImpl<$Res>; @override @useResult - $Res call({double rawRating, common.Rating rating}); + $Res call({double rawRating, Rating rating}); + + @override + $RatingCopyWith<$Res> get rating; } /// @nodoc @@ -94,7 +107,7 @@ class __$$ChartDataImplCopyWithImpl<$Res> rating: null == rating ? _value.rating : rating // ignore: cast_nullable_to_non_nullable - as common.Rating, + as Rating, )); } } @@ -107,7 +120,7 @@ class _$ChartDataImpl implements _ChartData { @override final double rawRating; @override - final common.Rating rating; + final Rating rating; @override String toString() { @@ -137,12 +150,12 @@ class _$ChartDataImpl implements _ChartData { abstract class _ChartData implements ChartData { const factory _ChartData( {required final double rawRating, - required final common.Rating rating}) = _$ChartDataImpl; + required final Rating rating}) = _$ChartDataImpl; @override double get rawRating; @override - common.Rating get rating; + Rating get rating; @override @JsonKey(ignore: true) _$$ChartDataImplCopyWith<_$ChartDataImpl> get copyWith => diff --git a/packages/app_center_ratings_client/lib/src/ratings.dart b/packages/app_center_ratings_client/lib/src/ratings.dart index c4dd35b13..745287c4b 100644 --- a/packages/app_center_ratings_client/lib/src/ratings.dart +++ b/packages/app_center_ratings_client/lib/src/ratings.dart @@ -1,31 +1,19 @@ +// ignore_for_file: invalid_annotation_target + import 'package:app_center_ratings_client/src/generated/ratings_features_common.pb.dart' as pb; import 'package:freezed_annotation/freezed_annotation.dart'; -@immutable -class Rating { - const Rating({ - required this.snapId, - required this.totalVotes, - required this.ratingsBand, - }); - final String snapId; - final int totalVotes; - final RatingsBand ratingsBand; - - @override - bool operator ==(Object other) { - if (identical(this, other)) return true; - - return other is Rating && - other.snapId == snapId && - other.totalVotes == totalVotes && - other.ratingsBand == ratingsBand; - } +part 'ratings.freezed.dart'; - @override - int get hashCode => - snapId.hashCode ^ totalVotes.hashCode ^ ratingsBand.hashCode; +@freezed +class Rating with _$Rating { + @JsonSerializable(explicitToJson: true) + const factory Rating({ + required String snapId, + required int totalVotes, + required RatingsBand ratingsBand, + }) = _Rating; } enum RatingsBand { diff --git a/packages/app_center_ratings_client/lib/src/ratings.freezed.dart b/packages/app_center_ratings_client/lib/src/ratings.freezed.dart new file mode 100644 index 000000000..7a6783c22 --- /dev/null +++ b/packages/app_center_ratings_client/lib/src/ratings.freezed.dart @@ -0,0 +1,170 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// 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 'ratings.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +mixin _$Rating { + String get snapId => throw _privateConstructorUsedError; + int get totalVotes => throw _privateConstructorUsedError; + RatingsBand get ratingsBand => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $RatingCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RatingCopyWith<$Res> { + factory $RatingCopyWith(Rating value, $Res Function(Rating) then) = + _$RatingCopyWithImpl<$Res, Rating>; + @useResult + $Res call({String snapId, int totalVotes, RatingsBand ratingsBand}); +} + +/// @nodoc +class _$RatingCopyWithImpl<$Res, $Val extends Rating> + implements $RatingCopyWith<$Res> { + _$RatingCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? snapId = null, + Object? totalVotes = null, + Object? ratingsBand = null, + }) { + return _then(_value.copyWith( + snapId: null == snapId + ? _value.snapId + : snapId // ignore: cast_nullable_to_non_nullable + as String, + totalVotes: null == totalVotes + ? _value.totalVotes + : totalVotes // ignore: cast_nullable_to_non_nullable + as int, + ratingsBand: null == ratingsBand + ? _value.ratingsBand + : ratingsBand // ignore: cast_nullable_to_non_nullable + as RatingsBand, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$RatingImplCopyWith<$Res> implements $RatingCopyWith<$Res> { + factory _$$RatingImplCopyWith( + _$RatingImpl value, $Res Function(_$RatingImpl) then) = + __$$RatingImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String snapId, int totalVotes, RatingsBand ratingsBand}); +} + +/// @nodoc +class __$$RatingImplCopyWithImpl<$Res> + extends _$RatingCopyWithImpl<$Res, _$RatingImpl> + implements _$$RatingImplCopyWith<$Res> { + __$$RatingImplCopyWithImpl( + _$RatingImpl _value, $Res Function(_$RatingImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? snapId = null, + Object? totalVotes = null, + Object? ratingsBand = null, + }) { + return _then(_$RatingImpl( + snapId: null == snapId + ? _value.snapId + : snapId // ignore: cast_nullable_to_non_nullable + as String, + totalVotes: null == totalVotes + ? _value.totalVotes + : totalVotes // ignore: cast_nullable_to_non_nullable + as int, + ratingsBand: null == ratingsBand + ? _value.ratingsBand + : ratingsBand // ignore: cast_nullable_to_non_nullable + as RatingsBand, + )); + } +} + +/// @nodoc + +@JsonSerializable(explicitToJson: true) +class _$RatingImpl implements _Rating { + const _$RatingImpl( + {required this.snapId, + required this.totalVotes, + required this.ratingsBand}); + + @override + final String snapId; + @override + final int totalVotes; + @override + final RatingsBand ratingsBand; + + @override + String toString() { + return 'Rating(snapId: $snapId, totalVotes: $totalVotes, ratingsBand: $ratingsBand)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$RatingImpl && + (identical(other.snapId, snapId) || other.snapId == snapId) && + (identical(other.totalVotes, totalVotes) || + other.totalVotes == totalVotes) && + (identical(other.ratingsBand, ratingsBand) || + other.ratingsBand == ratingsBand)); + } + + @override + int get hashCode => Object.hash(runtimeType, snapId, totalVotes, ratingsBand); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$RatingImplCopyWith<_$RatingImpl> get copyWith => + __$$RatingImplCopyWithImpl<_$RatingImpl>(this, _$identity); +} + +abstract class _Rating implements Rating { + const factory _Rating( + {required final String snapId, + required final int totalVotes, + required final RatingsBand ratingsBand}) = _$RatingImpl; + + @override + String get snapId; + @override + int get totalVotes; + @override + RatingsBand get ratingsBand; + @override + @JsonKey(ignore: true) + _$$RatingImplCopyWith<_$RatingImpl> get copyWith => + throw _privateConstructorUsedError; +}