Reputation: 294
I'm trying to follow DDD and CQRS principles in the project I'm currently working on. I'm now struggling with a design decision. Let's say I have a page with a list of topics a users can subscribe to. The users also sees what topics he has subscribed to. How do I retrieve the data? Do I query the topics and marked topics separately.
e.g.
and then in the view I do the magic of combining the 2 so that the users sees his subscriptions. Or do I make 1 model that contains all topics and already mark the topics the user have subscribed to
e.g.
Upvotes: 0
Views: 71
Reputation: 685
This really comes down to a design decision - what are you going to show the users?
If 1, you want a results view...
var resultView = new TwoResultViews(avaiableTopics, subscriptionTopics);
returns
"res": {
"availableTopics":
[
{
"topic": "topic1",
}
],
"subscribedTopics":
[
{
"topic": "anotherTopic"
}
]
}
or if 2
var resultView = new SingleResultView(availableTopics, susbcrtiptionTopics);
returns
[
{
"topic": "topic1",
"subscribed": true
}
],
Either way, you one want 1 call to the API, unless there are obvious (and accountable - aka performance) reasons to optimise it.
Upvotes: 0
Reputation: 58434
Let's say I have a page with a list of topics a users can subscribe to. The users also sees what topics he has subscribed to. How do I retrieve the data?
There is various ways to do this but I would create two read models:
When constructing your page, you can then use both data to see what topics users can subscribe in that page, and probably unsubscribe. As you have at most 50 topics on both ends, performance for page construction shouldn’t be an issue.
Upvotes: 2