How to expand a resource with new attributes given a value in query string?
I have a resource named product that has an attribute named units.
This attribute specifies the number of times the resource can be bought in a specific day.
Everytime the user buys the resource is created a new transaction resource related to the product resource. The relation is completed with the buy date.
So, the api /products returns all the product’s attributes and the value of ‘units’.
I’d like to obtain by that api the actual number of units (calculated by counting the transaction objects) when is given in query string the transaction date.
What’s the best way to achieve this?
How to specify the transaction date in query string?
Options:
- update the units attribute with the actual number of units
- always add an attribute named actual_units filled with null when the transaction date is not provided
- add an attribute actual_units only only when is set the transaction date.
None of the include or field keys described in the json specifications satisfy this situation.
Thanks