chore(shorebird_code_push_protocol): add CreateUserRequest message (#321)

This commit is contained in:
Bryan Oltman
2023-04-19 11:45:49 -04:00
committed by GitHub
parent 1c64cb52c6
commit 22a66df96a
7 changed files with 79 additions and 1 deletions
@@ -0,0 +1 @@
export 'create_user_request.dart';
@@ -0,0 +1,27 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
part 'create_user_request.g.dart';
/// {@template create_user_request}
/// The request body for POST /api/v1/users, which creates a new User.
///
/// Email is retrieved from the user's auth token.
/// {@endtemplate}
@JsonSerializable()
class CreateUserRequest {
/// {@macro create_user_request}
const CreateUserRequest({
required this.name,
});
/// Converts a JSON object to a [CreateUserRequest].
factory CreateUserRequest.fromJson(Json json) =>
_$CreateUserRequestFromJson(json);
/// Converts a [CreateUserRequest] to a JSON object.
Json toJson() => _$CreateUserRequestToJson(this);
/// The new user's display name.
final String name;
}
@@ -0,0 +1,26 @@
// 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 'create_user_request.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
CreateUserRequest _$CreateUserRequestFromJson(Map<String, dynamic> json) =>
$checkedCreate(
'CreateUserRequest',
json,
($checkedConvert) {
final val = CreateUserRequest(
name: $checkedConvert('name', (v) => v as String),
);
return val;
},
);
Map<String, dynamic> _$CreateUserRequestToJson(CreateUserRequest instance) =>
<String, dynamic>{
'name': instance.name,
};
@@ -7,4 +7,5 @@ export 'create_patch/create_patch.dart';
export 'create_payment_link/create_payment_link.dart';
export 'create_release/create_release.dart';
export 'create_release_artifact/create_release_artifact.dart';
export 'create_user/create_user.dart';
export 'promote_patch/promote_patch.dart';
@@ -12,6 +12,7 @@ class User {
required this.id,
required this.email,
this.hasActiveSubscription = false,
this.displayName,
});
/// Converts a Map<String, dynamic> to a [User]
@@ -26,6 +27,9 @@ class User {
/// The user's email address, as provided by the user during signup.
final String email;
/// The user's name, as provided by the user during signup.
final String? displayName;
/// Whether the user is currently a paying customer.
final bool hasActiveSubscription;
}
@@ -17,14 +17,19 @@ User _$UserFromJson(Map<String, dynamic> json) => $checkedCreate(
email: $checkedConvert('email', (v) => v as String),
hasActiveSubscription: $checkedConvert(
'has_active_subscription', (v) => v as bool? ?? false),
displayName: $checkedConvert('display_name', (v) => v as String?),
);
return val;
},
fieldKeyMap: const {'hasActiveSubscription': 'has_active_subscription'},
fieldKeyMap: const {
'hasActiveSubscription': 'has_active_subscription',
'displayName': 'display_name'
},
);
Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'id': instance.id,
'email': instance.email,
'display_name': instance.displayName,
'has_active_subscription': instance.hasActiveSubscription,
};
@@ -0,0 +1,14 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';
void main() {
group(CreateUserRequest, () {
test('can be (de)serialized', () {
const request = CreateUserRequest(name: 'Joe Tester');
expect(
CreateUserRequest.fromJson(request.toJson()).toJson(),
equals(request.toJson()),
);
});
});
}