diff --git a/AITSYS.Vimeo.Ott/Clients/VimeoOttApiClient.cs b/AITSYS.Vimeo.Ott/Clients/VimeoOttApiClient.cs index 5b24c51..a242645 100644 --- a/AITSYS.Vimeo.Ott/Clients/VimeoOttApiClient.cs +++ b/AITSYS.Vimeo.Ott/Clients/VimeoOttApiClient.cs @@ -1,5 +1,7 @@ // Copyright 2025 Aiko IT Systems. See https://github.com/Aiko-IT-Systems/AITSYS.Vimeo.OTT/blob/main/LICENSE.md for the license. +using System.Net; + using AITSYS.Vimeo.Ott.Entities.Customers; using AITSYS.Vimeo.Ott.Entities.EmbeddedData; using AITSYS.Vimeo.Ott.Entities.Pagination; @@ -66,7 +68,7 @@ internal void CanNotAccessEndpointWithCustomerAuthedClient() /// The page number of the paginated result. /// The page size of the paginated result. /// A paginated result. - internal async Task> ListCustomersAsync(string? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50) + internal async Task> ListCustomersAsync(int? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50) { this.CanNotAccessEndpointWithCustomerAuthedClient(); var route = $"{Endpoints.CUSTOMERS}"; @@ -102,7 +104,7 @@ internal async Task> ListCustomersAsync( /// The id of the customer being retrieved. /// The id of a product. /// The requested customer. - internal async Task> RetrieveCustomerAsync(int customerId, int? productId = null) + internal async Task?> RetrieveCustomerAsync(int customerId, int? productId = null) { var route = $"{Endpoints.CUSTOMERS}/:customer_id"; var bucket = this.RestClient.GetBucket(RestRequestMethod.GET, route, new @@ -113,6 +115,9 @@ internal async Task> RetrieveCustome if (productId is not null) url = url.AddParameter("product", $"{Utilities.GetApiBaseUri()}{Endpoints.PRODUCTS}/{productId}"); var res = await this.DoRequestAsync(bucket, url, RestRequestMethod.GET, route).ConfigureAwait(false); + if (res.ResponseCode == HttpStatusCode.NotFound) + return null; + var obj = JsonConvert.DeserializeObject>(res.Response)!; obj.Client = this.Client; foreach (var product in obj.Embedded.Products) @@ -203,7 +208,7 @@ internal async Task> ListProductsAsync(st /// /// The id of the product being retrieved. /// The requested product. - internal async Task> RetrieveProductAsync(int productId) + internal async Task?> RetrieveProductAsync(int productId) { var route = $"{Endpoints.PRODUCTS}/:product_id"; var bucket = this.RestClient.GetBucket(RestRequestMethod.GET, route, new @@ -212,6 +217,9 @@ internal async Task> RetrieveProductAsync(int }, out var path); var url = Utilities.GetApiUriFor(path); var res = await this.DoRequestAsync(bucket, url, RestRequestMethod.GET, route).ConfigureAwait(false); + if (res.ResponseCode == HttpStatusCode.NotFound) + return null; + var obj = JsonConvert.DeserializeObject>(res.Response)!; obj.Client = this.Client; return obj; diff --git a/AITSYS.Vimeo.Ott/Clients/VimeoOttClient.cs b/AITSYS.Vimeo.Ott/Clients/VimeoOttClient.cs index 71fd0d1..86486f2 100644 --- a/AITSYS.Vimeo.Ott/Clients/VimeoOttClient.cs +++ b/AITSYS.Vimeo.Ott/Clients/VimeoOttClient.cs @@ -81,11 +81,11 @@ public VimeoOttClient(VimeoOttConfiguration configuration) internal VimeoOttApiClient ApiClient { get; } /// - public async Task> ListCustomersAsync(string? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50) + public async Task> ListCustomersAsync(int? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50) => await this.ApiClient.ListCustomersAsync(productId, email, query, sort, status, page, perPage); /// - public async Task> RetrieveCustomerAsync(int customerId, int? productId = null) + public async Task?> RetrieveCustomerAsync(int customerId, int? productId = null) => await this.ApiClient.RetrieveCustomerAsync(customerId, productId); /// @@ -93,6 +93,6 @@ public async Task> ListProductsAsync(stri => await this.ApiClient.ListProductsAsync(query, active, sort, page, perPage); /// - public async Task> RetrieveProductAsync(int productId) + public async Task?> RetrieveProductAsync(int productId) => await this.ApiClient.RetrieveProductAsync(productId); } diff --git a/AITSYS.Vimeo.Ott/Entities/EmbeddedData/OttWebhookEmbeddedData.cs b/AITSYS.Vimeo.Ott/Entities/EmbeddedData/OttWebhookEmbeddedData.cs index b6d0fd2..d1e5da1 100644 --- a/AITSYS.Vimeo.Ott/Entities/EmbeddedData/OttWebhookEmbeddedData.cs +++ b/AITSYS.Vimeo.Ott/Entities/EmbeddedData/OttWebhookEmbeddedData.cs @@ -10,5 +10,5 @@ namespace AITSYS.Vimeo.Ott.Entities.EmbeddedData; public sealed class OttWebhookEmbeddedData : IOttEmbedded { [JsonProperty("customer", NullValueHandling = NullValueHandling.Ignore)] - public OttCustomer Customer { get; internal set; } = []; + public OttCustomer Customer { get; internal set; } }