Skip to content

Commit

Permalink
feat: aligning with proto refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-hagemann committed Nov 24, 2023
1 parent caab17f commit 01b55d2
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 692 deletions.
22 changes: 11 additions & 11 deletions lib/app_center_ratings_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:async';
import 'package:grpc/grpc.dart';
import 'package:meta/meta.dart';

import 'src/app.dart' as app;
import 'src/chart.dart' as chart;
import 'src/common.dart' as app;
import 'src/generated/google/protobuf/empty.pb.dart';
import 'src/generated/ratings_features_app.pbgrpc.dart';
import 'src/generated/ratings_features_chart.pbgrpc.dart';
Expand Down Expand Up @@ -50,6 +50,16 @@ class RatingsClient {
await _userClient.delete(request, options: callOptions);
}

Future<List<chart.ChartData>> getChart(
chart.Timeframe timeframe, String token) async {
final request = 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<app.Rating> getRating(
String snapId,
String token,
Expand Down Expand Up @@ -97,14 +107,4 @@ class RatingsClient {
CallOptions(metadata: {'authorization': 'Bearer $token'});
await _userClient.vote(request, options: callOptions);
}

Future<List<chart.ChartData>> getChart(
chart.Timeframe timeframe, String token) async {
final request = 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();
}
}
169 changes: 0 additions & 169 deletions lib/src/app.freezed.dart

This file was deleted.

37 changes: 5 additions & 32 deletions lib/src/chart.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import 'package:freezed_annotation/freezed_annotation.dart';

import 'common.dart' as common;
import 'generated/ratings_features_chart.pb.dart' as pb;

part 'chart.freezed.dart';

@freezed
class ChartData with _$ChartData {
const factory ChartData({
required String app,
required int totalUpVotes,
required int totalDownVotes,
required double rating,
required RatingsBand ratingsBand,
required double rawRating,
required common.Rating rating,
}) = _ChartData;
}

enum RatingsBand {
veryGood,
good,
neutral,
poor,
veryPoor,
insufficientVotes,
}

enum Timeframe {
unspecified,
week,
Expand All @@ -33,28 +22,12 @@ enum Timeframe {
extension ChartDataFromDTO on pb.ChartData {
ChartData fromDTO() {
return ChartData(
app: this.app,
totalUpVotes: this.totalUpVotes.toInt(),
totalDownVotes: this.totalDownVotes.toInt(),
rating: this.rating,
ratingsBand: this.ratingsBand.fromDTO(),
rating: this.rating.fromDTO(),
rawRating: this.rawRating,
);
}
}

extension RatingsBandFromDTO on pb.RatingsBand {
RatingsBand fromDTO() {
return switch (this) {
pb.RatingsBand.VERY_GOOD => RatingsBand.veryGood,
pb.RatingsBand.GOOD => RatingsBand.good,
pb.RatingsBand.NEUTRAL => RatingsBand.neutral,
pb.RatingsBand.POOR => RatingsBand.poor,
pb.RatingsBand.VERY_POOR => RatingsBand.veryPoor,
_ => RatingsBand.insufficientVotes,
};
}
}

extension TimeframeFromDTO on pb.Timeframe {
Timeframe fromDTO() {
return switch (this) {
Expand Down
Loading

0 comments on commit 01b55d2

Please sign in to comment.