chore: use int as Money transport type, expose money2 dependency from shorebird_code_push_protocol (#827)

This commit is contained in:
Bryan Oltman
2023-07-11 15:02:27 -04:00
committed by GitHub
parent 1b60e46d84
commit eb545110f2
6 changed files with 10 additions and 9 deletions
-1
View File
@@ -23,7 +23,6 @@ dependencies:
json_annotation: ^4.8.0
mason_logger: ^0.2.4
meta: ^1.9.0
money2: ^3.4.1
path: ^1.8.3
platform: ^3.1.0
propertylistserialization: ^1.3.0
@@ -10,7 +10,6 @@ environment:
dependencies:
http: ^1.0.0
money2: ^3.4.1
shorebird_code_push_protocol:
path: ../shorebird_code_push_protocol
@@ -1,6 +1,7 @@
/// The Shorebird CodePush Protocol
library shorebird_code_push_protocol;
export 'package:money2/money2.dart' show Currency, Money;
export 'src/converters/converters.dart';
export 'src/messages/messages.dart';
export 'src/models/models.dart';
@@ -5,15 +5,17 @@ import 'package:money2/money2.dart';
Currency get usd => Currency.create('USD', 2);
/// {@template money_converter}
/// Converts between [Money] and [String].
/// Converts between [Money] and [int].
/// {@endtemplate}
class MoneyConverter implements JsonConverter<Money, String> {
// TODO(bryanoltman): change this to use String as the transport type the next
// time we make a breaking change to the API.
class MoneyConverter implements JsonConverter<Money, int> {
/// {@macro money_converter}
const MoneyConverter();
@override
Money fromJson(String cents) => Money.parseWithCurrency(cents, usd);
Money fromJson(int cents) => Money.fromIntWithCurrency(cents, usd);
@override
String toJson(Money money) => money.minorUnits.toString();
int toJson(Money money) => money.minorUnits.toInt();
}
@@ -26,7 +26,7 @@ GetUsageResponse _$GetUsageResponseFromJson(Map<String, dynamic> json) =>
currentPeriodEnd: $checkedConvert(
'current_period_end', (v) => DateTime.parse(v as String)),
currentPeriodCost: $checkedConvert('current_period_cost',
(v) => const MoneyConverter().fromJson(v as String)),
(v) => const MoneyConverter().fromJson(v as int)),
patchInstallLimit:
$checkedConvert('patch_install_limit', (v) => v as int?),
);
@@ -15,8 +15,8 @@ ShorebirdPlan _$ShorebirdPlanFromJson(Map<String, dynamic> json) =>
($checkedConvert) {
final val = ShorebirdPlan(
name: $checkedConvert('name', (v) => v as String),
monthlyCost: $checkedConvert('monthly_cost',
(v) => const MoneyConverter().fromJson(v as String)),
monthlyCost: $checkedConvert(
'monthly_cost', (v) => const MoneyConverter().fromJson(v as int)),
patchInstallLimit:
$checkedConvert('patch_install_limit', (v) => v as int?),
maxTeamSize: $checkedConvert('max_team_size', (v) => v as int?),