-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
libs/TrybeSDK/Api/Shop/Basket/BasketOperations.Items.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
// This work is licensed under the terms of the MIT license. | ||
// For a copy, see <https://opensource.org/licenses/MIT>. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
using TrybeSDK.Primitives; | ||
|
||
namespace TrybeSDK.Api; | ||
|
||
partial interface IBasketOperations | ||
{ | ||
/// <summary> | ||
/// Adds an item to the basket. | ||
/// HTTP POST /shop/basket/{basketId}/items | ||
/// </summary> | ||
/// <param name="basketId">The ID of the basket.</param> | ||
/// <param name="request">The request representing the add operation.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>The updated basket instance.</returns> | ||
Task<TrybeResponse<Basket>> AddBasketItemAsync( | ||
string basketId, | ||
AddBasketItemRequest request, | ||
CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Deletes an item to the basket. | ||
/// HTTP DELETE /shop/basket/{basketId}/items/{basketItemId} | ||
/// </summary> | ||
/// <param name="basketId">The ID of the basket.</param> | ||
/// <param name="basketItemId">The ID of the basket item.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>The updated basket instance.</returns> | ||
Task<TrybeResponse<Basket>> DeleteBasketItemAsync( | ||
string basketId, | ||
string basketItemId, | ||
CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Updates an item to the basket. | ||
/// HTTP PUT /shop/basket/{basketId}/items/{basketItemId} | ||
/// </summary> | ||
/// <param name="basketId">The ID of the basket.</param> | ||
/// <param name="basketItemId">The ID of the basket item.</param> | ||
/// <param name="request">The request representing the update operation.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>The updated basket instance.</returns> | ||
Task<TrybeResponse<Basket>> UpdateBasketItemAsync( | ||
string basketId, | ||
string basketItemId, | ||
UpdateBasketItemRequest request, | ||
CancellationToken cancellationToken = default); | ||
} | ||
|
||
partial class BasketOperations | ||
{ | ||
public async Task<TrybeResponse<Basket>> AddBasketItemAsync( | ||
string basketId, | ||
AddBasketItemRequest itemRequest, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Ensure.IsNotNullOrEmpty(basketId, nameof(basketId)); | ||
Ensure.IsNotNull(itemRequest, nameof(itemRequest)); | ||
|
||
var request = new TrybeRequest<AddBasketItemRequest>(HttpMethod.Post, path + $"/{basketId}/items", itemRequest); | ||
|
||
return await client.FetchAsync<AddBasketItemRequest, Basket>(request, cancellationToken); | ||
} | ||
|
||
public async Task<TrybeResponse<Basket>> DeleteBasketItemAsync( | ||
string basketId, | ||
string basketItemId, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Ensure.IsNotNullOrEmpty(basketId, nameof(basketId)); | ||
Ensure.IsNotNullOrEmpty(basketItemId, nameof(basketItemId)); | ||
|
||
var request = new TrybeRequest(HttpMethod.Delete, path + $"/{basketId}/items/{basketItemId}"); | ||
|
||
return await client.FetchAsync<Basket>(request, cancellationToken); | ||
} | ||
|
||
public async Task<TrybeResponse<Basket>> UpdateBasketItemAsync( | ||
string basketId, | ||
string basketItemId, | ||
UpdateBasketItemRequest itemRequest, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Ensure.IsNotNullOrEmpty(basketId, nameof(basketId)); | ||
Ensure.IsNotNullOrEmpty(basketItemId, nameof(basketItemId)); | ||
Ensure.IsNotNull(itemRequest, nameof(itemRequest)); | ||
|
||
var request = new TrybeRequest<UpdateBasketItemRequest>(HttpMethod.Put, path + $"/{basketId}/items/{basketItemId}", itemRequest); | ||
|
||
return await client.FetchAsync<UpdateBasketItemRequest, Basket>(request, cancellationToken); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents a request to add a new basket item. | ||
/// </summary> | ||
public class AddBasketItemRequest | ||
{ | ||
/// <summary> | ||
/// The date selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("date")] | ||
public DateTime? Date { get; set; } | ||
|
||
/// <summary> | ||
/// The duration selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("duration")] | ||
public int? Duration { get; set; } | ||
|
||
/// <summary> | ||
/// The set of guests associated with this offering. | ||
/// </summary> | ||
[JsonPropertyName("guests")] | ||
public GuestList? Guests { get; set; } | ||
|
||
/// <summary> | ||
/// The set of custom item configuration settings. | ||
/// </summary> | ||
[JsonPropertyName("item_configuration")] | ||
public ObjectDictionary? ItemConfiguration { get; set; } | ||
|
||
/// <summary> | ||
/// The ID of the offering. | ||
/// </summary> | ||
[JsonPropertyName("offering_id")] | ||
public required string OfferingId { get; init; } | ||
|
||
/// <summary> | ||
/// The type of item being added. | ||
/// </summary> | ||
[JsonPropertyName("offering_type")] | ||
public required string OfferingType { get; init; } | ||
|
||
/// <summary> | ||
/// The overriden price, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("price")] | ||
public int? Price { get; set; } | ||
|
||
/// <summary> | ||
/// The quantity required of the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("quantity")] | ||
public int? Quantity { get; set; } | ||
|
||
/// <summary> | ||
/// The time selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("time")] | ||
public TimeSpan? Time { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a request to add a new basket item. | ||
/// </summary> | ||
public class UpdateBasketItemRequest | ||
{ | ||
/// <summary> | ||
/// The date selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("date")] | ||
public DateTime? Date { get; set; } | ||
|
||
/// <summary> | ||
/// The duration selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("duration")] | ||
public int? Duration { get; set; } | ||
|
||
/// <summary> | ||
/// The set of guests associated with this offering. | ||
/// </summary> | ||
[JsonPropertyName("guests")] | ||
public GuestList? Guests { get; set; } | ||
|
||
/// <summary> | ||
/// The set of custom item configuration settings. | ||
/// </summary> | ||
[JsonPropertyName("item_configuration")] | ||
public ObjectDictionary? ItemConfiguration { get; set; } | ||
|
||
/// <summary> | ||
/// The overriden price, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("price")] | ||
public int? Price { get; set; } | ||
|
||
/// <summary> | ||
/// The quantity required of the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("quantity")] | ||
public int? Quantity { get; set; } | ||
|
||
/// <summary> | ||
/// The time selected for the offering, if applicable. | ||
/// </summary> | ||
[JsonPropertyName("time")] | ||
public TimeSpan? Time { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This work is licensed under the terms of the MIT license. | ||
// For a copy, see <https://opensource.org/licenses/MIT>. | ||
|
||
namespace TrybeSDK.Api; | ||
|
||
partial interface IShopOperations | ||
{ | ||
/// <summary> | ||
/// Gets the /shop/basket operations. | ||
/// </summary> | ||
IBasketOperations Baskets { get; } | ||
} | ||
|
||
partial class ShopOperations | ||
{ | ||
Lazy<IBasketOperations> _baskets; | ||
public IBasketOperations Baskets => (_baskets ??= client.Defer<IBasketOperations>( | ||
c => new BasketOperations(path + "/basket", c))).Value; | ||
} | ||
|
||
/// <summary> | ||
/// Provides operations for operating on the /shop/basket endpoint. | ||
/// </summary> | ||
public partial interface IBasketOperations | ||
{ | ||
/// <summary> | ||
/// Gets the basket with the given ID. | ||
/// HTTP GET /shop/basket/{basketId} | ||
/// </summary> | ||
/// <param name="basketId">The basket ID.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>The basket instance.</returns> | ||
Task<TrybeResponse<Basket>> GetBasketAsync( | ||
string basketId, | ||
CancellationToken cancellationToken = default); | ||
} | ||
|
||
public partial class BasketOperations(PathString path, ApiClient client): IBasketOperations | ||
{ | ||
public async Task<TrybeResponse<Basket>> GetBasketAsync( | ||
string basketId, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Ensure.IsNotNullOrEmpty(basketId, nameof(basketId)); | ||
|
||
var request = new TrybeRequest(HttpMethod.Get, path + $"/{basketId}"); | ||
|
||
return await client.FetchAsync<Basket>(request, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters