From 7e6384a4f118ccb302f3fb6f6ce7ac84bd2bca17 Mon Sep 17 00:00:00 2001 From: Matthew Abbott Date: Thu, 15 Feb 2024 15:30:45 +0000 Subject: [PATCH] feat: Add JSON serialiser methods for all models --- apps/TrybeSDK.ConsoleSample/Program.cs | 29 +++++++++----- libs/TrybeSDK/Api/Shop/Basket/Basket.cs | 2 +- .../Api/Shop/Basket/BasketCouponSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/BasketItem.cs | 2 +- .../Api/Shop/Basket/BasketItemOptionBudget.cs | 2 +- .../Api/Shop/Basket/BasketItemValidity.cs | 4 +- .../Api/Shop/Basket/BasketPackageItem.cs | 2 +- .../Api/Shop/Basket/BasketPromoCodeSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/BasketTotals.cs | 2 +- .../Api/Shop/Basket/BasketVoucherSummary.cs | 2 +- .../Api/Shop/Basket/BookableAreaSummary.cs | 2 +- .../Api/Shop/Basket/BookingSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/Customer.cs | 2 +- .../Api/Shop/Basket/EquipmentSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/Guest.cs | 2 +- .../Api/Shop/Basket/OfferingSummary.cs | 2 +- .../Api/Shop/Basket/PaymentSummary.cs | 5 ++- .../Api/Shop/Basket/PractitionerSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/RoomSummary.cs | 2 +- libs/TrybeSDK/Api/Shop/Basket/ShopDiscount.cs | 2 +- .../Offerings/OfferingDateAvailability.cs | 2 +- .../Shop/Offerings/OfferingEmailOptions.cs | 2 +- .../Api/Shop/Offerings/OfferingIdentifier.cs | 2 +- .../Offerings/OfferingRevenueAllocation.cs | 2 +- .../Api/Shop/Offerings/ShopOffering.cs | 6 ++- .../Shop/Offerings/ShopOfferingCategories.cs | 2 +- .../Api/Shop/Orders/BookingOrderItem.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/Order.cs | 2 +- .../TrybeSDK/Api/Shop/Orders/OrderDiscount.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/OrderLabel.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/OrderNote.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/OrderPayment.cs | 2 +- .../Api/Shop/Orders/OrderPaymentTotals.cs | 2 +- .../Api/Shop/Orders/OrderServiceCharge.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/OrderTotals.cs | 2 +- .../Api/Shop/Orders/PackageOrderItem.cs | 2 +- .../Api/Shop/Orders/PurchaseOrderItem.cs | 14 +++---- libs/TrybeSDK/Api/Shop/Orders/Refund.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/SalesChannel.cs | 2 +- libs/TrybeSDK/Api/Shop/Orders/Visit.cs | 6 +-- .../Api/Shop/Packages/AppointmentTypeMeta.cs | 4 +- .../Api/Shop/Packages/AvailabilityRule.cs | 2 +- .../Shop/Packages/MembershipBookingWindow.cs | 2 +- libs/TrybeSDK/Api/Shop/Packages/Package.cs | 2 +- .../Packages/PackageChoiceStartTimeRule.cs | 2 +- .../Shop/Packages/PackageItemChoiceOption.cs | 2 +- .../Api/Shop/Packages/PackageItemChoices.cs | 2 +- .../Api/Shop/Packages/PackagePriceRule.cs | 2 +- libs/TrybeSDK/Api/Sites/Site.cs | 2 +- .../Frontend/BookingFrame/BookingFrame.cs | 2 +- libs/TrybeSDK/Model.cs | 39 +++++++++++++++++++ 51 files changed, 120 insertions(+), 73 deletions(-) create mode 100644 libs/TrybeSDK/Model.cs diff --git a/apps/TrybeSDK.ConsoleSample/Program.cs b/apps/TrybeSDK.ConsoleSample/Program.cs index 28f37df..2f4d828 100644 --- a/apps/TrybeSDK.ConsoleSample/Program.cs +++ b/apps/TrybeSDK.ConsoleSample/Program.cs @@ -13,16 +13,25 @@ var http = CreateHttpClient(); var api = new TrybeApiClient(http, settings); -//var response = await api.Shop.Packages.GetPackageAsync("6372bc492ea8f57d2508fe82"); -var response = await api.Shop.ItemAvailability.GetOfferingDates( - new GetOfferingDatesRequest - { - OfferingType = "package", - OfferingId = "6372bc492ea8f57d2508fe82", - DateFrom = new(2024, 04, 01), - DateTo = new(2024, 04, 30), - Quantity = 1 - }); +var response = await api.Shop.Packages.GetPackageAsync("6372bc492ea8f57d2508fe82"); +//var response = await api.Shop.ItemAvailability.GetOfferingDates( +// new GetOfferingDatesRequest +// { +// OfferingType = "package", +// OfferingId = "6372bc492ea8f57d2508fe82", +// DateFrom = new(2024, 04, 01), +// DateTo = new(2024, 04, 30), +// Quantity = 1 +// }); + +if (response.IsSuccess && response.HasData) +{ + var package = response.Data!; + + string packageJson = package.ToJsonString(); + + var package2 = package.FromJsonString(packageJson); +} Console.WriteLine(response); diff --git a/libs/TrybeSDK/Api/Shop/Basket/Basket.cs b/libs/TrybeSDK/Api/Shop/Basket/Basket.cs index 9557179..c4ccb44 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/Basket.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/Basket.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket object. /// -public class Basket +public class Basket : Model { /// /// The ID of the basket. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketCouponSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketCouponSummary.cs index 497a1c2..db43504 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketCouponSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketCouponSummary.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket coupon summary instance. /// -public class BasketCouponSummary +public class BasketCouponSummary : Model { /// /// The ID of the coupon. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketItem.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketItem.cs index 7ea280d..5615d98 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketItem.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketItem.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket item instance. /// -public class BasketItem +public class BasketItem : Model { /// /// A unique ID for the basket item diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketItemOptionBudget.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketItemOptionBudget.cs index f99f417..1f50b65 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketItemOptionBudget.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketItemOptionBudget.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket item option budget instance. /// -public class BasketItemOptionBudget +public class BasketItemOptionBudget : Model { /// /// The ID of the choice this option budget belongs to. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketItemValidity.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketItemValidity.cs index 7397788..2be9944 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketItemValidity.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketItemValidity.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket item validity instance. /// -public class BasketItemValidity +public class BasketItemValidity : Model { /// /// Whether the given basket item is valid. @@ -28,7 +28,7 @@ public class BasketItemValidity /// /// A basket item validity error instance. /// -public class BasketItemValidityErrors +public class BasketItemValidityErrors : Model { /// /// A friendly description of the error. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketPackageItem.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketPackageItem.cs index ec9d0dc..0b82b09 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketPackageItem.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketPackageItem.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A basket package item. /// -public class BasketPackageItem +public class BasketPackageItem : Model { /// /// A unique ID for the basket package item diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketPromoCodeSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketPromoCodeSummary.cs index 27bd451..1c3efee 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketPromoCodeSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketPromoCodeSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class BasketPromoCodeSummary +public class BasketPromoCodeSummary : Model { /// /// The ID of the applied promo code. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketTotals.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketTotals.cs index 3559916..b73ac01 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketTotals.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketTotals.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class BasketTotals +public class BasketTotals : Model { /// /// The total cost of the basket before tax. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BasketVoucherSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/BasketVoucherSummary.cs index 7f5c693..c5b8390 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BasketVoucherSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BasketVoucherSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class BasketVoucherSummary +public class BasketVoucherSummary : Model { /// /// The ID of the voucher. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BookableAreaSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/BookableAreaSummary.cs index 7a658f1..a5cd74f 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BookableAreaSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BookableAreaSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class BookableAreaSummary +public class BookableAreaSummary : Model { /// /// The ID of the area. diff --git a/libs/TrybeSDK/Api/Shop/Basket/BookingSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/BookingSummary.cs index 275730a..b7269fe 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/BookingSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/BookingSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class BookingSummary +public class BookingSummary : Model { /// /// Gets or Sets Id diff --git a/libs/TrybeSDK/Api/Shop/Basket/Customer.cs b/libs/TrybeSDK/Api/Shop/Basket/Customer.cs index b020261..3767653 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/Customer.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/Customer.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class Customer +public class Customer : Model { /// /// The ID of the customer. diff --git a/libs/TrybeSDK/Api/Shop/Basket/EquipmentSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/EquipmentSummary.cs index 8cad1f1..6c5bb52 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/EquipmentSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/EquipmentSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class EquipmentSummary +public class EquipmentSummary : Model { /// /// The ID of the equipment. diff --git a/libs/TrybeSDK/Api/Shop/Basket/Guest.cs b/libs/TrybeSDK/Api/Shop/Basket/Guest.cs index aab864f..72d0b40 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/Guest.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/Guest.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A guest instance. /// -public class Guest +public class Guest : Model { /// /// The ID of the guest. diff --git a/libs/TrybeSDK/Api/Shop/Basket/OfferingSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/OfferingSummary.cs index f5deb2d..3a31d5f 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/OfferingSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/OfferingSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OfferingSummary +public class OfferingSummary : Model { /// /// The ID of the offering. diff --git a/libs/TrybeSDK/Api/Shop/Basket/PaymentSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/PaymentSummary.cs index 76088d5..edd3448 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/PaymentSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/PaymentSummary.cs @@ -5,7 +5,10 @@ namespace TrybeSDK.Api; -public class PaymentSummary +public class PaymentSummary : PaymentSummary { } + +public class PaymentSummary : Model + where T : PaymentSummary { /// /// The ID of the item to be added. diff --git a/libs/TrybeSDK/Api/Shop/Basket/PractitionerSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/PractitionerSummary.cs index d8e3dbb..f46e64a 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/PractitionerSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/PractitionerSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class PractitionerSummary +public class PractitionerSummary : Model { /// /// The ID of the practitioner. diff --git a/libs/TrybeSDK/Api/Shop/Basket/RoomSummary.cs b/libs/TrybeSDK/Api/Shop/Basket/RoomSummary.cs index e8ef64d..f0160d2 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/RoomSummary.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/RoomSummary.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class RoomSummary +public class RoomSummary : Model { /// /// The ID of the room. diff --git a/libs/TrybeSDK/Api/Shop/Basket/ShopDiscount.cs b/libs/TrybeSDK/Api/Shop/Basket/ShopDiscount.cs index dd611f2..3a1d58c 100644 --- a/libs/TrybeSDK/Api/Shop/Basket/ShopDiscount.cs +++ b/libs/TrybeSDK/Api/Shop/Basket/ShopDiscount.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A shop discount instance. /// -public class ShopDiscount +public class ShopDiscount : Model { /// /// The ID of the discount. diff --git a/libs/TrybeSDK/Api/Shop/Offerings/OfferingDateAvailability.cs b/libs/TrybeSDK/Api/Shop/Offerings/OfferingDateAvailability.cs index 1bd4470..910e849 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/OfferingDateAvailability.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/OfferingDateAvailability.cs @@ -7,7 +7,7 @@ namespace TrybeSDK.Api; [DebuggerDisplay("{ToDebuggerString(),nq}")] -public class OfferingDateAvailability +public class OfferingDateAvailability : Model { /// /// The date availability is for. diff --git a/libs/TrybeSDK/Api/Shop/Offerings/OfferingEmailOptions.cs b/libs/TrybeSDK/Api/Shop/Offerings/OfferingEmailOptions.cs index 0fa639d..3c204a7 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/OfferingEmailOptions.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/OfferingEmailOptions.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OfferingEmailOptions +public class OfferingEmailOptions : Model { /// /// Enable to hide prices from customer emails, in cases where the customer didn't purchase the item directly. diff --git a/libs/TrybeSDK/Api/Shop/Offerings/OfferingIdentifier.cs b/libs/TrybeSDK/Api/Shop/Offerings/OfferingIdentifier.cs index 8b52658..616ea0c 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/OfferingIdentifier.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/OfferingIdentifier.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OfferingIdentifier +public class OfferingIdentifier : Model { /// /// The type of the offering. diff --git a/libs/TrybeSDK/Api/Shop/Offerings/OfferingRevenueAllocation.cs b/libs/TrybeSDK/Api/Shop/Offerings/OfferingRevenueAllocation.cs index ed915da..ffe683f 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/OfferingRevenueAllocation.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/OfferingRevenueAllocation.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OfferingRevenueAllocation +public class OfferingRevenueAllocation : Model { /// /// The identifier of the revenue centre. diff --git a/libs/TrybeSDK/Api/Shop/Offerings/ShopOffering.cs b/libs/TrybeSDK/Api/Shop/Offerings/ShopOffering.cs index cf8e0c2..a33ab3c 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/ShopOffering.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/ShopOffering.cs @@ -7,7 +7,11 @@ namespace TrybeSDK.Api; [DebuggerDisplay("{ToDebuggerString(),nq}")] -public class ShopOffering +public class ShopOffering : ShopOffering { } + +[DebuggerDisplay("{ToDebuggerString(),nq}")] +public class ShopOffering : Model + where T : ShopOffering { /// /// The ID of the offering diff --git a/libs/TrybeSDK/Api/Shop/Offerings/ShopOfferingCategories.cs b/libs/TrybeSDK/Api/Shop/Offerings/ShopOfferingCategories.cs index 4857cca..1acf50f 100644 --- a/libs/TrybeSDK/Api/Shop/Offerings/ShopOfferingCategories.cs +++ b/libs/TrybeSDK/Api/Shop/Offerings/ShopOfferingCategories.cs @@ -7,7 +7,7 @@ namespace TrybeSDK.Api; [DebuggerDisplay("{Name,nq} ({Id,nq})")] -public class ShopOfferingCategories +public class ShopOfferingCategories : Model { /// /// The ID of the category diff --git a/libs/TrybeSDK/Api/Shop/Orders/BookingOrderItem.cs b/libs/TrybeSDK/Api/Shop/Orders/BookingOrderItem.cs index 1d80d2f..647a74f 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/BookingOrderItem.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/BookingOrderItem.cs @@ -7,7 +7,7 @@ namespace TrybeSDK.Api; -public class BookingOrderItem +public class BookingOrderItem : Model { /// /// Gets or Sets Id diff --git a/libs/TrybeSDK/Api/Shop/Orders/Order.cs b/libs/TrybeSDK/Api/Shop/Orders/Order.cs index 9d2c457..74694bc 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/Order.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/Order.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class Order +public class Order : Model { /// /// The ID of the basket this order represents. diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderDiscount.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderDiscount.cs index 6d6c992..ea69e63 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderDiscount.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderDiscount.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderDiscount +public class OrderDiscount : Model { /// /// The ID of the order discount diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderLabel.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderLabel.cs index 2175f30..ea1b394 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderLabel.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderLabel.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderLabel +public class OrderLabel : Model { /// /// The ID of the label. diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderNote.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderNote.cs index 9afbe16..0ab1043 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderNote.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderNote.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderNote +public class OrderNote : Model { /// /// Gets or Sets Id diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderPayment.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderPayment.cs index 202dded..104c103 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderPayment.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderPayment.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderPayment : PaymentSummary +public class OrderPayment : PaymentSummary { /// /// The amount of the payment that may be refunded. diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderPaymentTotals.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderPaymentTotals.cs index 4383455..46b0828 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderPaymentTotals.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderPaymentTotals.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderPaymentTotals +public class OrderPaymentTotals : Model { /// /// The total of payments in a paid status. diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderServiceCharge.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderServiceCharge.cs index 9dc5933..dec9a66 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderServiceCharge.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderServiceCharge.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderServiceCharge +public class OrderServiceCharge : Model { /// /// The amount of the service charge, in minor units. diff --git a/libs/TrybeSDK/Api/Shop/Orders/OrderTotals.cs b/libs/TrybeSDK/Api/Shop/Orders/OrderTotals.cs index f4e3f1a..341a480 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/OrderTotals.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/OrderTotals.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class OrderTotals +public class OrderTotals : Model { /// /// The total cost of all items in the order. Item-level discounts are applied before this total is calculated. diff --git a/libs/TrybeSDK/Api/Shop/Orders/PackageOrderItem.cs b/libs/TrybeSDK/Api/Shop/Orders/PackageOrderItem.cs index 7309640..1eb6ba7 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/PackageOrderItem.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/PackageOrderItem.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class PackageOrderItem +public class PackageOrderItem : Model { /// /// Gets or Sets Id diff --git a/libs/TrybeSDK/Api/Shop/Orders/PurchaseOrderItem.cs b/libs/TrybeSDK/Api/Shop/Orders/PurchaseOrderItem.cs index 7c4424d..e045fe8 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/PurchaseOrderItem.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/PurchaseOrderItem.cs @@ -1,15 +1,11 @@ // This work is licensed under the terms of the MIT license. // For a copy, see . -using System; -using System.Collections.Generic; using System.Text.Json.Serialization; -using System.Text; -using System.Xml; namespace TrybeSDK.Api; -public class PurchaseOrderItem +public class PurchaseOrderItem : Model { /// /// Gets or Sets Id @@ -117,7 +113,7 @@ public class PurchaseOrderItem /// The date and time the booking was created. /// /// The date and time the booking was created. - + [JsonPropertyName("created_at")] public DateTime? CreatedAt { get; set; } @@ -125,21 +121,21 @@ public class PurchaseOrderItem /// The date and time the booking was last updated. /// /// The date and time the booking was last updated. - + [JsonPropertyName("updated_at")] public DateTime? UpdatedAt { get; set; } /// /// Gets or Sets ItemConfiguration /// - + [JsonPropertyName("item_configuration")] public ObjectDictionary? ItemConfiguration { get; set; } /// /// Gets or Sets PurchasableDetails /// - + [JsonPropertyName("purchasable_details")] public ObjectDictionary? PurchasableDetails { get; set; } diff --git a/libs/TrybeSDK/Api/Shop/Orders/Refund.cs b/libs/TrybeSDK/Api/Shop/Orders/Refund.cs index eb726af..2761c59 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/Refund.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/Refund.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class Refund +public class Refund : Model { /// /// The ID of the refund. diff --git a/libs/TrybeSDK/Api/Shop/Orders/SalesChannel.cs b/libs/TrybeSDK/Api/Shop/Orders/SalesChannel.cs index 24800cf..847ecf9 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/SalesChannel.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/SalesChannel.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class SalesChannel +public class SalesChannel : Model { /// /// The ID of the sales channel. diff --git a/libs/TrybeSDK/Api/Shop/Orders/Visit.cs b/libs/TrybeSDK/Api/Shop/Orders/Visit.cs index cc65ac8..aa089a8 100644 --- a/libs/TrybeSDK/Api/Shop/Orders/Visit.cs +++ b/libs/TrybeSDK/Api/Shop/Orders/Visit.cs @@ -1,15 +1,11 @@ // This work is licensed under the terms of the MIT license. // For a copy, see . -using System.Net.Http.Json; -using System.Runtime.Serialization; -using System.Text; using System.Text.Json.Serialization; -using System.Xml; namespace TrybeSDK.Api; -public class Visit +public class Visit : Model { /// /// The ID of the visit. diff --git a/libs/TrybeSDK/Api/Shop/Packages/AppointmentTypeMeta.cs b/libs/TrybeSDK/Api/Shop/Packages/AppointmentTypeMeta.cs index aa64b2e..5ff447e 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/AppointmentTypeMeta.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/AppointmentTypeMeta.cs @@ -5,14 +5,14 @@ namespace TrybeSDK.Api; -public class AppointmentTypeMeta +public class AppointmentTypeMeta : Model { /// /// The meta title of this offering. If not specified, it falls back to the name of the offering. /// /// The meta title of this offering. If not specified, it falls back to the name of the offering. [JsonPropertyName("title")] - public required string Title { get; set; } + public string? Title { get; set; } /// /// The meta description of this offering. If not specified, it falls back to the description of the offering. diff --git a/libs/TrybeSDK/Api/Shop/Packages/AvailabilityRule.cs b/libs/TrybeSDK/Api/Shop/Packages/AvailabilityRule.cs index 6792e88..0d401a2 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/AvailabilityRule.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/AvailabilityRule.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class AvailabilityRule +public class AvailabilityRule : Model { /// /// The ID of the availability rule. diff --git a/libs/TrybeSDK/Api/Shop/Packages/MembershipBookingWindow.cs b/libs/TrybeSDK/Api/Shop/Packages/MembershipBookingWindow.cs index d465ec4..803ecd0 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/MembershipBookingWindow.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/MembershipBookingWindow.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class MembershipBookingWindow +public class MembershipBookingWindow : Model { /// /// The ID of the membership type this booking window applies to. diff --git a/libs/TrybeSDK/Api/Shop/Packages/Package.cs b/libs/TrybeSDK/Api/Shop/Packages/Package.cs index 50a5eb2..e3bf783 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/Package.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/Package.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class Package : ShopOffering +public class Package : ShopOffering { /// /// A custom product code for the package. diff --git a/libs/TrybeSDK/Api/Shop/Packages/PackageChoiceStartTimeRule.cs b/libs/TrybeSDK/Api/Shop/Packages/PackageChoiceStartTimeRule.cs index 5ca0dea..c5b6c09 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/PackageChoiceStartTimeRule.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/PackageChoiceStartTimeRule.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class PackageChoiceStartTimeRule +public class PackageChoiceStartTimeRule : Model { /// /// The type of the rule. diff --git a/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoiceOption.cs b/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoiceOption.cs index 6334bc9..538e75f 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoiceOption.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoiceOption.cs @@ -7,7 +7,7 @@ namespace TrybeSDK.Api; [DebuggerDisplay("{Offering.ToDebuggerString(),nq}")] -public class PackageItemChoiceOption +public class PackageItemChoiceOption : Model { /// /// The ID of the item type. diff --git a/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoices.cs b/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoices.cs index 8454e6f..f01fac4 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoices.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/PackageItemChoices.cs @@ -7,7 +7,7 @@ namespace TrybeSDK.Api; [DebuggerDisplay("{Name,nq} ({Id,nq})")] -public class PackageItemChoice +public class PackageItemChoice : Model { /// /// The ID of this choice. diff --git a/libs/TrybeSDK/Api/Shop/Packages/PackagePriceRule.cs b/libs/TrybeSDK/Api/Shop/Packages/PackagePriceRule.cs index a68bf3c..19a41bf 100644 --- a/libs/TrybeSDK/Api/Shop/Packages/PackagePriceRule.cs +++ b/libs/TrybeSDK/Api/Shop/Packages/PackagePriceRule.cs @@ -5,7 +5,7 @@ namespace TrybeSDK.Api; -public class PackagePriceRule +public class PackagePriceRule : Model { /// /// The ID of the price rule. diff --git a/libs/TrybeSDK/Api/Sites/Site.cs b/libs/TrybeSDK/Api/Sites/Site.cs index 631be77..7796809 100644 --- a/libs/TrybeSDK/Api/Sites/Site.cs +++ b/libs/TrybeSDK/Api/Sites/Site.cs @@ -8,7 +8,7 @@ namespace TrybeSDK.Api; /// /// A site object. /// -public class Site +public class Site : Model { /// /// The date and time the site was created. diff --git a/libs/TrybeSDK/Frontend/BookingFrame/BookingFrame.cs b/libs/TrybeSDK/Frontend/BookingFrame/BookingFrame.cs index 6bb0cf5..c667810 100644 --- a/libs/TrybeSDK/Frontend/BookingFrame/BookingFrame.cs +++ b/libs/TrybeSDK/Frontend/BookingFrame/BookingFrame.cs @@ -11,7 +11,7 @@ namespace TrybeSDK.Frontend; /// /// A booking frame object. /// -public class BookingFrame +public class BookingFrame : Model { [JsonPropertyName("basket")] public Basket? Basket { get; set; } diff --git a/libs/TrybeSDK/Model.cs b/libs/TrybeSDK/Model.cs new file mode 100644 index 0000000..f5437f4 --- /dev/null +++ b/libs/TrybeSDK/Model.cs @@ -0,0 +1,39 @@ +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +using System.Text.Json; + +namespace TrybeSDK; + +/// +/// Provides a base implementation of a model that is convertible to JSON. +/// +/// The model type. +public abstract class Model + where T : Model +{ + /// + /// Converts the given JSON string to an instance of . + /// + /// The JSON string. + /// The model instance. + public T? FromJsonString(string json) + { + Ensure.IsNotNullOrEmpty(json, nameof(json)); + + var settings = JsonUtility.CreateDeserializerOptions(); + + return JsonSerializer.Deserialize(json, settings); + } + + /// + /// Converts the current instance to a JSON string. + /// + /// The JSON string. + public string ToJsonString() + { + var settings = JsonUtility.CreateSerializerOptions(); + + return JsonSerializer.Serialize((T)this, settings); + } +}