Skip to content

Overriding GET method to search with TSVectorType #63

@paridin

Description

@paridin

I try to create an API which inherited from ResourceBase, The problem is i can't set every record as jsonApi,
I expected,

{
  "data": [
    {
      "type": "trademarks",
      "id": "1",
      "attributes": {
        "expediente": "1717801",
        "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
        "figura_juridica": "REGISTRO DE MARCA",
        "logotipo": null,
        "signo": "IGUY",
        "tipo": "NOMINATIVA",
        "titular": "SAMSONITE IP HOLDINGS S.\u00c0.R.L."
      }
    },
    .
    . rest of the data
    .
    ]
}

Got

{
    "data": {
        "attributes": {
            "trademarks": [
                {
                    "fecha_de_presentacion": "01/02/2016 12:00:00 AM",
                    "figura_juridica": "REGISTRO DE MARCA",
                    "id": 1,
                    "signo": "IGUY",
                    "logotipo": null,
                    "tipo": "NOMINATIVA",
                    "titular": "SAMSONITE IP HOLDINGS S.À.R.L.",
                    "expediente": "1717801"
                },
    .
    . rest of the data
    .
    ]
}
# python implementation using ripozo
class Trademarks(restmixins.ResourceBase):
    """
    Trademarks Class provide a resource for search Using a TSVector
    to create a search box
    """
    @apimethod(methods=['GET'])
    def search_trademark(cls, request):
        print(request.query_args)
        props = {'pks': ('id',)}
        if 'search' in request.query_args:
            search = request.query_args.pop('search')[0]
            result = TrademarkMarcanet.query.search(search).all()
        else:
            result = TrademarkMarcanet.query.all()
        response = [r.serialize() for r in result]
        props.update(dict(trademarks=make_json_safe(response)))
        return cls(properties=props, status_code=200)

exists another way to do this task using ripozo api?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions