I'm creating a small issue tracker with ASP Core MVC to bring myself back up to speed after some time away from code. My application started with onion architecture but I have found myself dipping my toes into CQRS and feature slices, slowly transitioning some of the functionality to this style. I'm not using event sourcing and I do not have read-specific tables.
My question is about queries related to commands, specifically my CreateProject/EditProject commands. The commands themselves are simple, they just have a name, description, and some IDs for relationships, two of which are PrioritySchemeId and PermissionSchemeId. No issues there.
Where I'm stuck is the initial queries for the Create/Edit pages. These pages are of course comprised of two parts: the initial GET to display the page and the POST to perform the action.
Let's take the EditProject example. Every example I've seen online for this shows a simple entity with no relationships. For the first part, the GET, they simply call a query like "GetProjectQuery", map that result to a view model (or use it as the view model) and then show the page. When that page posts back, they model bind to an EditProjectCommand and fire it off. End of story.
My issue is that I need dropdowns on my page. I need a list of all the available priority schemes and permission schemes for the user to choose from, so a query like GetProjectQuery is no good as it wouldn't contain that data.
I could call a query like GetPermissionSchemesQuery in my controller where I build the view model but this reminds me of service methods and there's much more data on a permission scheme than what I need, I just need the ids and names for the select list.
My thinking is to create a query specifically for this page, a GetEditProjectQuery. This query would load all of the data that is needed for the initial display of the page. This would basically leave me with a query/command pair: GetEditProjectQuery and EditProjectCommand. I'd then do the same for GetCreateProjectQuery/CreateProjectCommand.
Is this the correct approach? Is there something I'm missing? In the long run I would probably end up with a lot of these pairs for different features and I'm not sure if it's the right way to go. It feels like the best way but I can't find any examples of anyone else doing this.
Aucun commentaire:
Enregistrer un commentaire