C
C#3mo ago
Alex

help me find correct response model

Hi, here is my database schema for a shop. I want to build a page to display product details. Use can choose between attributes and based on their choice I want to display price and quantity in stock (select variant of product). Some attributes might be unavailable. What's response model (dto) should I create and return as a response for this page to make less calculations on the client (for example group attribute value)?
No description
No description
2 Replies
Trinitek
Trinitek3mo ago
given your schema allows for an unlimited number of custom attributes, I'd probably do this like
record ProductVariant(
int Id,
Dictionary<string, string> Attributes,
int Quantity,
int Price)

record ProductPageDTO(
ProductVariant[] Variants)
record ProductVariant(
int Id,
Dictionary<string, string> Attributes,
int Quantity,
int Price)

record ProductPageDTO(
ProductVariant[] Variants)
let the view generate an attribute group for each key, add a button for each value under that key, and if a product variant is missing a key-value pair generate a "None" button to represent that
Alex
AlexOP3mo ago
I'll try it, thanks
Want results from more Discord servers?
Add your server