Skip to content

Replace JsonElement returns with typed response DTOs and tuple request inputs#11

Merged
stephanstapel merged 1 commit intomainfrom
codex/remove-createcatalogcartbasicasync-and-bulkbatchasync
Dec 30, 2025
Merged

Replace JsonElement returns with typed response DTOs and tuple request inputs#11
stephanstapel merged 1 commit intomainfrom
codex/remove-createcatalogcartbasicasync-and-bulkbatchasync

Conversation

@stephanstapel
Copy link
Owner

Motivation

  • Reduce reliance on unstructured JsonElement responses and provide typed DTOs for clearer deserialization and stronger typing.
  • Simplify request construction for batch and cart endpoints by accepting tuple-style inputs instead of requiring pre-serialized JSON payloads.
  • Improve code organization by placing each response DTO in its own file for maintainability.
  • Update sample/demo code to reflect the new signatures and typed responses.

Description

  • Replaced Task<JsonElement> return types with concrete DTOs such as CatalogBulkResponse, CatalogSearchResponse, OrderTaxSchemesResponse, UserDetailsResponse, and InvoiceTransactionsResponse, and added the corresponding response classes (one per file).
  • Changed BulkBatchAsync to accept IEnumerable<(string Endpoint, string RequestMethod, IEnumerable<Dictionary<string,string>> Parameters)> and CreateCatalogCartBasicAsync to accept IEnumerable<(string DesignId, int? ColorId, string Boid, int Quantity)>, with internal serialization of the payloads.
  • Updated IBrickOwlClient signatures and BrickOwlClient implementations to use the new DTO types and to call ExecuteGet<T>/ExecutePost<T> with the DTOs.
  • Updated demo projects (CatalogAdvancedDemo, InvoiceDemo, OrderManagementDemo, UserDemo) to construct tuple inputs and consume the new typed responses.

Testing

  • No automated tests were executed as part of this change.

Codex Task

Copilot AI review requested due to automatic review settings December 30, 2025 16:47
@stephanstapel stephanstapel merged commit 692f4d8 into main Dec 30, 2025
4 checks passed
@stephanstapel stephanstapel deleted the codex/remove-createcatalogcartbasicasync-and-bulkbatchasync branch December 30, 2025 16:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the BrickOwlSharp client library to replace unstructured JsonElement return types with strongly-typed response DTOs for improved type safety and developer experience. The PR also simplifies request construction for batch and cart endpoints by accepting tuple-style inputs instead of requiring pre-serialized JSON payloads.

  • Introduced 14 new response DTO classes (e.g., CatalogBulkResponse, UserDetailsResponse, BulkBatchResponse) to replace JsonElement returns
  • Changed BulkBatchAsync and CreateCatalogCartBasicAsync to accept structured tuple inputs with internal JSON serialization
  • Updated all demo projects to use the new typed responses and tuple-based request construction

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
BrickOwlSharp.Client/UserDetailsResponse.cs New DTO for user details with extension data support
BrickOwlSharp.Client/UserAddressesResponse.cs New DTO for user addresses with extension data support
BrickOwlSharp.Client/TokenDetailsResponse.cs New DTO for token details with extension data support
BrickOwlSharp.Client/OrderTaxSchemesResponse.cs New DTO for order tax schemes with extension data support
BrickOwlSharp.Client/InvoiceTransactionsResponse.cs New DTO for invoice transactions with extension data support
BrickOwlSharp.Client/CatalogSearchResponse.cs New DTO for catalog search results with extension data support
BrickOwlSharp.Client/CatalogFieldOptionListResponse.cs New DTO for catalog field options with extension data support
BrickOwlSharp.Client/CatalogConditionListResponse.cs New DTO for catalog conditions with extension data support
BrickOwlSharp.Client/CatalogBulkResponse.cs New DTO for bulk catalog data with extension data support
BrickOwlSharp.Client/CatalogBulkLookupResponse.cs New DTO for bulk lookup results with extension data support
BrickOwlSharp.Client/CatalogCartBasicResponse.cs New DTO for cart responses with typed properties (Currency, CartTotal, Items)
BrickOwlSharp.Client/CatalogCartBasicItemResponse.cs New DTO for individual cart items with typed properties (Boid, Quantity, Price)
BrickOwlSharp.Client/BulkBatchResponse.cs New DTO for batch responses containing a list of response items
BrickOwlSharp.Client/BulkBatchResponseItem.cs New DTO for individual batch response items with endpoint, status, and body
BrickOwlSharp.Client/IBrickOwlClient.cs Updated interface signatures to use new DTOs and tuple parameters for batch and cart methods
BrickOwlSharp.Client/BrickOwlClient.cs Implemented tuple-to-JSON serialization logic for batch and cart methods, updated all affected methods to return typed DTOs
BrickOwlSharp.Demos/UserDemo.cs Updated to use typed responses and access AdditionalData instead of JsonElement enumeration
BrickOwlSharp.Demos/OrderManagementDemo.cs Updated to use OrderTaxSchemesResponse instead of JsonElement
BrickOwlSharp.Demos/InvoiceDemo.cs Updated to use InvoiceTransactionsResponse instead of JsonElement
BrickOwlSharp.Demos/CatalogAdvancedDemo.cs Updated to construct tuple-based requests and consume typed responses for cart and batch operations
Comments suppressed due to low confidence (6)

BrickOwlSharp.Client/BrickOwlClient.cs:673

  • Disposable 'FormUrlEncodedContent' is created but not disposed.
            HttpContent content = new FormUrlEncodedContent(formData);

BrickOwlSharp.Client/BrickOwlClient.cs:92

  • These 'if' statements can be combined.
            if (disposing)
            {
                if (_disposeHttpClient)
                {
                    _httpClient.Dispose();
                }
            }

BrickOwlSharp.Client/BrickOwlClient.cs:454

  • The expression 'A == true' can be simplified to 'A'.
                url = AppendOptionalParam(url, "active_only", activeOnly.Value == true ? 1 : 0);

BrickOwlSharp.Client/BrickOwlClient.cs:184

  • Both branches of this 'if' statement return - consider using '?' to express intent better.
                if (string.Equals(result.Status, "success", StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                else
                {
                    return false;
                }

BrickOwlSharp.Client/BrickOwlClient.cs:615

  • Both branches of this 'if' statement return - consider using '?' to express intent better.
                if (string.Equals(result.Status, "success", StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                else
                {
                    return false;
                }

BrickOwlSharp.Client/BrickOwlClient.cs:755

  • Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.
                    if (rawValue is decimal v)
                    {
                        value = v.ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        value = rawValue.ToString();
                    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +323 to +347
var itemList = new List<Dictionary<string, string>>();
foreach (var item in items ?? Enumerable.Empty<(string DesignId, int? ColorId, string Boid, int Quantity)>())
{
var itemDictionary = new Dictionary<string, string>
{
{ "qty", item.Quantity.ToString() }
};

if (!string.IsNullOrWhiteSpace(item.DesignId))
{
itemDictionary["design_id"] = item.DesignId;
}

if (item.ColorId.HasValue)
{
itemDictionary["color_id"] = item.ColorId.Value.ToString();
}

if (!string.IsNullOrWhiteSpace(item.Boid))
{
itemDictionary["boid"] = item.Boid;
}

itemList.Add(itemDictionary);
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tuple parameter for CreateCatalogCartBasicAsync allows both DesignId/ColorId and Boid to be null/empty simultaneously. According to typical catalog cart APIs, at least one identification method (either DesignId with ColorId, or Boid) should be required. Consider adding validation to ensure that each item has either a non-empty DesignId or a non-empty Boid before processing.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants