From 5b368667d396e274cba94cf5cc964d068f6712de Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 19 Apr 2023 10:54:00 -0400 Subject: [PATCH 1/2] chore(shorebird_code_push_protocol): add CreateUserRequest message --- .../src/messages/create_user/create_user.dart | 1 + .../create_user/create_user_request.dart | 27 +++++++++++++++++++ .../create_user/create_user_request.g.dart | 26 ++++++++++++++++++ .../get_current_user/get_current_user.dart | 1 + .../lib/src/messages/messages.dart | 1 + .../lib/src/models/user.dart | 4 +++ .../lib/src/models/user.g.dart | 7 ++++- .../create_user/create_user_request_test.dart | 14 ++++++++++ 8 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.g.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart create mode 100644 packages/shorebird_code_push_protocol/test/src/messages/create_user/create_user_request_test.dart diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user.dart new file mode 100644 index 000000000..ab2dfd19e --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user.dart @@ -0,0 +1 @@ +export 'create_user_request.dart'; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.dart new file mode 100644 index 000000000..f9d0db5c1 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/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; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.g.dart b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.g.dart new file mode 100644 index 000000000..0d47612bb --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/create_user/create_user_request.g.dart @@ -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 json) => + $checkedCreate( + 'CreateUserRequest', + json, + ($checkedConvert) { + final val = CreateUserRequest( + name: $checkedConvert('name', (v) => v as String), + ); + return val; + }, + ); + +Map _$CreateUserRequestToJson(CreateUserRequest instance) => + { + 'name': instance.name, + }; diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart b/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart @@ -0,0 +1 @@ + diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart b/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart index 45fa22fe7..dbc0aa6d2 100644 --- a/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart +++ b/packages/shorebird_code_push_protocol/lib/src/messages/messages.dart @@ -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'; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/user.dart b/packages/shorebird_code_push_protocol/lib/src/models/user.dart index bd3afa807..1fb290348 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/user.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/user.dart @@ -12,6 +12,7 @@ class User { required this.id, required this.email, this.hasActiveSubscription = false, + this.displayName, }); /// Converts a Map 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; } diff --git a/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart index c997396a5..f87781dae 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/user.g.dart @@ -17,14 +17,19 @@ User _$UserFromJson(Map 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 _$UserToJson(User instance) => { 'id': instance.id, 'email': instance.email, + 'display_name': instance.displayName, 'has_active_subscription': instance.hasActiveSubscription, }; diff --git a/packages/shorebird_code_push_protocol/test/src/messages/create_user/create_user_request_test.dart b/packages/shorebird_code_push_protocol/test/src/messages/create_user/create_user_request_test.dart new file mode 100644 index 000000000..c4453c368 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/messages/create_user/create_user_request_test.dart @@ -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()), + ); + }); + }); +} From 23f337847f8d93f2f6a40eb21efa52bd2146d2ec Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Wed, 19 Apr 2023 10:57:48 -0400 Subject: [PATCH 2/2] Remove unused file --- .../lib/src/messages/get_current_user/get_current_user.dart | 1 - 1 file changed, 1 deletion(-) delete mode 100644 packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart diff --git a/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart b/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart deleted file mode 100644 index 8b1378917..000000000 --- a/packages/shorebird_code_push_protocol/lib/src/messages/get_current_user/get_current_user.dart +++ /dev/null @@ -1 +0,0 @@ -