C
C#2y ago
shadi

❔ Social media profiles hidden information?

in social media websites when i set something like my email to private or only shown for me does the api return a different DTO each time? and in that case, I will need to have 99999 DTOs depending on how many properties I have and how many combinations of information that can be hidden/shown?
9 Replies
V0FBU1VM
V0FBU1VM2y ago
@shadilios Then take a look at GraphQL. You can write your query from the client and retrieve the exact amount of data you need.
V0FBU1VM
V0FBU1VM2y ago
If you choose to go with GraphQL. Take a look at hotchocolate -> https://chillicream.com/docs/hotchocolate
Introduction - Hot Chocolate
We're building the ultimate GraphQL platform
ACiDCA7
ACiDCA72y ago
since you arent giving any more concrete examples, i wont go to deep into the topic, but an api can have optional fields, meaning they dont have to be part of the payload, your dto then just sets the value to null or whatever you want to do with it. one dto is normally more than enough for such a case
khamas
khamas2y ago
How I do it is remove certain fields from the DTO So like email address will be null client side But the model is the same
ACiDCA7
ACiDCA72y ago
pretty much jea
khamas
khamas2y ago
Email address field in profile model Ye
Landan
Landan2y ago
You could setup a pattern for your dto validation like:
Model.CouldBe(emailSource=>emailSource.tryGetValue(emailSourceKey, out var emailSourceObject) ? emailSourceObject as emailSourceDTO : default)
.CouldBe(addressSource...)
.CouldBe(infoSource...)
Model.CouldBe(emailSource=>emailSource.tryGetValue(emailSourceKey, out var emailSourceObject) ? emailSourceObject as emailSourceDTO : default)
.CouldBe(addressSource...)
.CouldBe(infoSource...)
Your parameter for the Func would be an IDictionary, or you might be able to use, as, to try casting it to your dto Make a special attribute for model validation, and voila
Model.CouldBe(emailSource=>emailSource as emailSourceDTO);
Model.CouldBe(emailSource=>emailSource as emailSourceDTO);
Model.CouldBe<emailSourceDTO>();
Model.CouldBe<emailSourceDTO>();
Model.CouldBe(typeof(emailSourceDTO));
Model.CouldBe(typeof(emailSourceDTO));
Angius
Angius2y ago
Just use null, and you can tell ASP to remove null fields from the response
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server