diff --git a/lib/app_center_ratings_client.dart b/lib/app_center_ratings_client.dart index 4db30fd..6026a79 100644 --- a/lib/app_center_ratings_client.dart +++ b/lib/app_center_ratings_client.dart @@ -3,15 +3,18 @@ import 'dart:async'; import 'package:grpc/grpc.dart'; import 'package:meta/meta.dart'; -import 'src/app.dart' as app; +import 'src/chart.dart'; import 'src/generated/google/protobuf/empty.pb.dart'; -import 'src/generated/ratings_features_app.pbgrpc.dart'; -import 'src/generated/ratings_features_user.pbgrpc.dart'; -import 'src/user.dart' as user; +import 'src/generated/ratings_features_app.pbgrpc.dart' as appPb; +import 'src/generated/ratings_features_chart.pbgrpc.dart' as chartPb; +import 'src/generated/ratings_features_user.pbgrpc.dart' as userPb; +import 'src/ratings.dart'; +import 'src/user.dart'; class RatingsClient { - late AppClient _appClient; - late UserClient _userClient; + late appPb.AppClient _appClient; + late userPb.UserClient _userClient; + late chartPb.ChartClient _chartClient; RatingsClient(String serverUrl, int port) { final channel = ClientChannel( @@ -21,8 +24,9 @@ class RatingsClient { credentials: ChannelCredentials.insecure(), ), ); - _appClient = AppClient(channel); - _userClient = UserClient(channel); + _appClient = appPb.AppClient(channel); + _userClient = userPb.UserClient(channel); + _chartClient = chartPb.ChartClient(channel); } // Additional constructor for testing @@ -30,13 +34,36 @@ class RatingsClient { RatingsClient.withClients( this._appClient, this._userClient, + this._chartClient, ); - Future getRating( + Future authenticate(String id) async { + final request = userPb.AuthenticateRequest(id: id); + final grpcResponse = await _userClient.authenticate(request); + return grpcResponse.token; + } + + Future delete(String token) async { + final request = Empty(); + final callOptions = + CallOptions(metadata: {'authorization': 'Bearer $token'}); + await _userClient.delete(request, options: callOptions); + } + + Future> getChart(Timeframe timeframe, String token) async { + final request = chartPb.GetChartRequest(timeframe: timeframe.toDTO()); + final callOptions = + CallOptions(metadata: {'authorization': 'Bearer $token'}); + final grpcResponse = + await _chartClient.getChart(request, options: callOptions); + return grpcResponse.orderedChartData.map((data) => data.fromDTO()).toList(); + } + + Future getRating( String snapId, String token, ) async { - final request = GetRatingRequest(snapId: snapId); + final request = appPb.GetRatingRequest(snapId: snapId); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _appClient.getRating( @@ -46,14 +73,19 @@ class RatingsClient { return grpcResponse.rating.fromDTO(); } - Future authenticate(String id) async { - final request = AuthenticateRequest(id: id); - final grpcResponse = await _userClient.authenticate(request); - return grpcResponse.token; + Future> getSnapVotes(String snap_id, String token) async { + final request = userPb.GetSnapVotesRequest(snapId: snap_id); + final callOptions = + CallOptions(metadata: {'authorization': 'Bearer $token'}); + final grpcResponse = await _userClient.getSnapVotes( + request, + options: callOptions, + ); + return grpcResponse.votes.map((vote) => vote.fromDTO()).toList(); } - Future> listMyVotes(String snapIdFilter, String token) async { - final request = ListMyVotesRequest(snapIdFilter: snapIdFilter); + Future> listMyVotes(String snapIdFilter, String token) async { + final request = userPb.ListMyVotesRequest(snapIdFilter: snapIdFilter); final callOptions = CallOptions(metadata: {'authorization': 'Bearer $token'}); final grpcResponse = await _userClient.listMyVotes( @@ -65,7 +97,7 @@ class RatingsClient { Future vote( String snapId, int snapRevision, bool voteUp, String token) async { - final request = VoteRequest( + final request = userPb.VoteRequest( snapId: snapId, snapRevision: snapRevision, voteUp: voteUp, @@ -74,22 +106,4 @@ class RatingsClient { CallOptions(metadata: {'authorization': 'Bearer $token'}); await _userClient.vote(request, options: callOptions); } - - Future delete(String token) async { - final request = Empty(); - final callOptions = - CallOptions(metadata: {'authorization': 'Bearer $token'}); - await _userClient.delete(request, options: callOptions); - } - - Future> getSnapVotes(String snap_id, String token) async { - final request = GetSnapVotesRequest(snapId: snap_id); - final callOptions = - CallOptions(metadata: {'authorization': 'Bearer $token'}); - final grpcResponse = await _userClient.getSnapVotes( - request, - options: callOptions, - ); - return grpcResponse.votes.map((vote) => vote.fromDTO()).toList(); - } } diff --git a/lib/src/app.freezed.dart b/lib/src/app.freezed.dart deleted file mode 100644 index 831d407..0000000 --- a/lib/src/app.freezed.dart +++ /dev/null @@ -1,167 +0,0 @@ -// 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 'app.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#custom-getters-and-methods'); - -/// @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 _$$_RatingCopyWith<$Res> implements $RatingCopyWith<$Res> { - factory _$$_RatingCopyWith(_$_Rating value, $Res Function(_$_Rating) then) = - __$$_RatingCopyWithImpl<$Res>; - @override - @useResult - $Res call({String snapId, int totalVotes, RatingsBand ratingsBand}); -} - -/// @nodoc -class __$$_RatingCopyWithImpl<$Res> - extends _$RatingCopyWithImpl<$Res, _$_Rating> - implements _$$_RatingCopyWith<$Res> { - __$$_RatingCopyWithImpl(_$_Rating _value, $Res Function(_$_Rating) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? snapId = null, - Object? totalVotes = null, - Object? ratingsBand = null, - }) { - return _then(_$_Rating( - 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 - -class _$_Rating implements _Rating { - const _$_Rating( - {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 ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_Rating && - (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') - _$$_RatingCopyWith<_$_Rating> get copyWith => - __$$_RatingCopyWithImpl<_$_Rating>(this, _$identity); -} - -abstract class _Rating implements Rating { - const factory _Rating( - {required final String snapId, - required final int totalVotes, - required final RatingsBand ratingsBand}) = _$_Rating; - - @override - String get snapId; - @override - int get totalVotes; - @override - RatingsBand get ratingsBand; - @override - @JsonKey(ignore: true) - _$$_RatingCopyWith<_$_Rating> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/src/chart.dart b/lib/src/chart.dart new file mode 100644 index 0000000..41c6ffd --- /dev/null +++ b/lib/src/chart.dart @@ -0,0 +1,50 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +import 'generated/ratings_features_chart.pb.dart' as pb; +import 'ratings.dart' as common; + +part 'chart.freezed.dart'; + +@freezed +class ChartData with _$ChartData { + const factory ChartData({ + required double rawRating, + required common.Rating rating, + }) = _ChartData; +} + +enum Timeframe { + unspecified, + week, + month, +} + +extension ChartDataFromDTO on pb.ChartData { + ChartData fromDTO() { + return ChartData( + rating: this.rating.fromDTO(), + rawRating: this.rawRating, + ); + } +} + +extension TimeframeFromDTO on pb.Timeframe { + Timeframe fromDTO() { + return switch (this) { + pb.Timeframe.TIMEFRAME_UNSPECIFIED => Timeframe.unspecified, + pb.Timeframe.TIMEFRAME_WEEK => Timeframe.week, + pb.Timeframe.TIMEFRAME_MONTH => Timeframe.month, + _ => Timeframe.unspecified, + }; + } +} + +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/lib/src/chart.freezed.dart b/lib/src/chart.freezed.dart new file mode 100644 index 0000000..29a230a --- /dev/null +++ b/lib/src/chart.freezed.dart @@ -0,0 +1,150 @@ +// 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 'chart.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#custom-getters-and-methods'); + +/// @nodoc +mixin _$ChartData { + double get rawRating => throw _privateConstructorUsedError; + common.Rating get rating => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $ChartDataCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ChartDataCopyWith<$Res> { + factory $ChartDataCopyWith(ChartData value, $Res Function(ChartData) then) = + _$ChartDataCopyWithImpl<$Res, ChartData>; + @useResult + $Res call({double rawRating, common.Rating rating}); +} + +/// @nodoc +class _$ChartDataCopyWithImpl<$Res, $Val extends ChartData> + implements $ChartDataCopyWith<$Res> { + _$ChartDataCopyWithImpl(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? rawRating = null, + Object? rating = null, + }) { + return _then(_value.copyWith( + rawRating: null == rawRating + ? _value.rawRating + : rawRating // ignore: cast_nullable_to_non_nullable + as double, + rating: null == rating + ? _value.rating + : rating // ignore: cast_nullable_to_non_nullable + as common.Rating, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ChartDataImplCopyWith<$Res> + implements $ChartDataCopyWith<$Res> { + factory _$$ChartDataImplCopyWith( + _$ChartDataImpl value, $Res Function(_$ChartDataImpl) then) = + __$$ChartDataImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double rawRating, common.Rating rating}); +} + +/// @nodoc +class __$$ChartDataImplCopyWithImpl<$Res> + extends _$ChartDataCopyWithImpl<$Res, _$ChartDataImpl> + implements _$$ChartDataImplCopyWith<$Res> { + __$$ChartDataImplCopyWithImpl( + _$ChartDataImpl _value, $Res Function(_$ChartDataImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? rawRating = null, + Object? rating = null, + }) { + return _then(_$ChartDataImpl( + rawRating: null == rawRating + ? _value.rawRating + : rawRating // ignore: cast_nullable_to_non_nullable + as double, + rating: null == rating + ? _value.rating + : rating // ignore: cast_nullable_to_non_nullable + as common.Rating, + )); + } +} + +/// @nodoc + +class _$ChartDataImpl implements _ChartData { + const _$ChartDataImpl({required this.rawRating, required this.rating}); + + @override + final double rawRating; + @override + final common.Rating rating; + + @override + String toString() { + return 'ChartData(rawRating: $rawRating, rating: $rating)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ChartDataImpl && + (identical(other.rawRating, rawRating) || + other.rawRating == rawRating) && + (identical(other.rating, rating) || other.rating == rating)); + } + + @override + int get hashCode => Object.hash(runtimeType, rawRating, rating); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$ChartDataImplCopyWith<_$ChartDataImpl> get copyWith => + __$$ChartDataImplCopyWithImpl<_$ChartDataImpl>(this, _$identity); +} + +abstract class _ChartData implements ChartData { + const factory _ChartData( + {required final double rawRating, + required final common.Rating rating}) = _$ChartDataImpl; + + @override + double get rawRating; + @override + common.Rating get rating; + @override + @JsonKey(ignore: true) + _$$ChartDataImplCopyWith<_$ChartDataImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/generated/ratings_features_app.pb.dart b/lib/src/generated/ratings_features_app.pb.dart index 56193eb..6ea544c 100644 --- a/lib/src/generated/ratings_features_app.pb.dart +++ b/lib/src/generated/ratings_features_app.pb.dart @@ -11,12 +11,9 @@ import 'dart:core' as $core; -import 'package:fixnum/fixnum.dart' as $fixnum; import 'package:protobuf/protobuf.dart' as $pb; -import 'ratings_features_app.pbenum.dart'; - -export 'ratings_features_app.pbenum.dart'; +import 'ratings_features_common.pb.dart' as $1; class GetRatingRequest extends $pb.GeneratedMessage { factory GetRatingRequest({ @@ -82,7 +79,7 @@ class GetRatingRequest extends $pb.GeneratedMessage { class GetRatingResponse extends $pb.GeneratedMessage { factory GetRatingResponse({ - Rating? rating, + $1.Rating? rating, }) { final $result = create(); if (rating != null) { @@ -103,7 +100,8 @@ class GetRatingResponse extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'ratings.features.app'), createEmptyInstance: create) - ..aOM(1, _omitFieldNames ? '' : 'rating', subBuilder: Rating.create) + ..aOM<$1.Rating>(1, _omitFieldNames ? '' : 'rating', + subBuilder: $1.Rating.create) ..hasRequiredFields = false; @$core.Deprecated('Using this can add significant overhead to your binary. ' @@ -130,9 +128,9 @@ class GetRatingResponse extends $pb.GeneratedMessage { static GetRatingResponse? _defaultInstance; @$pb.TagNumber(1) - Rating get rating => $_getN(0); + $1.Rating get rating => $_getN(0); @$pb.TagNumber(1) - set rating(Rating v) { + set rating($1.Rating v) { setField(1, v); } @@ -141,107 +139,7 @@ class GetRatingResponse extends $pb.GeneratedMessage { @$pb.TagNumber(1) void clearRating() => clearField(1); @$pb.TagNumber(1) - Rating ensureRating() => $_ensure(0); -} - -class Rating extends $pb.GeneratedMessage { - factory Rating({ - $core.String? snapId, - $fixnum.Int64? totalVotes, - RatingsBand? ratingsBand, - }) { - final $result = create(); - if (snapId != null) { - $result.snapId = snapId; - } - if (totalVotes != null) { - $result.totalVotes = totalVotes; - } - if (ratingsBand != null) { - $result.ratingsBand = ratingsBand; - } - return $result; - } - Rating._() : super(); - factory Rating.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - factory Rating.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - _omitMessageNames ? '' : 'Rating', - package: const $pb.PackageName( - _omitMessageNames ? '' : 'ratings.features.app'), - createEmptyInstance: create) - ..aOS(1, _omitFieldNames ? '' : 'snapId') - ..a<$fixnum.Int64>( - 2, _omitFieldNames ? '' : 'totalVotes', $pb.PbFieldType.OU6, - defaultOrMaker: $fixnum.Int64.ZERO) - ..e( - 3, _omitFieldNames ? '' : 'ratingsBand', $pb.PbFieldType.OE, - defaultOrMaker: RatingsBand.VERY_GOOD, - valueOf: RatingsBand.valueOf, - enumValues: RatingsBand.values) - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - Rating clone() => Rating()..mergeFromMessage(this); - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - Rating copyWith(void Function(Rating) updates) => - super.copyWith((message) => updates(message as Rating)) as Rating; - - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static Rating create() => Rating._(); - Rating createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); - @$core.pragma('dart2js:noInline') - static Rating getDefault() => - _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static Rating? _defaultInstance; - - @$pb.TagNumber(1) - $core.String get snapId => $_getSZ(0); - @$pb.TagNumber(1) - set snapId($core.String v) { - $_setString(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasSnapId() => $_has(0); - @$pb.TagNumber(1) - void clearSnapId() => clearField(1); - - @$pb.TagNumber(2) - $fixnum.Int64 get totalVotes => $_getI64(1); - @$pb.TagNumber(2) - set totalVotes($fixnum.Int64 v) { - $_setInt64(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasTotalVotes() => $_has(1); - @$pb.TagNumber(2) - void clearTotalVotes() => clearField(2); - - @$pb.TagNumber(3) - RatingsBand get ratingsBand => $_getN(2); - @$pb.TagNumber(3) - set ratingsBand(RatingsBand v) { - setField(3, v); - } - - @$pb.TagNumber(3) - $core.bool hasRatingsBand() => $_has(2); - @$pb.TagNumber(3) - void clearRatingsBand() => clearField(3); + $1.Rating ensureRating() => $_ensure(0); } const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); diff --git a/lib/src/generated/ratings_features_app.pbenum.dart b/lib/src/generated/ratings_features_app.pbenum.dart index eeaebe1..bd80860 100644 --- a/lib/src/generated/ratings_features_app.pbenum.dart +++ b/lib/src/generated/ratings_features_app.pbenum.dart @@ -8,39 +8,3 @@ // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields // ignore_for_file: unnecessary_import, unnecessary_this, unused_import - -import 'dart:core' as $core; - -import 'package:protobuf/protobuf.dart' as $pb; - -class RatingsBand extends $pb.ProtobufEnum { - static const RatingsBand VERY_GOOD = - RatingsBand._(0, _omitEnumNames ? '' : 'VERY_GOOD'); - static const RatingsBand GOOD = - RatingsBand._(1, _omitEnumNames ? '' : 'GOOD'); - static const RatingsBand NEUTRAL = - RatingsBand._(2, _omitEnumNames ? '' : 'NEUTRAL'); - static const RatingsBand POOR = - RatingsBand._(3, _omitEnumNames ? '' : 'POOR'); - static const RatingsBand VERY_POOR = - RatingsBand._(4, _omitEnumNames ? '' : 'VERY_POOR'); - static const RatingsBand INSUFFICIENT_VOTES = - RatingsBand._(5, _omitEnumNames ? '' : 'INSUFFICIENT_VOTES'); - - static const $core.List values = [ - VERY_GOOD, - GOOD, - NEUTRAL, - POOR, - VERY_POOR, - INSUFFICIENT_VOTES, - ]; - - static final $core.Map<$core.int, RatingsBand> _byValue = - $pb.ProtobufEnum.initByValue(values); - static RatingsBand? valueOf($core.int value) => _byValue[value]; - - const RatingsBand._($core.int v, $core.String n) : super(v, n); -} - -const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names'); diff --git a/lib/src/generated/ratings_features_app.pbjson.dart b/lib/src/generated/ratings_features_app.pbjson.dart index 6323d1a..62661ec 100644 --- a/lib/src/generated/ratings_features_app.pbjson.dart +++ b/lib/src/generated/ratings_features_app.pbjson.dart @@ -13,24 +13,6 @@ import 'dart:convert' as $convert; import 'dart:core' as $core; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use ratingsBandDescriptor instead') -const RatingsBand$json = { - '1': 'RatingsBand', - '2': [ - {'1': 'VERY_GOOD', '2': 0}, - {'1': 'GOOD', '2': 1}, - {'1': 'NEUTRAL', '2': 2}, - {'1': 'POOR', '2': 3}, - {'1': 'VERY_POOR', '2': 4}, - {'1': 'INSUFFICIENT_VOTES', '2': 5}, - ], -}; - -/// Descriptor for `RatingsBand`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List ratingsBandDescriptor = $convert.base64Decode( - 'CgtSYXRpbmdzQmFuZBINCglWRVJZX0dPT0QQABIICgRHT09EEAESCwoHTkVVVFJBTBACEggKBF' - 'BPT1IQAxINCglWRVJZX1BPT1IQBBIWChJJTlNVRkZJQ0lFTlRfVk9URVMQBQ=='); - @$core.Deprecated('Use getRatingRequestDescriptor instead') const GetRatingRequest$json = { '1': 'GetRatingRequest', @@ -52,7 +34,7 @@ const GetRatingResponse$json = { '3': 1, '4': 1, '5': 11, - '6': '.ratings.features.app.Rating', + '6': '.ratings.features.common.Rating', '10': 'rating' }, ], @@ -60,28 +42,5 @@ const GetRatingResponse$json = { /// Descriptor for `GetRatingResponse`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List getRatingResponseDescriptor = $convert.base64Decode( - 'ChFHZXRSYXRpbmdSZXNwb25zZRI0CgZyYXRpbmcYASABKAsyHC5yYXRpbmdzLmZlYXR1cmVzLm' - 'FwcC5SYXRpbmdSBnJhdGluZw=='); - -@$core.Deprecated('Use ratingDescriptor instead') -const Rating$json = { - '1': 'Rating', - '2': [ - {'1': 'snap_id', '3': 1, '4': 1, '5': 9, '10': 'snapId'}, - {'1': 'total_votes', '3': 2, '4': 1, '5': 4, '10': 'totalVotes'}, - { - '1': 'ratings_band', - '3': 3, - '4': 1, - '5': 14, - '6': '.ratings.features.app.RatingsBand', - '10': 'ratingsBand' - }, - ], -}; - -/// Descriptor for `Rating`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List ratingDescriptor = $convert.base64Decode( - 'CgZSYXRpbmcSFwoHc25hcF9pZBgBIAEoCVIGc25hcElkEh8KC3RvdGFsX3ZvdGVzGAIgASgEUg' - 'p0b3RhbFZvdGVzEkQKDHJhdGluZ3NfYmFuZBgDIAEoDjIhLnJhdGluZ3MuZmVhdHVyZXMuYXBw' - 'LlJhdGluZ3NCYW5kUgtyYXRpbmdzQmFuZA=='); + 'ChFHZXRSYXRpbmdSZXNwb25zZRI3CgZyYXRpbmcYASABKAsyHy5yYXRpbmdzLmZlYXR1cmVzLm' + 'NvbW1vbi5SYXRpbmdSBnJhdGluZw=='); diff --git a/lib/src/generated/ratings_features_chart.pb.dart b/lib/src/generated/ratings_features_chart.pb.dart index 3331026..c17ae01 100644 --- a/lib/src/generated/ratings_features_chart.pb.dart +++ b/lib/src/generated/ratings_features_chart.pb.dart @@ -11,25 +11,21 @@ import 'dart:core' as $core; -import 'package:fixnum/fixnum.dart' as $fixnum; import 'package:protobuf/protobuf.dart' as $pb; import 'ratings_features_chart.pbenum.dart'; +import 'ratings_features_common.pb.dart' as $1; export 'ratings_features_chart.pbenum.dart'; class GetChartRequest extends $pb.GeneratedMessage { factory GetChartRequest({ Timeframe? timeframe, - ChartType? type, }) { final $result = create(); if (timeframe != null) { $result.timeframe = timeframe; } - if (type != null) { - $result.type = type; - } return $result; } GetChartRequest._() : super(); @@ -49,10 +45,6 @@ class GetChartRequest extends $pb.GeneratedMessage { defaultOrMaker: Timeframe.TIMEFRAME_UNSPECIFIED, valueOf: Timeframe.valueOf, enumValues: Timeframe.values) - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, - defaultOrMaker: ChartType.CHART_TYPE_TOP_UNSPECIFIED, - valueOf: ChartType.valueOf, - enumValues: ChartType.values) ..hasRequiredFields = false; @$core.Deprecated('Using this can add significant overhead to your binary. ' @@ -89,33 +81,17 @@ class GetChartRequest extends $pb.GeneratedMessage { $core.bool hasTimeframe() => $_has(0); @$pb.TagNumber(1) void clearTimeframe() => clearField(1); - - @$pb.TagNumber(2) - ChartType get type => $_getN(1); - @$pb.TagNumber(2) - set type(ChartType v) { - setField(2, v); - } - - @$pb.TagNumber(2) - $core.bool hasType() => $_has(1); - @$pb.TagNumber(2) - void clearType() => clearField(2); } class GetChartResponse extends $pb.GeneratedMessage { factory GetChartResponse({ Timeframe? timeframe, - ChartType? type, $core.Iterable? orderedChartData, }) { final $result = create(); if (timeframe != null) { $result.timeframe = timeframe; } - if (type != null) { - $result.type = type; - } if (orderedChartData != null) { $result.orderedChartData.addAll(orderedChartData); } @@ -138,12 +114,8 @@ class GetChartResponse extends $pb.GeneratedMessage { defaultOrMaker: Timeframe.TIMEFRAME_UNSPECIFIED, valueOf: Timeframe.valueOf, enumValues: Timeframe.values) - ..e(2, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE, - defaultOrMaker: ChartType.CHART_TYPE_TOP_UNSPECIFIED, - valueOf: ChartType.valueOf, - enumValues: ChartType.values) ..pc( - 3, _omitFieldNames ? '' : 'orderedChartData', $pb.PbFieldType.PM, + 2, _omitFieldNames ? '' : 'orderedChartData', $pb.PbFieldType.PM, subBuilder: ChartData.create) ..hasRequiredFields = false; @@ -183,36 +155,20 @@ class GetChartResponse extends $pb.GeneratedMessage { void clearTimeframe() => clearField(1); @$pb.TagNumber(2) - ChartType get type => $_getN(1); - @$pb.TagNumber(2) - set type(ChartType v) { - setField(2, v); - } - - @$pb.TagNumber(2) - $core.bool hasType() => $_has(1); - @$pb.TagNumber(2) - void clearType() => clearField(2); - - @$pb.TagNumber(3) - $core.List get orderedChartData => $_getList(2); + $core.List get orderedChartData => $_getList(1); } class ChartData extends $pb.GeneratedMessage { factory ChartData({ - $core.String? app, - $fixnum.Int64? totalUpVotes, - $fixnum.Int64? totalDownVotes, + $core.double? rawRating, + $1.Rating? rating, }) { final $result = create(); - if (app != null) { - $result.app = app; - } - if (totalUpVotes != null) { - $result.totalUpVotes = totalUpVotes; + if (rawRating != null) { + $result.rawRating = rawRating; } - if (totalDownVotes != null) { - $result.totalDownVotes = totalDownVotes; + if (rating != null) { + $result.rating = rating; } return $result; } @@ -229,13 +185,9 @@ class ChartData extends $pb.GeneratedMessage { package: const $pb.PackageName( _omitMessageNames ? '' : 'ratings.features.chart'), createEmptyInstance: create) - ..aOS(1, _omitFieldNames ? '' : 'app') - ..a<$fixnum.Int64>( - 2, _omitFieldNames ? '' : 'totalUpVotes', $pb.PbFieldType.OU6, - defaultOrMaker: $fixnum.Int64.ZERO) - ..a<$fixnum.Int64>( - 3, _omitFieldNames ? '' : 'totalDownVotes', $pb.PbFieldType.OU6, - defaultOrMaker: $fixnum.Int64.ZERO) + ..a<$core.double>(1, _omitFieldNames ? '' : 'rawRating', $pb.PbFieldType.OF) + ..aOM<$1.Rating>(2, _omitFieldNames ? '' : 'rating', + subBuilder: $1.Rating.create) ..hasRequiredFields = false; @$core.Deprecated('Using this can add significant overhead to your binary. ' @@ -260,40 +212,30 @@ class ChartData extends $pb.GeneratedMessage { static ChartData? _defaultInstance; @$pb.TagNumber(1) - $core.String get app => $_getSZ(0); + $core.double get rawRating => $_getN(0); @$pb.TagNumber(1) - set app($core.String v) { - $_setString(0, v); + set rawRating($core.double v) { + $_setFloat(0, v); } @$pb.TagNumber(1) - $core.bool hasApp() => $_has(0); + $core.bool hasRawRating() => $_has(0); @$pb.TagNumber(1) - void clearApp() => clearField(1); + void clearRawRating() => clearField(1); @$pb.TagNumber(2) - $fixnum.Int64 get totalUpVotes => $_getI64(1); + $1.Rating get rating => $_getN(1); @$pb.TagNumber(2) - set totalUpVotes($fixnum.Int64 v) { - $_setInt64(1, v); + set rating($1.Rating v) { + setField(2, v); } @$pb.TagNumber(2) - $core.bool hasTotalUpVotes() => $_has(1); + $core.bool hasRating() => $_has(1); @$pb.TagNumber(2) - void clearTotalUpVotes() => clearField(2); - - @$pb.TagNumber(3) - $fixnum.Int64 get totalDownVotes => $_getI64(2); - @$pb.TagNumber(3) - set totalDownVotes($fixnum.Int64 v) { - $_setInt64(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasTotalDownVotes() => $_has(2); - @$pb.TagNumber(3) - void clearTotalDownVotes() => clearField(3); + void clearRating() => clearField(2); + @$pb.TagNumber(2) + $1.Rating ensureRating() => $_ensure(1); } const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); diff --git a/lib/src/generated/ratings_features_chart.pbenum.dart b/lib/src/generated/ratings_features_chart.pbenum.dart index 6b940e9..f8d8dce 100644 --- a/lib/src/generated/ratings_features_chart.pbenum.dart +++ b/lib/src/generated/ratings_features_chart.pbenum.dart @@ -13,24 +13,6 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class ChartType extends $pb.ProtobufEnum { - static const ChartType CHART_TYPE_TOP_UNSPECIFIED = - ChartType._(0, _omitEnumNames ? '' : 'CHART_TYPE_TOP_UNSPECIFIED'); - static const ChartType CHART_TYPE_TOP = - ChartType._(1, _omitEnumNames ? '' : 'CHART_TYPE_TOP'); - - static const $core.List values = [ - CHART_TYPE_TOP_UNSPECIFIED, - CHART_TYPE_TOP, - ]; - - static final $core.Map<$core.int, ChartType> _byValue = - $pb.ProtobufEnum.initByValue(values); - static ChartType? valueOf($core.int value) => _byValue[value]; - - const ChartType._($core.int v, $core.String n) : super(v, n); -} - class Timeframe extends $pb.ProtobufEnum { static const Timeframe TIMEFRAME_UNSPECIFIED = Timeframe._(0, _omitEnumNames ? '' : 'TIMEFRAME_UNSPECIFIED'); diff --git a/lib/src/generated/ratings_features_chart.pbjson.dart b/lib/src/generated/ratings_features_chart.pbjson.dart index c8c3225..3ba8ff1 100644 --- a/lib/src/generated/ratings_features_chart.pbjson.dart +++ b/lib/src/generated/ratings_features_chart.pbjson.dart @@ -13,20 +13,6 @@ import 'dart:convert' as $convert; import 'dart:core' as $core; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use chartTypeDescriptor instead') -const ChartType$json = { - '1': 'ChartType', - '2': [ - {'1': 'CHART_TYPE_TOP_UNSPECIFIED', '2': 0}, - {'1': 'CHART_TYPE_TOP', '2': 1}, - ], -}; - -/// Descriptor for `ChartType`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List chartTypeDescriptor = $convert.base64Decode( - 'CglDaGFydFR5cGUSHgoaQ0hBUlRfVFlQRV9UT1BfVU5TUEVDSUZJRUQQABISCg5DSEFSVF9UWV' - 'BFX1RPUBAB'); - @$core.Deprecated('Use timeframeDescriptor instead') const Timeframe$json = { '1': 'Timeframe', @@ -54,22 +40,13 @@ const GetChartRequest$json = { '6': '.ratings.features.chart.Timeframe', '10': 'timeframe' }, - { - '1': 'type', - '3': 2, - '4': 1, - '5': 14, - '6': '.ratings.features.chart.ChartType', - '10': 'type' - }, ], }; /// Descriptor for `GetChartRequest`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List getChartRequestDescriptor = $convert.base64Decode( 'Cg9HZXRDaGFydFJlcXVlc3QSPwoJdGltZWZyYW1lGAEgASgOMiEucmF0aW5ncy5mZWF0dXJlcy' - '5jaGFydC5UaW1lZnJhbWVSCXRpbWVmcmFtZRI1CgR0eXBlGAIgASgOMiEucmF0aW5ncy5mZWF0' - 'dXJlcy5jaGFydC5DaGFydFR5cGVSBHR5cGU='); + '5jaGFydC5UaW1lZnJhbWVSCXRpbWVmcmFtZQ=='); @$core.Deprecated('Use getChartResponseDescriptor instead') const GetChartResponse$json = { @@ -83,17 +60,9 @@ const GetChartResponse$json = { '6': '.ratings.features.chart.Timeframe', '10': 'timeframe' }, - { - '1': 'type', - '3': 2, - '4': 1, - '5': 14, - '6': '.ratings.features.chart.ChartType', - '10': 'type' - }, { '1': 'ordered_chart_data', - '3': 3, + '3': 2, '4': 3, '5': 11, '6': '.ratings.features.chart.ChartData', @@ -105,21 +74,26 @@ const GetChartResponse$json = { /// Descriptor for `GetChartResponse`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List getChartResponseDescriptor = $convert.base64Decode( 'ChBHZXRDaGFydFJlc3BvbnNlEj8KCXRpbWVmcmFtZRgBIAEoDjIhLnJhdGluZ3MuZmVhdHVyZX' - 'MuY2hhcnQuVGltZWZyYW1lUgl0aW1lZnJhbWUSNQoEdHlwZRgCIAEoDjIhLnJhdGluZ3MuZmVh' - 'dHVyZXMuY2hhcnQuQ2hhcnRUeXBlUgR0eXBlEk8KEm9yZGVyZWRfY2hhcnRfZGF0YRgDIAMoCz' - 'IhLnJhdGluZ3MuZmVhdHVyZXMuY2hhcnQuQ2hhcnREYXRhUhBvcmRlcmVkQ2hhcnREYXRh'); + 'MuY2hhcnQuVGltZWZyYW1lUgl0aW1lZnJhbWUSTwoSb3JkZXJlZF9jaGFydF9kYXRhGAIgAygL' + 'MiEucmF0aW5ncy5mZWF0dXJlcy5jaGFydC5DaGFydERhdGFSEG9yZGVyZWRDaGFydERhdGE='); @$core.Deprecated('Use chartDataDescriptor instead') const ChartData$json = { '1': 'ChartData', '2': [ - {'1': 'app', '3': 1, '4': 1, '5': 9, '10': 'app'}, - {'1': 'total_up_votes', '3': 2, '4': 1, '5': 4, '10': 'totalUpVotes'}, - {'1': 'total_down_votes', '3': 3, '4': 1, '5': 4, '10': 'totalDownVotes'}, + {'1': 'raw_rating', '3': 1, '4': 1, '5': 2, '10': 'rawRating'}, + { + '1': 'rating', + '3': 2, + '4': 1, + '5': 11, + '6': '.ratings.features.common.Rating', + '10': 'rating' + }, ], }; /// Descriptor for `ChartData`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List chartDataDescriptor = $convert.base64Decode( - 'CglDaGFydERhdGESEAoDYXBwGAEgASgJUgNhcHASJAoOdG90YWxfdXBfdm90ZXMYAiABKARSDH' - 'RvdGFsVXBWb3RlcxIoChB0b3RhbF9kb3duX3ZvdGVzGAMgASgEUg50b3RhbERvd25Wb3Rlcw=='); + 'CglDaGFydERhdGESHQoKcmF3X3JhdGluZxgBIAEoAlIJcmF3UmF0aW5nEjcKBnJhdGluZxgCIA' + 'EoCzIfLnJhdGluZ3MuZmVhdHVyZXMuY29tbW9uLlJhdGluZ1IGcmF0aW5n'); diff --git a/lib/src/generated/ratings_features_common.pb.dart b/lib/src/generated/ratings_features_common.pb.dart new file mode 100644 index 0000000..a980ba0 --- /dev/null +++ b/lib/src/generated/ratings_features_common.pb.dart @@ -0,0 +1,123 @@ +// +// Generated code. Do not modify. +// source: ratings_features_common.proto +// +// @dart = 2.12 + +// ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: constant_identifier_names, library_prefixes +// ignore_for_file: non_constant_identifier_names, prefer_final_fields +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import + +import 'dart:core' as $core; + +import 'package:fixnum/fixnum.dart' as $fixnum; +import 'package:protobuf/protobuf.dart' as $pb; + +import 'ratings_features_common.pbenum.dart'; + +export 'ratings_features_common.pbenum.dart'; + +class Rating extends $pb.GeneratedMessage { + factory Rating({ + $core.String? snapId, + $fixnum.Int64? totalVotes, + RatingsBand? ratingsBand, + }) { + final $result = create(); + if (snapId != null) { + $result.snapId = snapId; + } + if (totalVotes != null) { + $result.totalVotes = totalVotes; + } + if (ratingsBand != null) { + $result.ratingsBand = ratingsBand; + } + return $result; + } + Rating._() : super(); + factory Rating.fromBuffer($core.List<$core.int> i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromBuffer(i, r); + factory Rating.fromJson($core.String i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromJson(i, r); + + static final $pb.BuilderInfo _i = $pb.BuilderInfo( + _omitMessageNames ? '' : 'Rating', + package: const $pb.PackageName( + _omitMessageNames ? '' : 'ratings.features.common'), + createEmptyInstance: create) + ..aOS(1, _omitFieldNames ? '' : 'snapId') + ..a<$fixnum.Int64>( + 2, _omitFieldNames ? '' : 'totalVotes', $pb.PbFieldType.OU6, + defaultOrMaker: $fixnum.Int64.ZERO) + ..e( + 3, _omitFieldNames ? '' : 'ratingsBand', $pb.PbFieldType.OE, + defaultOrMaker: RatingsBand.VERY_GOOD, + valueOf: RatingsBand.valueOf, + enumValues: RatingsBand.values) + ..hasRequiredFields = false; + + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + Rating clone() => Rating()..mergeFromMessage(this); + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + Rating copyWith(void Function(Rating) updates) => + super.copyWith((message) => updates(message as Rating)) as Rating; + + $pb.BuilderInfo get info_ => _i; + + @$core.pragma('dart2js:noInline') + static Rating create() => Rating._(); + Rating createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static Rating getDefault() => + _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static Rating? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get snapId => $_getSZ(0); + @$pb.TagNumber(1) + set snapId($core.String v) { + $_setString(0, v); + } + + @$pb.TagNumber(1) + $core.bool hasSnapId() => $_has(0); + @$pb.TagNumber(1) + void clearSnapId() => clearField(1); + + @$pb.TagNumber(2) + $fixnum.Int64 get totalVotes => $_getI64(1); + @$pb.TagNumber(2) + set totalVotes($fixnum.Int64 v) { + $_setInt64(1, v); + } + + @$pb.TagNumber(2) + $core.bool hasTotalVotes() => $_has(1); + @$pb.TagNumber(2) + void clearTotalVotes() => clearField(2); + + @$pb.TagNumber(3) + RatingsBand get ratingsBand => $_getN(2); + @$pb.TagNumber(3) + set ratingsBand(RatingsBand v) { + setField(3, v); + } + + @$pb.TagNumber(3) + $core.bool hasRatingsBand() => $_has(2); + @$pb.TagNumber(3) + void clearRatingsBand() => clearField(3); +} + +const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); +const _omitMessageNames = + $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/lib/src/generated/ratings_features_common.pbenum.dart b/lib/src/generated/ratings_features_common.pbenum.dart new file mode 100644 index 0000000..3b190bc --- /dev/null +++ b/lib/src/generated/ratings_features_common.pbenum.dart @@ -0,0 +1,46 @@ +// +// Generated code. Do not modify. +// source: ratings_features_common.proto +// +// @dart = 2.12 + +// ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: constant_identifier_names, library_prefixes +// ignore_for_file: non_constant_identifier_names, prefer_final_fields +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class RatingsBand extends $pb.ProtobufEnum { + static const RatingsBand VERY_GOOD = + RatingsBand._(0, _omitEnumNames ? '' : 'VERY_GOOD'); + static const RatingsBand GOOD = + RatingsBand._(1, _omitEnumNames ? '' : 'GOOD'); + static const RatingsBand NEUTRAL = + RatingsBand._(2, _omitEnumNames ? '' : 'NEUTRAL'); + static const RatingsBand POOR = + RatingsBand._(3, _omitEnumNames ? '' : 'POOR'); + static const RatingsBand VERY_POOR = + RatingsBand._(4, _omitEnumNames ? '' : 'VERY_POOR'); + static const RatingsBand INSUFFICIENT_VOTES = + RatingsBand._(5, _omitEnumNames ? '' : 'INSUFFICIENT_VOTES'); + + static const $core.List values = [ + VERY_GOOD, + GOOD, + NEUTRAL, + POOR, + VERY_POOR, + INSUFFICIENT_VOTES, + ]; + + static final $core.Map<$core.int, RatingsBand> _byValue = + $pb.ProtobufEnum.initByValue(values); + static RatingsBand? valueOf($core.int value) => _byValue[value]; + + const RatingsBand._($core.int v, $core.String n) : super(v, n); +} + +const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names'); diff --git a/lib/src/generated/ratings_features_common.pbjson.dart b/lib/src/generated/ratings_features_common.pbjson.dart new file mode 100644 index 0000000..2955126 --- /dev/null +++ b/lib/src/generated/ratings_features_common.pbjson.dart @@ -0,0 +1,55 @@ +// +// Generated code. Do not modify. +// source: ratings_features_common.proto +// +// @dart = 2.12 + +// ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: constant_identifier_names, library_prefixes +// ignore_for_file: non_constant_identifier_names, prefer_final_fields +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import + +import 'dart:convert' as $convert; +import 'dart:core' as $core; +import 'dart:typed_data' as $typed_data; + +@$core.Deprecated('Use ratingsBandDescriptor instead') +const RatingsBand$json = { + '1': 'RatingsBand', + '2': [ + {'1': 'VERY_GOOD', '2': 0}, + {'1': 'GOOD', '2': 1}, + {'1': 'NEUTRAL', '2': 2}, + {'1': 'POOR', '2': 3}, + {'1': 'VERY_POOR', '2': 4}, + {'1': 'INSUFFICIENT_VOTES', '2': 5}, + ], +}; + +/// Descriptor for `RatingsBand`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List ratingsBandDescriptor = $convert.base64Decode( + 'CgtSYXRpbmdzQmFuZBINCglWRVJZX0dPT0QQABIICgRHT09EEAESCwoHTkVVVFJBTBACEggKBF' + 'BPT1IQAxINCglWRVJZX1BPT1IQBBIWChJJTlNVRkZJQ0lFTlRfVk9URVMQBQ=='); + +@$core.Deprecated('Use ratingDescriptor instead') +const Rating$json = { + '1': 'Rating', + '2': [ + {'1': 'snap_id', '3': 1, '4': 1, '5': 9, '10': 'snapId'}, + {'1': 'total_votes', '3': 2, '4': 1, '5': 4, '10': 'totalVotes'}, + { + '1': 'ratings_band', + '3': 3, + '4': 1, + '5': 14, + '6': '.ratings.features.common.RatingsBand', + '10': 'ratingsBand' + }, + ], +}; + +/// Descriptor for `Rating`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List ratingDescriptor = $convert.base64Decode( + 'CgZSYXRpbmcSFwoHc25hcF9pZBgBIAEoCVIGc25hcElkEh8KC3RvdGFsX3ZvdGVzGAIgASgEUg' + 'p0b3RhbFZvdGVzEkcKDHJhdGluZ3NfYmFuZBgDIAEoDjIkLnJhdGluZ3MuZmVhdHVyZXMuY29t' + 'bW9uLlJhdGluZ3NCYW5kUgtyYXRpbmdzQmFuZA=='); diff --git a/lib/src/app.dart b/lib/src/ratings.dart similarity index 55% rename from lib/src/app.dart rename to lib/src/ratings.dart index c13be5d..0efe696 100644 --- a/lib/src/app.dart +++ b/lib/src/ratings.dart @@ -1,16 +1,32 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import 'generated/ratings_features_app.pb.dart' as pb; +import 'generated/ratings_features_common.pb.dart' as pb; -part 'app.freezed.dart'; +@immutable +class Rating { + final String snapId; + final int totalVotes; + final RatingsBand ratingsBand; -@freezed -class Rating with _$Rating { - const factory Rating({ - required String snapId, - required int totalVotes, - required RatingsBand ratingsBand, - }) = _Rating; + const Rating({ + required this.snapId, + required this.totalVotes, + required this.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; + } + + @override + int get hashCode => + snapId.hashCode ^ totalVotes.hashCode ^ ratingsBand.hashCode; } enum RatingsBand { diff --git a/lib/src/user.freezed.dart b/lib/src/user.freezed.dart index 6411431..e52bb57 100644 --- a/lib/src/user.freezed.dart +++ b/lib/src/user.freezed.dart @@ -73,18 +73,20 @@ class _$VoteCopyWithImpl<$Res, $Val extends Vote> } /// @nodoc -abstract class _$$_VoteCopyWith<$Res> implements $VoteCopyWith<$Res> { - factory _$$_VoteCopyWith(_$_Vote value, $Res Function(_$_Vote) then) = - __$$_VoteCopyWithImpl<$Res>; +abstract class _$$VoteImplCopyWith<$Res> implements $VoteCopyWith<$Res> { + factory _$$VoteImplCopyWith( + _$VoteImpl value, $Res Function(_$VoteImpl) then) = + __$$VoteImplCopyWithImpl<$Res>; @override @useResult $Res call({String snapId, int snapRevision, bool voteUp, DateTime dateTime}); } /// @nodoc -class __$$_VoteCopyWithImpl<$Res> extends _$VoteCopyWithImpl<$Res, _$_Vote> - implements _$$_VoteCopyWith<$Res> { - __$$_VoteCopyWithImpl(_$_Vote _value, $Res Function(_$_Vote) _then) +class __$$VoteImplCopyWithImpl<$Res> + extends _$VoteCopyWithImpl<$Res, _$VoteImpl> + implements _$$VoteImplCopyWith<$Res> { + __$$VoteImplCopyWithImpl(_$VoteImpl _value, $Res Function(_$VoteImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -95,7 +97,7 @@ class __$$_VoteCopyWithImpl<$Res> extends _$VoteCopyWithImpl<$Res, _$_Vote> Object? voteUp = null, Object? dateTime = null, }) { - return _then(_$_Vote( + return _then(_$VoteImpl( snapId: null == snapId ? _value.snapId : snapId // ignore: cast_nullable_to_non_nullable @@ -118,8 +120,8 @@ class __$$_VoteCopyWithImpl<$Res> extends _$VoteCopyWithImpl<$Res, _$_Vote> /// @nodoc -class _$_Vote implements _Vote { - const _$_Vote( +class _$VoteImpl implements _Vote { + const _$VoteImpl( {required this.snapId, required this.snapRevision, required this.voteUp, @@ -143,7 +145,7 @@ class _$_Vote implements _Vote { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_Vote && + other is _$VoteImpl && (identical(other.snapId, snapId) || other.snapId == snapId) && (identical(other.snapRevision, snapRevision) || other.snapRevision == snapRevision) && @@ -159,8 +161,8 @@ class _$_Vote implements _Vote { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_VoteCopyWith<_$_Vote> get copyWith => - __$$_VoteCopyWithImpl<_$_Vote>(this, _$identity); + _$$VoteImplCopyWith<_$VoteImpl> get copyWith => + __$$VoteImplCopyWithImpl<_$VoteImpl>(this, _$identity); } abstract class _Vote implements Vote { @@ -168,7 +170,7 @@ abstract class _Vote implements Vote { {required final String snapId, required final int snapRevision, required final bool voteUp, - required final DateTime dateTime}) = _$_Vote; + required final DateTime dateTime}) = _$VoteImpl; @override String get snapId; @@ -180,5 +182,6 @@ abstract class _Vote implements Vote { DateTime get dateTime; @override @JsonKey(ignore: true) - _$$_VoteCopyWith<_$_Vote> get copyWith => throw _privateConstructorUsedError; + _$$VoteImplCopyWith<_$VoteImpl> get copyWith => + throw _privateConstructorUsedError; } diff --git a/protos/ratings_features_app.proto b/protos/ratings_features_app.proto index e6494e4..ac40cff 100644 --- a/protos/ratings_features_app.proto +++ b/protos/ratings_features_app.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package ratings.features.app; +import "ratings_features_common.proto"; + service App { rpc GetRating (GetRatingRequest) returns (GetRatingResponse) {} } @@ -11,20 +13,5 @@ message GetRatingRequest { } message GetRatingResponse { - Rating rating = 1; -} - -message Rating { - string snap_id = 1; - uint64 total_votes = 2; - RatingsBand ratings_band = 3; -} - -enum RatingsBand { - VERY_GOOD = 0; - GOOD = 1; - NEUTRAL = 2; - POOR = 3; - VERY_POOR = 4; - INSUFFICIENT_VOTES = 5; + ratings.features.common.Rating rating = 1; } diff --git a/protos/ratings_features_chart.proto b/protos/ratings_features_chart.proto index d5f1b8c..19f39d3 100644 --- a/protos/ratings_features_chart.proto +++ b/protos/ratings_features_chart.proto @@ -2,30 +2,24 @@ syntax = "proto3"; package ratings.features.chart; +import "ratings_features_common.proto"; + service Chart { rpc GetChart (GetChartRequest) returns (GetChartResponse) {} } message GetChartRequest { Timeframe timeframe = 1; - ChartType type = 2; -} - -enum ChartType { - CHART_TYPE_TOP_UNSPECIFIED = 0; - CHART_TYPE_TOP = 1; } message GetChartResponse { Timeframe timeframe = 1; - ChartType type = 2; - repeated ChartData ordered_chart_data = 3; + repeated ChartData ordered_chart_data = 2; } message ChartData { - string app = 1; - uint64 total_up_votes = 2; - uint64 total_down_votes = 3; + float raw_rating = 1; + ratings.features.common.Rating rating = 2; } enum Timeframe { diff --git a/protos/ratings_features_common.proto b/protos/ratings_features_common.proto new file mode 100644 index 0000000..84a53d5 --- /dev/null +++ b/protos/ratings_features_common.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package ratings.features.common; + +message Rating { + string snap_id = 1; + uint64 total_votes = 2; + RatingsBand ratings_band = 3; +} + +enum RatingsBand { + VERY_GOOD = 0; + GOOD = 1; + NEUTRAL = 2; + POOR = 3; + VERY_POOR = 4; + INSUFFICIENT_VOTES = 5; +} diff --git a/test/ratings_client_test.dart b/test/ratings_client_test.dart index 0f21cee..061e8f2 100644 --- a/test/ratings_client_test.dart +++ b/test/ratings_client_test.dart @@ -1,11 +1,15 @@ import 'dart:async'; import 'package:app_center_ratings_client/app_center_ratings_client.dart'; -import 'package:app_center_ratings_client/src/app.dart' as app; +import 'package:app_center_ratings_client/src/chart.dart' as chart; import 'package:app_center_ratings_client/src/generated/google/protobuf/empty.pb.dart'; import 'package:app_center_ratings_client/src/generated/google/protobuf/timestamp.pb.dart'; -import 'package:app_center_ratings_client/src/generated/ratings_features_app.pbgrpc.dart'; +import 'package:app_center_ratings_client/src/generated/ratings_features_app.pbgrpc.dart' + as pb; +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pbgrpc.dart'; +import 'package:app_center_ratings_client/src/generated/ratings_features_common.pb.dart'; import 'package:app_center_ratings_client/src/generated/ratings_features_user.pbgrpc.dart'; +import 'package:app_center_ratings_client/src/ratings.dart' as ratings; import 'package:app_center_ratings_client/src/user.dart' as user; import 'package:fixnum/fixnum.dart'; import 'package:grpc/grpc.dart'; @@ -15,14 +19,64 @@ import 'package:test/test.dart'; import 'ratings_client_test.mocks.dart'; -@GenerateMocks([AppClient, UserClient]) +@GenerateMocks([pb.AppClient, UserClient, ChartClient]) void main() { final mockAppClient = MockAppClient(); final mockUserClient = MockUserClient(); - final ratingsClient = RatingsClient.withClients( - mockAppClient, - mockUserClient, - ); + final mockChartClient = MockChartClient(); + final ratingsClient = + RatingsClient.withClients(mockAppClient, mockUserClient, mockChartClient); + + test('get chart', () async { + final snapId = 'foobar'; + final token = 'bar'; + final timeframe = chart.Timeframe.month; + final pbChartList = [ + ChartData( + rawRating: 3, + rating: Rating( + snapId: snapId, + totalVotes: Int64(105), + ratingsBand: RatingsBand.NEUTRAL, + )) + ]; + + final expectedResponse = [ + chart.ChartData( + rawRating: 3, + rating: ratings.Rating( + snapId: snapId, + totalVotes: 105, + ratingsBand: ratings.RatingsBand.neutral, + )) + ]; + final mockResponse = GetChartResponse( + timeframe: Timeframe.TIMEFRAME_MONTH, + orderedChartData: pbChartList, + ); + final request = GetChartRequest(timeframe: Timeframe.TIMEFRAME_MONTH); + when(mockChartClient.getChart( + request, + options: anyNamed('options'), + )).thenAnswer((_) => MockResponseFuture(mockResponse)); + final response = await ratingsClient.getChart(timeframe, token); + expect( + response, + equals(expectedResponse), + ); + final capturedArgs = verify(mockChartClient.getChart( + request, + options: captureAnyNamed('options'), + )).captured; + final capturedOptions = capturedArgs.single as CallOptions; + expect( + capturedOptions.metadata, + containsPair( + 'authorization', + 'Bearer $token', + ), + ); + }); test('get rating', () async { final snapId = 'foo'; @@ -32,17 +86,18 @@ void main() { totalVotes: Int64(105), ratingsBand: RatingsBand.NEUTRAL, ); - final expectedResponse = app.Rating( + final expectedResponse = ratings.Rating( snapId: snapId, totalVotes: 105, - ratingsBand: app.RatingsBand.neutral, + ratingsBand: ratings.RatingsBand.neutral, ); - final mockResponse = GetRatingResponse(rating: pbRating); - final request = GetRatingRequest(snapId: snapId); + final mockResponse = pb.GetRatingResponse(rating: pbRating); + final request = pb.GetRatingRequest(snapId: snapId); when(mockAppClient.getRating( request, options: anyNamed('options'), - )).thenAnswer((_) => MockResponseFuture(mockResponse)); + )).thenAnswer( + (_) => MockResponseFuture(mockResponse)); final response = await ratingsClient.getRating( snapId, token, diff --git a/test/ratings_client_test.mocks.dart b/test/ratings_client_test.mocks.dart index def6ce3..334cd95 100644 --- a/test/ratings_client_test.mocks.dart +++ b/test/ratings_client_test.mocks.dart @@ -11,6 +11,10 @@ import 'package:app_center_ratings_client/src/generated/ratings_features_app.pb. as _i5; import 'package:app_center_ratings_client/src/generated/ratings_features_app.pbgrpc.dart' as _i4; +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pb.dart' + as _i11; +import 'package:app_center_ratings_client/src/generated/ratings_features_chart.pbgrpc.dart' + as _i10; import 'package:app_center_ratings_client/src/generated/ratings_features_user.pb.dart' as _i8; import 'package:app_center_ratings_client/src/generated/ratings_features_user.pbgrpc.dart' @@ -91,6 +95,7 @@ class MockAppClient extends _i1.Mock implements _i4.AppClient { ), ), ) as _i2.ResponseFuture<_i5.GetRatingResponse>); + @override _i3.ClientCall $createCall( _i2.ClientMethod? method, @@ -118,6 +123,7 @@ class MockAppClient extends _i1.Mock implements _i4.AppClient { ), ), ) as _i3.ClientCall); + @override _i2.ResponseFuture $createUnaryCall( _i2.ClientMethod? method, @@ -145,6 +151,7 @@ class MockAppClient extends _i1.Mock implements _i4.AppClient { ), ), ) as _i2.ResponseFuture); + @override _i2.ResponseStream $createStreamingCall( _i2.ClientMethod? method, @@ -202,6 +209,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture<_i8.AuthenticateResponse>); + @override _i2.ResponseFuture<_i9.Empty> delete( _i9.Empty? request, { @@ -222,6 +230,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture<_i9.Empty>); + @override _i2.ResponseFuture<_i9.Empty> vote( _i8.VoteRequest? request, { @@ -242,6 +251,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture<_i9.Empty>); + @override _i2.ResponseFuture<_i8.ListMyVotesResponse> listMyVotes( _i8.ListMyVotesRequest? request, { @@ -262,6 +272,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture<_i8.ListMyVotesResponse>); + @override _i2.ResponseFuture<_i8.GetSnapVotesResponse> getSnapVotes( _i8.GetSnapVotesRequest? request, { @@ -282,6 +293,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture<_i8.GetSnapVotesResponse>); + @override _i3.ClientCall $createCall( _i2.ClientMethod? method, @@ -309,6 +321,7 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i3.ClientCall); + @override _i2.ResponseFuture $createUnaryCall( _i2.ClientMethod? method, @@ -336,6 +349,121 @@ class MockUserClient extends _i1.Mock implements _i7.UserClient { ), ), ) as _i2.ResponseFuture); + + @override + _i2.ResponseStream $createStreamingCall( + _i2.ClientMethod? method, + _i6.Stream? requests, { + _i2.CallOptions? options, + }) => + (super.noSuchMethod( + Invocation.method( + #$createStreamingCall, + [ + method, + requests, + ], + {#options: options}, + ), + returnValue: _FakeResponseStream_2( + this, + Invocation.method( + #$createStreamingCall, + [ + method, + requests, + ], + {#options: options}, + ), + ), + ) as _i2.ResponseStream); +} + +/// A class which mocks [ChartClient]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockChartClient extends _i1.Mock implements _i10.ChartClient { + MockChartClient() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.ResponseFuture<_i11.GetChartResponse> getChart( + _i11.GetChartRequest? request, { + _i2.CallOptions? options, + }) => + (super.noSuchMethod( + Invocation.method( + #getChart, + [request], + {#options: options}, + ), + returnValue: _FakeResponseFuture_0<_i11.GetChartResponse>( + this, + Invocation.method( + #getChart, + [request], + {#options: options}, + ), + ), + ) as _i2.ResponseFuture<_i11.GetChartResponse>); + + @override + _i3.ClientCall $createCall( + _i2.ClientMethod? method, + _i6.Stream? requests, { + _i2.CallOptions? options, + }) => + (super.noSuchMethod( + Invocation.method( + #$createCall, + [ + method, + requests, + ], + {#options: options}, + ), + returnValue: _FakeClientCall_1( + this, + Invocation.method( + #$createCall, + [ + method, + requests, + ], + {#options: options}, + ), + ), + ) as _i3.ClientCall); + + @override + _i2.ResponseFuture $createUnaryCall( + _i2.ClientMethod? method, + Q? request, { + _i2.CallOptions? options, + }) => + (super.noSuchMethod( + Invocation.method( + #$createUnaryCall, + [ + method, + request, + ], + {#options: options}, + ), + returnValue: _FakeResponseFuture_0( + this, + Invocation.method( + #$createUnaryCall, + [ + method, + request, + ], + {#options: options}, + ), + ), + ) as _i2.ResponseFuture); + @override _i2.ResponseStream $createStreamingCall( _i2.ClientMethod? method,