Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used @freezed to create Rating class #1669

Merged
merged 12 commits into from
Jun 26, 2024
17 changes: 17 additions & 0 deletions packages/app_center/lib/ratings/ratings_data.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ abstract class $RatingsDataCopyWith<$Res> {
int snapRevision,
Rating? rating,
VoteStatus? voteStatus});

$RatingCopyWith<$Res>? get rating;
}

/// @nodoc
Expand Down Expand Up @@ -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
Expand All @@ -91,6 +105,9 @@ abstract class _$$RatingsDataImplCopyWith<$Res>
int snapRevision,
Rating? rating,
VoteStatus? voteStatus});

@override
$RatingCopyWith<$Res>? get rating;
}

/// @nodoc
Expand Down
24 changes: 11 additions & 13 deletions packages/app_center_ratings_client/lib/src/chart.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand All @@ -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,
};
}
}
29 changes: 21 additions & 8 deletions packages/app_center_ratings_client/lib/src/chart.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChartData> get copyWith =>
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an issue with nested freezed classes here - this is only part of ratings.dart but not chart.dart. Chart is another freezed class, that has a Rating field.

I don't know from the top of my head how to fix this, though.

}

/// @nodoc
Expand All @@ -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
Expand All @@ -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
Expand All @@ -94,7 +107,7 @@ class __$$ChartDataImplCopyWithImpl<$Res>
rating: null == rating
? _value.rating
: rating // ignore: cast_nullable_to_non_nullable
as common.Rating,
as Rating,
));
}
}
Expand All @@ -107,7 +120,7 @@ class _$ChartDataImpl implements _ChartData {
@override
final double rawRating;
@override
final common.Rating rating;
final Rating rating;

@override
String toString() {
Expand Down Expand Up @@ -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 =>
Expand Down
34 changes: 11 additions & 23 deletions packages/app_center_ratings_client/lib/src/ratings.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
170 changes: 170 additions & 0 deletions packages/app_center_ratings_client/lib/src/ratings.freezed.dart
Original file line number Diff line number Diff line change
@@ -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>(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<Rating> 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;
}
Loading