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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include snap names in ratings service requests #1873

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/app_center/lib/ratings/ratings_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RatingsModel extends _$RatingsModel {
}

final results = await Future.wait([
_ratings.getRating(snapId),
_ratings.getRating(snapName, snapId),
_ratings.getSnapVotes(snapId),
]);

Expand Down
16 changes: 13 additions & 3 deletions packages/app_center/lib/ratings/ratings_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ class RatingsService {
}
}

Future<ratings.Rating?> getRating(String snapId) async {
Future<ratings.Rating?> getRating(
String snapName,
// TODO: remove snapId once the server doesn't require it anymore
String snapId,
) async {
await _ensureValidToken();
return client.getRating(snapId, _jwt!);
return client.getRating(snapName, snapId, _jwt!);
}

Future<List<ratings.ChartData>> getChart(SnapCategoryEnum category) async {
Expand All @@ -46,7 +50,13 @@ class RatingsService {

Future<void> vote(ratings.Vote vote) async {
await _ensureValidToken();
await client.vote(vote.snapId, vote.snapRevision, vote.voteUp, _jwt!);
await client.vote(
vote.snapName,
vote.snapId,
vote.snapRevision,
vote.voteUp,
_jwt!,
);
}

Future<void> delete() async {
Expand Down
4 changes: 2 additions & 2 deletions packages/app_center/test/ratings_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
);
final service = RatingsService(mockClient, id: 'myId');

final rating = await service.getRating('firefox');
final rating = await service.getRating('firefox', '1234');
verify(mockClient.authenticate('myId')).called(1);
expect(
rating,
Expand Down Expand Up @@ -101,7 +101,7 @@ void main() {
),
);
verify(mockClient.authenticate('myId')).called(1);
verify(mockClient.vote('7890', 42, true, 'jwt')).called(1);
verify(mockClient.vote('thunderbird', '7890', 42, true, 'jwt')).called(1);
});

test('delete', () async {
Expand Down
4 changes: 2 additions & 2 deletions packages/app_center/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ MockRatingsService registerMockRatingsService({
List<Vote>? snapVotes,
}) {
final service = MockRatingsService();
when(service.getRating(any)).thenAnswer(
when(service.getRating(any, any)).thenAnswer(
(_) async =>
rating ??
const Rating(
Expand All @@ -322,7 +322,7 @@ MockRatingsClient createMockRatingsClient({
}) {
final client = MockRatingsClient();
when(client.authenticate(any)).thenAnswer((_) async => token ?? '');
when(client.getRating(any, any)).thenAnswer(
when(client.getRating(any, any, any)).thenAnswer(
(_) async =>
rating ??
const Rating(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import 'ratings_features_common.pb.dart' as $4;
class GetRatingRequest extends $pb.GeneratedMessage {
factory GetRatingRequest({
$core.String? snapId,
$core.String? snapName,
}) {
final $result = create();
if (snapId != null) {
$result.snapId = snapId;
}
if (snapName != null) {
$result.snapName = snapName;
}
return $result;
}
GetRatingRequest._() : super();
Expand All @@ -31,6 +35,7 @@ class GetRatingRequest extends $pb.GeneratedMessage {

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'GetRatingRequest', package: const $pb.PackageName(_omitMessageNames ? '' : 'ratings.features.app'), createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'snapId')
..aOS(2, _omitFieldNames ? '' : 'snapName')
..hasRequiredFields = false
;

Expand Down Expand Up @@ -63,6 +68,15 @@ class GetRatingRequest extends $pb.GeneratedMessage {
$core.bool hasSnapId() => $_has(0);
@$pb.TagNumber(1)
void clearSnapId() => clearField(1);

@$pb.TagNumber(2)
$core.String get snapName => $_getSZ(1);
@$pb.TagNumber(2)
set snapName($core.String v) { $_setString(1, v); }
@$pb.TagNumber(2)
$core.bool hasSnapName() => $_has(1);
@$pb.TagNumber(2)
void clearSnapName() => clearField(2);
}

class GetRatingResponse extends $pb.GeneratedMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ const GetRatingRequest$json = {
'1': 'GetRatingRequest',
'2': [
{'1': 'snap_id', '3': 1, '4': 1, '5': 9, '10': 'snapId'},
{'1': 'snap_name', '3': 2, '4': 1, '5': 9, '10': 'snapName'},
],
};

/// Descriptor for `GetRatingRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getRatingRequestDescriptor = $convert.base64Decode(
'ChBHZXRSYXRpbmdSZXF1ZXN0EhcKB3NuYXBfaWQYASABKAlSBnNuYXBJZA==');
'ChBHZXRSYXRpbmdSZXF1ZXN0EhcKB3NuYXBfaWQYASABKAlSBnNuYXBJZBIbCglzbmFwX25hbW'
'UYAiABKAlSCHNuYXBOYW1l');

@$core.Deprecated('Use getRatingResponseDescriptor instead')
const GetRatingResponse$json = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,56 +115,6 @@ class AuthenticateResponse extends $pb.GeneratedMessage {
void clearToken() => clearField(1);
}

class ListMyVotesRequest extends $pb.GeneratedMessage {
factory ListMyVotesRequest({
$core.String? snapIdFilter,
}) {
final $result = create();
if (snapIdFilter != null) {
$result.snapIdFilter = snapIdFilter;
}
return $result;
}
ListMyVotesRequest._() : super();
factory ListMyVotesRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory ListMyVotesRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'ListMyVotesRequest', package: const $pb.PackageName(_omitMessageNames ? '' : 'ratings.features.user'), createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'snapIdFilter')
..hasRequiredFields = false
;

@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
ListMyVotesRequest clone() => ListMyVotesRequest()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
ListMyVotesRequest copyWith(void Function(ListMyVotesRequest) updates) => super.copyWith((message) => updates(message as ListMyVotesRequest)) as ListMyVotesRequest;

$pb.BuilderInfo get info_ => _i;

@$core.pragma('dart2js:noInline')
static ListMyVotesRequest create() => ListMyVotesRequest._();
ListMyVotesRequest createEmptyInstance() => create();
static $pb.PbList<ListMyVotesRequest> createRepeated() => $pb.PbList<ListMyVotesRequest>();
@$core.pragma('dart2js:noInline')
static ListMyVotesRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<ListMyVotesRequest>(create);
static ListMyVotesRequest? _defaultInstance;

@$pb.TagNumber(1)
$core.String get snapIdFilter => $_getSZ(0);
@$pb.TagNumber(1)
set snapIdFilter($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasSnapIdFilter() => $_has(0);
@$pb.TagNumber(1)
void clearSnapIdFilter() => clearField(1);
}

class ListMyVotesResponse extends $pb.GeneratedMessage {
factory ListMyVotesResponse({
$core.Iterable<Vote>? votes,
Expand Down Expand Up @@ -212,11 +162,15 @@ class ListMyVotesResponse extends $pb.GeneratedMessage {
class GetSnapVotesRequest extends $pb.GeneratedMessage {
factory GetSnapVotesRequest({
$core.String? snapId,
$core.String? snapName,
}) {
final $result = create();
if (snapId != null) {
$result.snapId = snapId;
}
if (snapName != null) {
$result.snapName = snapName;
}
return $result;
}
GetSnapVotesRequest._() : super();
Expand All @@ -225,6 +179,7 @@ class GetSnapVotesRequest extends $pb.GeneratedMessage {

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'GetSnapVotesRequest', package: const $pb.PackageName(_omitMessageNames ? '' : 'ratings.features.user'), createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'snapId')
..aOS(2, _omitFieldNames ? '' : 'snapName')
..hasRequiredFields = false
;

Expand Down Expand Up @@ -257,6 +212,15 @@ class GetSnapVotesRequest extends $pb.GeneratedMessage {
$core.bool hasSnapId() => $_has(0);
@$pb.TagNumber(1)
void clearSnapId() => clearField(1);

@$pb.TagNumber(2)
$core.String get snapName => $_getSZ(1);
@$pb.TagNumber(2)
set snapName($core.String v) { $_setString(1, v); }
@$pb.TagNumber(2)
$core.bool hasSnapName() => $_has(1);
@$pb.TagNumber(2)
void clearSnapName() => clearField(2);
}

class GetSnapVotesResponse extends $pb.GeneratedMessage {
Expand Down Expand Up @@ -416,6 +380,7 @@ class VoteRequest extends $pb.GeneratedMessage {
$core.String? snapId,
$core.int? snapRevision,
$core.bool? voteUp,
$core.String? snapName,
}) {
final $result = create();
if (snapId != null) {
Expand All @@ -427,6 +392,9 @@ class VoteRequest extends $pb.GeneratedMessage {
if (voteUp != null) {
$result.voteUp = voteUp;
}
if (snapName != null) {
$result.snapName = snapName;
}
return $result;
}
VoteRequest._() : super();
Expand All @@ -437,6 +405,7 @@ class VoteRequest extends $pb.GeneratedMessage {
..aOS(1, _omitFieldNames ? '' : 'snapId')
..a<$core.int>(2, _omitFieldNames ? '' : 'snapRevision', $pb.PbFieldType.O3)
..aOB(3, _omitFieldNames ? '' : 'voteUp')
..aOS(4, _omitFieldNames ? '' : 'snapName')
..hasRequiredFields = false
;

Expand Down Expand Up @@ -487,6 +456,15 @@ class VoteRequest extends $pb.GeneratedMessage {
$core.bool hasVoteUp() => $_has(2);
@$pb.TagNumber(3)
void clearVoteUp() => clearField(3);

@$pb.TagNumber(4)
$core.String get snapName => $_getSZ(3);
@$pb.TagNumber(4)
set snapName($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4)
$core.bool hasSnapName() => $_has(3);
@$pb.TagNumber(4)
void clearSnapName() => clearField(4);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ const AuthenticateResponse$json = {
final $typed_data.Uint8List authenticateResponseDescriptor = $convert.base64Decode(
'ChRBdXRoZW50aWNhdGVSZXNwb25zZRIUCgV0b2tlbhgBIAEoCVIFdG9rZW4=');

@$core.Deprecated('Use listMyVotesRequestDescriptor instead')
const ListMyVotesRequest$json = {
'1': 'ListMyVotesRequest',
'2': [
{'1': 'snap_id_filter', '3': 1, '4': 1, '5': 9, '10': 'snapIdFilter'},
],
};

/// Descriptor for `ListMyVotesRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List listMyVotesRequestDescriptor = $convert.base64Decode(
'ChJMaXN0TXlWb3Rlc1JlcXVlc3QSJAoOc25hcF9pZF9maWx0ZXIYASABKAlSDHNuYXBJZEZpbH'
'Rlcg==');

@$core.Deprecated('Use listMyVotesResponseDescriptor instead')
const ListMyVotesResponse$json = {
'1': 'ListMyVotesResponse',
Expand All @@ -68,12 +55,14 @@ const GetSnapVotesRequest$json = {
'1': 'GetSnapVotesRequest',
'2': [
{'1': 'snap_id', '3': 1, '4': 1, '5': 9, '10': 'snapId'},
{'1': 'snap_name', '3': 2, '4': 1, '5': 9, '10': 'snapName'},
],
};

/// Descriptor for `GetSnapVotesRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getSnapVotesRequestDescriptor = $convert.base64Decode(
'ChNHZXRTbmFwVm90ZXNSZXF1ZXN0EhcKB3NuYXBfaWQYASABKAlSBnNuYXBJZA==');
'ChNHZXRTbmFwVm90ZXNSZXF1ZXN0EhcKB3NuYXBfaWQYASABKAlSBnNuYXBJZBIbCglzbmFwX2'
'5hbWUYAiABKAlSCHNuYXBOYW1l');

@$core.Deprecated('Use getSnapVotesResponseDescriptor instead')
const GetSnapVotesResponse$json = {
Expand Down Expand Up @@ -114,11 +103,13 @@ const VoteRequest$json = {
{'1': 'snap_id', '3': 1, '4': 1, '5': 9, '10': 'snapId'},
{'1': 'snap_revision', '3': 2, '4': 1, '5': 5, '10': 'snapRevision'},
{'1': 'vote_up', '3': 3, '4': 1, '5': 8, '10': 'voteUp'},
{'1': 'snap_name', '3': 4, '4': 1, '5': 9, '10': 'snapName'},
],
};

/// Descriptor for `VoteRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List voteRequestDescriptor = $convert.base64Decode(
'CgtWb3RlUmVxdWVzdBIXCgdzbmFwX2lkGAEgASgJUgZzbmFwSWQSIwoNc25hcF9yZXZpc2lvbh'
'gCIAEoBVIMc25hcFJldmlzaW9uEhcKB3ZvdGVfdXAYAyABKAhSBnZvdGVVcA==');
'gCIAEoBVIMc25hcFJldmlzaW9uEhcKB3ZvdGVfdXAYAyABKAhSBnZvdGVVcBIbCglzbmFwX25h'
'bWUYBCABKAlSCHNuYXBOYW1l');

10 changes: 9 additions & 1 deletion packages/app_center_ratings_client/lib/src/ratings_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ class RatingsClient {
}

Future<Rating> getRating(
String snapName,
// TODO: remove snapId once the server doesn't require it anymore
String snapId,
String token,
) async {
final request = app_pb.GetRatingRequest(snapId: snapId);
final request = app_pb.GetRatingRequest(
snapName: snapName,
snapId: snapId,
);
final callOptions =
CallOptions(metadata: {'authorization': 'Bearer $token'});
final grpcResponse = await _appClient.getRating(
Expand All @@ -95,12 +100,15 @@ class RatingsClient {
}

Future<void> vote(
String snapName,
// TODO: remove snapId once the server doesn't require it anymore
String snapId,
int snapRevision,
bool voteUp,
String token,
) async {
final request = user_pb.VoteRequest(
snapName: snapName,
snapId: snapId,
snapRevision: snapRevision,
voteUp: voteUp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ service App {

message GetRatingRequest {
string snap_id = 1;
string snap_name = 2;
}

message GetRatingResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ message AuthenticateResponse {
string token = 1;
}

message ListMyVotesRequest {
string snap_id_filter = 1;
}

message ListMyVotesResponse {
repeated Vote votes = 1;
}

message GetSnapVotesRequest {
string snap_id = 1;
string snap_name = 2;
}

message GetSnapVotesResponse {
Expand All @@ -49,4 +46,5 @@ message VoteRequest {
string snap_id = 1;
int32 snap_revision = 2;
bool vote_up = 3;
string snap_name = 4;
}
Loading
Loading