jaystack / odata-v4-server-mongodb-example

OData V4 Server with MongoDB example
11 stars 4 forks source link

When I call to edm.function the get method called also #14

Open ramifi opened 7 years ago

ramifi commented 7 years ago

Hi When I am calling a function like: http://laptop:3000/Offers/xact.getCheapest(campaign_id='5967c67258a92021c8d350e8')

The function getCheapest is called BUT the generic get method called also.

lazarv commented 7 years ago

@ramifi: this is by design. The function is running in the context of the previous navigation part (Offers entity set in this case). You can implement such custom logic in the Offers controller class which will affect the result of the function. You can use the @odata.result parameter decorator to get access to that result set. These navigation parts are working like middlewares.

ramifi commented 7 years ago

Thanx lazarv. How can I call to the function without the generic get method?

lazarv commented 7 years ago

@ramifi: you should implement a function import in the server class and call that like /getCheapestProduct(campaign_id='5967c67258a92021c8d350e8').

ramifi commented 7 years ago

How do I do that? Do you have an example?

lazarv commented 7 years ago

See the according part in this blogpost. It's the same as implementing an entity or entity collection bound function, but use the @Edm.FunctionImport decorator. initDb in the examples are action import implementations. Function imports are the same with a return type defined.