-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding additional document collection properties to align model with item response #18309
Adding additional document collection properties to align model with item response #18309
Conversation
Good instinct 😄 With the new management API, we try to keep the mappers for only mapping properties from one object to another, so there is no additional population from various services 😄 This is because mapping should be a "cheap" operation; however, this was not always the case in the old backoffice. What we do instead now is create a factory when we need to populate values from services, you can see examples of this in the |
Thanks @nikolajlauridsen - agreed. I could tell it was a code smell but I couldn't see the best way forward. I'll have a look at what you suggest. |
…on-models # Conflicts: # src/Umbraco.Cms.Api.Management/Mapping/Document/DocumentMapDefinition.cs
OK @nikolajlauridsen, I've refactored now as per your suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great and tests good 👍
This PR adds the
IsTrashed
andIsProtected
fields to the document collection result, aligning with the document item result.IsTrashed
was straightforward, we just needed to update the mapping.IsProtected
is a little more tricky, as we have to make a call via theIPublicAccessService
to get the result.I've actually implemented this twice when you look through the commits. Neither I'm totally happy with but I can't find a better way.
First I did the work in the controller (see this commit), but this didn't feel right. Meant having to unpack the
IActionResult
to get at the object being returned to manipulate it.So I ended with pushing this up the mapping layer, which is the right place, but requires injecting the
IPublicAccessService
intoDocumentMapDefinition
. Maybe that's OK, but I don't see we inject services into the mapping definitions in other cases.So needs a second opinion.
To test just pull up the management API via Swagger and test the
/umbraco/management/api/v1/collection/document/
endpoint to verify it returns these two new properties.