Currently I have set up a RESTful API to return 1 or more Book
(s) that belongsTo
an Author
. Although this is what I want, it is not in the format I like it to be.
When I give an ID of 2 for the Author
, I get the following response:
<author id="2">
<author_name>Stephen</author_name>
<books>
<book id="2"/>
<book id="3"/>
</books>
</author>
Instead I would like a response that shows the contents of the books instead of a reference:
<list>
<book id="2">
<book_name>BookA</book_name>
<book_year>2001</book_year>
</book>
<book id="3">
<book_name>BookB</book_name>
<book_year>2005</book_year>
</book>
</list>
My contents of the controller that produces the first response is:
@Override
protected Book queryForResource(Serializable id) {
def p = Author.id == params.AuthorId
Book.where {
id == id && p
}.find()
}
Also is it possible to sort by book_year
descending? Any help will be much appreciated.