Conversation
| { | ||
| public static class IEnumerableExtensions | ||
| { | ||
| public static IEnumerable<ExpandoObject> ShapeData<TSource>(this IEnumerable<TSource> source, string? fields) |
There was a problem hiding this comment.
Not sure if I follow the logic behind having almost identical lines of code in both extensions? Can't we just re-use the generic or object extension here with using smth like source.Select(o => o.ShapeObject)?
There was a problem hiding this comment.
We can do that, but the main reason behind why its written like this initially is optimization purposes. In the IEnumerable extension the propertyInfo list is cached since it is an expensive operation and doing it for every single element in the list would be very performance heavy. It can be changed, but this is the main reason why its made this way.
There was a problem hiding this comment.
This issue has been resolved. Now instead of using extension methods, we have a DataShaper service, and we are caching the propertyInfos inside a dictionary field. And we only have one implementation of the data shaping logic instead of the two as we had before
|
|
||
| namespace Dappi.HeadlessCms.Extensions | ||
| { | ||
| public static class ObjectExtensions |
There was a problem hiding this comment.
just a suggestion: I would call this something like DataShaper for example. First of all because it doesn't really extend object but it is a generic.
|
Like the idea overall. Would suggest some unit tests to find some hidden and nasty edge-cases if they exist. |
Unit tests are implemented, we have a lot of coverage for this part. We will see if any bugs arise in the future. |
Implemented data shaping trough query params.
The fields parameter is optional. If left empty we will get all of the properties of the requested resource.
Example:
/api/Users/e3171502-622c-4a05-beb8-0c4c37f48401The response will be:
but if we add the fields parameter:
/api/Users/e3171502-622c-4a05-beb8-0c4c37f48401?fields=userNameThe response will only contain the requested properties
Also we can separate field names with comma to select multiple properties:
/api/Users/e3171502-622c-4a05-beb8-0c4c37f48401?fields=id,userNameThe response will only contain the requested properties
closes #197