Skip to content

Commit

Permalink
add ability to create an order file, add copyWith, optimize json writing
Browse files Browse the repository at this point in the history
  • Loading branch information
ueman committed Oct 13, 2024
1 parent 9b90ebc commit 4fd648b
Show file tree
Hide file tree
Showing 29 changed files with 779 additions and 195 deletions.
23 changes: 22 additions & 1 deletion passkit/lib/src/order/order_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
part 'order_address.g.dart';

/// The physical address for an order.
@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderAddress {
OrderAddress({
required this.addressLines,
Expand Down Expand Up @@ -51,4 +51,25 @@ class OrderAddress {
/// Additional information associated with the location, such as a district or neighborhood.
@JsonKey(name: 'subLocality')
final String? subLocality;

OrderAddress copyWith({
List<String>? addressLines,
String? administrativeArea,
String? countryCode,
String? locality,
String? postalCode,
String? subAdministrativeArea,
String? subLocality,
}) {
return OrderAddress(
addressLines: addressLines ?? this.addressLines,
administrativeArea: administrativeArea ?? this.administrativeArea,
countryCode: countryCode ?? this.countryCode,
locality: locality ?? this.locality,
postalCode: postalCode ?? this.postalCode,
subAdministrativeArea:
subAdministrativeArea ?? this.subAdministrativeArea,
subLocality: subLocality ?? this.subLocality,
);
}
}
28 changes: 18 additions & 10 deletions passkit/lib/src/order/order_address.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion passkit/lib/src/order/order_application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
part 'order_application.g.dart';

/// The details of an app in the App Store.
@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderApplication {
OrderApplication({
required this.customProductPageIdentifier,
Expand All @@ -29,4 +29,17 @@ class OrderApplication {
/// (Required) The ADAM ID (store identifier) of the application.
@JsonKey(name: 'storeIdentifier')
final num storeIdentifier;

OrderApplication copyWith({
String? customProductPageIdentifier,
String? launchURL,
num? storeIdentifier,
}) {
return OrderApplication(
customProductPageIdentifier:
customProductPageIdentifier ?? this.customProductPageIdentifier,
launchURL: launchURL ?? this.launchURL,
storeIdentifier: storeIdentifier ?? this.storeIdentifier,
);
}
}
21 changes: 15 additions & 6 deletions passkit/lib/src/order/order_application.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion passkit/lib/src/order/order_barcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
part 'order_barcode.g.dart';

/// Information about a pass’s barcode.
@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderBarcode {
OrderBarcode({
this.altText,
Expand Down Expand Up @@ -37,6 +37,20 @@ class OrderBarcode {
/// iso-8859-1, but you may specify an alternative encoding if required.
@JsonKey(name: 'messageEncoding')
final String messageEncoding;

OrderBarcode copyWith({
String? altText,
OrderBarcodeType? format,
String? message,
String? messageEncoding,
}) {
return OrderBarcode(
altText: altText ?? this.altText,
format: format ?? this.format,
message: message ?? this.message,
messageEncoding: messageEncoding ?? this.messageEncoding,
);
}
}

enum OrderBarcodeType {
Expand Down
22 changes: 15 additions & 7 deletions passkit/lib/src/order/order_barcode.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion passkit/lib/src/order/order_customer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
part 'order_customer.g.dart';

/// The details of the order’s customer.
@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderCustomer {
OrderCustomer({
required this.emailAddress,
Expand Down Expand Up @@ -39,4 +39,20 @@ class OrderCustomer {
/// The customer’s phone number.
@JsonKey(name: 'phoneNumber')
final String phoneNumber;

OrderCustomer copyWith({
String? emailAddress,
String? familyName,
String? givenName,
String? organizationName,
String? phoneNumber,
}) {
return OrderCustomer(
emailAddress: emailAddress ?? this.emailAddress,
familyName: familyName ?? this.familyName,
givenName: givenName ?? this.givenName,
organizationName: organizationName ?? this.organizationName,
phoneNumber: phoneNumber ?? this.phoneNumber,
);
}
}
62 changes: 59 additions & 3 deletions passkit/lib/src/order/order_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class OrderData {
required this.orderType,
required this.orderTypeIdentifier,
required this.status,
required this.schemaVersion,
this.schemaVersion = 1,
required this.updatedAt,
required this.associatedApplications,
required this.associatedApplicationIdentifiers,
required this.authenticationToken,
required this.barcode,
required this.changeNotifications,
this.changeNotifications = OrderChangeNotification.enabled,
required this.customer,
required this.fulfillments,
required this.lineItems,
Expand Down Expand Up @@ -109,7 +109,7 @@ class OrderData {
/// A property that describes whether the device notifies the user about
/// relevant changes to the order. The default is enabled.
@JsonKey(name: 'changeNotifications')
final OrderChangeNotification? changeNotifications;
final OrderChangeNotification changeNotifications;

/// The customer for this order.
@JsonKey(name: 'customer')
Expand Down Expand Up @@ -154,6 +154,62 @@ class OrderData {
/// The URL of your web service. This must begin with `HTTPS://`.
@JsonKey(name: 'webServiceURL')
final Uri? webServiceURL;

OrderData copyWith({
DateTime? createdAt,
OrderMerchant? merchant,
String? orderIdentifier,
Uri? orderManagementURL,
String? orderType,
String? orderTypeIdentifier,
OrderStatus? status,
num? schemaVersion,
DateTime? updatedAt,
List<OrderApplication>? associatedApplications,
List<String>? associatedApplicationIdentifiers,
String? authenticationToken,
OrderBarcode? barcode,
OrderChangeNotification? changeNotifications,
OrderCustomer? customer,
List<Object>? fulfillments,
List<OrderLineItem>? lineItems,
String? orderNumber,
OrderProvider? orderProvider,
OrderPayment? payment,
OrderReturnInfo? returnInfo,
List<OrderReturn>? returns,
String? statusDescription,
Uri? webServiceURL,
}) {
return OrderData(
createdAt: createdAt ?? this.createdAt,
merchant: merchant ?? this.merchant,
orderIdentifier: orderIdentifier ?? this.orderIdentifier,
orderManagementURL: orderManagementURL ?? this.orderManagementURL,
orderType: orderType ?? this.orderType,
orderTypeIdentifier: orderTypeIdentifier ?? this.orderTypeIdentifier,
status: status ?? this.status,
schemaVersion: schemaVersion ?? this.schemaVersion,
updatedAt: updatedAt ?? this.updatedAt,
associatedApplications:
associatedApplications ?? this.associatedApplications,
associatedApplicationIdentifiers: associatedApplicationIdentifiers ??
this.associatedApplicationIdentifiers,
authenticationToken: authenticationToken ?? this.authenticationToken,
barcode: barcode ?? this.barcode,
changeNotifications: changeNotifications ?? this.changeNotifications,
customer: customer ?? this.customer,
fulfillments: fulfillments ?? this.fulfillments,
lineItems: lineItems ?? this.lineItems,
orderNumber: orderNumber ?? this.orderNumber,
orderProvider: orderProvider ?? this.orderProvider,
payment: payment ?? this.payment,
returnInfo: returnInfo ?? this.returnInfo,
returns: returns ?? this.returns,
statusDescription: statusDescription ?? this.statusDescription,
webServiceURL: webServiceURL ?? this.webServiceURL,
);
}
}

List<Object>? _fulfillmentsFromJson(List<dynamic>? fulfillments) {
Expand Down
7 changes: 4 additions & 3 deletions passkit/lib/src/order/order_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions passkit/lib/src/order/order_line_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:json_annotation/json_annotation.dart';

part 'order_line_item.g.dart';

@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderLineItem {
OrderLineItem({
required this.image,
Expand Down Expand Up @@ -49,9 +49,29 @@ class OrderLineItem {
/// A merchant-specific unique product identifier.
@JsonKey(name: 'sku')
final String? sku;

OrderLineItem copyWith({
String? image,
OrderCurrencyAmount? price,
num? quantity,
String? subtitle,
String? title,
String? gtin,
String? sku,
}) {
return OrderLineItem(
image: image ?? this.image,
price: price ?? this.price,
quantity: quantity ?? this.quantity,
subtitle: subtitle ?? this.subtitle,
title: title ?? this.title,
gtin: gtin ?? this.gtin,
sku: sku ?? this.sku,
);
}
}

@JsonSerializable()
@JsonSerializable(includeIfNull: false)
class OrderCurrencyAmount {
OrderCurrencyAmount({required this.amount, required this.currency});

Expand All @@ -71,4 +91,14 @@ class OrderCurrencyAmount {
/// Maximum Length: 3
@JsonKey(name: 'currency')
final String currency;

OrderCurrencyAmount copyWith({
double? amount,
String? currency,
}) {
return OrderCurrencyAmount(
amount: amount ?? this.amount,
currency: currency ?? this.currency,
);
}
}
Loading

0 comments on commit 4fd648b

Please sign in to comment.