SkywardApps / popcorn

Popcorn is a .Net Middleware for your RESTful API that allows your consumers to request exactly as much or as little as they need, with no effort from you.
https://skywardapps.github.io/popcorn/
MIT License
59 stars 19 forks source link

Allow 'mapping' to be defined for more than one target type. #10

Closed undiwahn closed 7 years ago

undiwahn commented 7 years ago

Right now Popcorn only allows configuration of a 'default' mapping; one source type to one destination type.

This makes sense at the point of 'blind' expansion (the return result from the Api) but we need to be able to map any given source into multiple different projections, especially given that we know the destination type when we inspect properties. So for example:

// data object
class User{
 public Guid Id {get; set;}
 public string Name {get; set;}
 public string Email {get; set; }
}

// a projection
class UserNameOnly { 
 public Guid Id {get; set;}
 public string Name {get; set;}
}

// a different projection
class UserEmailOnly {
 public Guid Id {get; set;}
 public string Email {get; set;}
}

// Aggregation object
public class UserRelationship{
 public User Owner {get; set;}
 public User  Child {get; set;}
} 

// A projection of the aggregation, 
// projecting the User into different forms
public class UserRelationshipProjection {
 public UserNameOnly Owner {get; set;}
 public UserEmailOnly Child {get; set;}
}

We should be able to return a UserRelationship from an API and have the contained users correctly projected into UserNameOnly and UserEmailOnly types as expected.

We do still need the concept of a 'default' projection type to meet the requirements of the current implementation.

alexbarbato commented 7 years ago

Looks like @undiwahn is on this