Reputation: 1271
I have a Rest layer that call the Service layer.
My language is Java with Spring Framework
With some code would be:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Entity get(@PathVariable("id") Long id) {
Entity entity = new Entity();
entity.setId(id);
return entityService.get(entity);
}
Well.... here are my questions:
Is it better to have unit methods to filter the get like:
entityService.getByID(id); entityService.getByValue1(value1); entityService.getByIDAndValue1(id, value1);
Is it better to set the properties of Entity at Rest layer and call service passing an object?
Upvotes: 0
Views: 30
Reputation: 960
I think you may have some separate methods for more frequent use cases, like findByPrimaryKey(id)
or findByName
, and also a find by example method that will find entity by all not null fields in given entity.
You can also define a Business aware query interface (i mean no database layer query) to find objects, But this will complicate your rest service layer code so i prefer separated and simple methods that will make your service layer more readable.
There is also a Parameters Object design pattern, that mean grouping logically related parameters in object, eg. start date and and date as DateRange
object.
But is useful when some logically related sequence of objects are passed as parameters to various methods. For example contact parameter may contain address, Zipcode and tel.
Upvotes: 1