feat(shorebird_code_push_protocol): add UpdateAppCollaboratorRequest (#2478)

This commit is contained in:
Bryan Oltman
2024-09-09 15:26:21 -04:00
committed by GitHub
parent 6b1feccf53
commit 18b1838d59
18 changed files with 122 additions and 25 deletions
@@ -14,7 +14,7 @@ CreatePatchRequest _$CreatePatchRequestFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = CreatePatchRequest(
releaseId: $checkedConvert('release_id', (v) => v as int),
releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()),
metadata:
$checkedConvert('metadata', (v) => v as Map<String, dynamic>),
);
@@ -14,8 +14,8 @@ CreatePatchResponse _$CreatePatchResponseFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = CreatePatchResponse(
id: $checkedConvert('id', (v) => v as int),
number: $checkedConvert('number', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
number: $checkedConvert('number', (v) => (v as num).toInt()),
);
return val;
},
@@ -15,13 +15,13 @@ CreatePatchArtifactResponse _$CreatePatchArtifactResponseFromJson(
json,
($checkedConvert) {
final val = CreatePatchArtifactResponse(
id: $checkedConvert('id', (v) => v as int),
patchId: $checkedConvert('patch_id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()),
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert(
'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)),
hash: $checkedConvert('hash', (v) => v as String),
size: $checkedConvert('size', (v) => v as int),
size: $checkedConvert('size', (v) => (v as num).toInt()),
url: $checkedConvert('url', (v) => v as String),
);
return val;
@@ -15,13 +15,13 @@ CreateReleaseArtifactResponse _$CreateReleaseArtifactResponseFromJson(
json,
($checkedConvert) {
final val = CreateReleaseArtifactResponse(
id: $checkedConvert('id', (v) => v as int),
releaseId: $checkedConvert('release_id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()),
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert(
'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)),
hash: $checkedConvert('hash', (v) => v as String),
size: $checkedConvert('size', (v) => v as int),
size: $checkedConvert('size', (v) => (v as num).toInt()),
url: $checkedConvert('url', (v) => v as String),
);
return val;
@@ -14,8 +14,8 @@ PromotePatchRequest _$PromotePatchRequestFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = PromotePatchRequest(
patchId: $checkedConvert('patch_id', (v) => v as int),
channelId: $checkedConvert('channel_id', (v) => v as int),
patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()),
channelId: $checkedConvert('channel_id', (v) => (v as num).toInt()),
);
return val;
},
@@ -0,0 +1,26 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
part 'update_app_collaborator_request.g.dart';
/// {@template update_app_collaborator_request}
/// The request body for
/// PATCH /api/v1/apps/<appId>/collaborators/<collaboratorId>
/// {@endtemplate}
@JsonSerializable()
class UpdateAppCollaboratorRequest {
/// {@macro update_app_collaborator_request}
const UpdateAppCollaboratorRequest({
required this.role,
});
/// Converts a Map<String, dynamic> to a [UpdateAppCollaboratorRequest].
factory UpdateAppCollaboratorRequest.fromJson(Map<String, dynamic> json) =>
_$UpdateAppCollaboratorRequestFromJson(json);
/// Converts a [UpdateAppCollaboratorRequest] to a Map<String, dynamic>.
Map<String, dynamic> toJson() => _$UpdateAppCollaboratorRequestToJson(this);
/// The new role for the collaborator.
final AppCollaboratorRole role;
}
@@ -0,0 +1,34 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
part of 'update_app_collaborator_request.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UpdateAppCollaboratorRequest _$UpdateAppCollaboratorRequestFromJson(
Map<String, dynamic> json) =>
$checkedCreate(
'UpdateAppCollaboratorRequest',
json,
($checkedConvert) {
final val = UpdateAppCollaboratorRequest(
role: $checkedConvert(
'role', (v) => $enumDecode(_$AppCollaboratorRoleEnumMap, v)),
);
return val;
},
);
Map<String, dynamic> _$UpdateAppCollaboratorRequestToJson(
UpdateAppCollaboratorRequest instance) =>
<String, dynamic>{
'role': _$AppCollaboratorRoleEnumMap[instance.role]!,
};
const _$AppCollaboratorRoleEnumMap = {
AppCollaboratorRole.admin: 'admin',
AppCollaboratorRole.developer: 'developer',
};
@@ -0,0 +1,19 @@
/// {@template app_collaborator_role}
/// The role a user has for a specific app. Roles are associated with different
/// permission levels.
/// {@endtemplate}
enum AppCollaboratorRole {
/// A user with this role can perform all available actions on apps, releases,
/// patches, channels, and collaborators.
admin('admin'),
/// A user with this role can manage releases and patches, but cannot manage
/// collaborators or the application itself.
developer('developer');
/// {@macro app_collaborator_role}
const AppCollaboratorRole(this.name);
/// The name of the role.
final String name;
}
@@ -21,8 +21,8 @@ AppMetadata _$AppMetadataFromJson(Map<String, dynamic> json) => $checkedCreate(
$checkedConvert('updated_at', (v) => DateTime.parse(v as String)),
latestReleaseVersion:
$checkedConvert('latest_release_version', (v) => v as String?),
latestPatchNumber:
$checkedConvert('latest_patch_number', (v) => v as int?),
latestPatchNumber: $checkedConvert(
'latest_patch_number', (v) => (v as num?)?.toInt()),
);
return val;
},
@@ -13,7 +13,7 @@ Channel _$ChannelFromJson(Map<String, dynamic> json) => $checkedCreate(
json,
($checkedConvert) {
final val = Channel(
id: $checkedConvert('id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
appId: $checkedConvert('app_id', (v) => v as String),
name: $checkedConvert('name', (v) => v as String),
);
@@ -1,4 +1,5 @@
export 'app.dart';
export 'app_collaborator_role.dart';
export 'app_metadata.dart';
export 'auth_provider.dart';
export 'channel.dart';
@@ -13,8 +13,8 @@ Patch _$PatchFromJson(Map<String, dynamic> json) => $checkedCreate(
json,
($checkedConvert) {
final val = Patch(
id: $checkedConvert('id', (v) => v as int),
number: $checkedConvert('number', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
number: $checkedConvert('number', (v) => (v as num).toInt()),
);
return val;
},
@@ -14,13 +14,13 @@ PatchArtifact _$PatchArtifactFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = PatchArtifact(
id: $checkedConvert('id', (v) => v as int),
patchId: $checkedConvert('patch_id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
patchId: $checkedConvert('patch_id', (v) => (v as num).toInt()),
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert(
'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)),
hash: $checkedConvert('hash', (v) => v as String),
size: $checkedConvert('size', (v) => v as int),
size: $checkedConvert('size', (v) => (v as num).toInt()),
createdAt:
$checkedConvert('created_at', (v) => DateTime.parse(v as String)),
);
@@ -13,7 +13,7 @@ Release _$ReleaseFromJson(Map<String, dynamic> json) => $checkedCreate(
json,
($checkedConvert) {
final val = Release(
id: $checkedConvert('id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
appId: $checkedConvert('app_id', (v) => v as String),
version: $checkedConvert('version', (v) => v as String),
flutterRevision:
@@ -14,13 +14,13 @@ ReleaseArtifact _$ReleaseArtifactFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = ReleaseArtifact(
id: $checkedConvert('id', (v) => v as int),
releaseId: $checkedConvert('release_id', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
releaseId: $checkedConvert('release_id', (v) => (v as num).toInt()),
arch: $checkedConvert('arch', (v) => v as String),
platform: $checkedConvert(
'platform', (v) => $enumDecode(_$ReleasePlatformEnumMap, v)),
hash: $checkedConvert('hash', (v) => v as String),
size: $checkedConvert('size', (v) => v as int),
size: $checkedConvert('size', (v) => (v as num).toInt()),
url: $checkedConvert('url', (v) => v as String),
podfileLockHash:
$checkedConvert('podfile_lock_hash', (v) => v as String?),
@@ -14,8 +14,8 @@ ReleasePatch _$ReleasePatchFromJson(Map<String, dynamic> json) =>
json,
($checkedConvert) {
final val = ReleasePatch(
id: $checkedConvert('id', (v) => v as int),
number: $checkedConvert('number', (v) => v as int),
id: $checkedConvert('id', (v) => (v as num).toInt()),
number: $checkedConvert('number', (v) => (v as num).toInt()),
channel: $checkedConvert('channel', (v) => v as String?),
artifacts: $checkedConvert(
'artifacts',
@@ -0,0 +1,16 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:shorebird_code_push_protocol/src/messages/update_app_collaborator/update_app_collaborator_request.dart';
import 'package:test/test.dart';
void main() {
group(UpdateAppCollaboratorRequest, () {
test('can be (de)serialized', () {
const request =
UpdateAppCollaboratorRequest(role: AppCollaboratorRole.admin);
expect(
UpdateAppCollaboratorRequest.fromJson(request.toJson()).toJson(),
equals(request.toJson()),
);
});
});
}