Open paridin opened 8 years ago
Assuming that you also want an endpoint to get individual trademarks the following would work:
class Trademarks(restmixins.ResourceBase): """ Trademarks Class provide a resource for search Using a TSVector to create a search box """
pks = 'id',
_relationships = ListRelationship(cls.resource_name, relation='Trademarks', embedded=True),
@apimethod(methods=['GET'], no_pks=True)
def search_trademark(cls, request):
...
return cls(properties=props, status_code=200, no_pks=True)
In ReSTful frameworks a list of resources is actually a different resource than an individual resources. You can tell this by the fact that they have different endpoints (/resource
vs /resource/:id
) hence why you need a relationship to tell ripozo what they are.
Just to be clear, I didn't test this. But it should work. If it doesn't let me know and we can try to work it out.
Thanks for the response, I will try to be more clear with my trouble, I want all records were matched with a search parameter, to maintain it simple.
I have the following request: /trademarks/?search=sams
so it retrieves all records similar sams
like samsonite, samsung, sams club, etc..
With my implementation of Trademarks class it works (only tested with rest client), So when I connect my API with an ember app, it give me an error based on id.
After researching and doing some test I found that the problem was in the api exposed, this one was not in the correct place.
I'm currently getting all the fields into the attributes node. But I was looking into de ripozo framework, how can I move the id and node list of values(trademarks) one level up and maintain attributes with the fields (exposed in trademarks node) in my response, to look like this my api
{
"data": [
{
"type": "trademarks",
"id": "1",
"attributes": {
"signo": "samsonite",
"logotipo": null,
//... more attributes here
}
},
{
"type": "trademarks",
"id": "2",
"attributes": {
"signo": "samsung",
"logotipo": null,
//... more attributes here
}
}, // .. more results
]
}
Hm... So I looked into this more and it seems it may be a bug with the JSONApiAdapter. I will look into getting a fix out ASAP
I try to create an API which inherited from ResourceBase, The problem is i can't set every record as jsonApi, I expected,
Got
exists another way to do this task using ripozo api?