Controller calling multiple services
I have a few layers in my WebApplication: Presentation, Service, DAO, Domain. Services call DAO objects which reads data from a Database/File whatever. I have a Controller that needs to fetch data from different Services and set them as part of the Response. Should I put the logic to call different Services in the Controller method or should I create some sort of Facade which in turn will call different Services? If so, in what Layer should the Facade reside? @Path("/") public class MyController { @Autowired private FirstService firstService; @Autowired private SecondService secondService; @GET public Response getData(@QueryParam("query") final String query) { final MyResponse response = new MyResponse(); // Service 1 final String firstData = firstService.getData(query); response.setFirstData(query); if (someCondition) { // Service 2 final String secondData = secondService.getData(query); response.setSecondData(query); } // more Service calls maybe return Response.status(Response.Status.OK).entity(response).build(); } }

I have a few layers in my WebApplication: Presentation, Service, DAO, Domain.
Services call DAO objects which reads data from a Database/File whatever.
I have a Controller
that needs to fetch data from different Services
and set them as part of the Response
.
Should I put the logic to call different Services in the Controller method or should I create some sort of Facade
which in turn will call different Services? If so, in what Layer should the Facade reside?
@Path("/")
public class MyController {
@Autowired
private FirstService firstService;
@Autowired
private SecondService secondService;
@GET
public Response getData(@QueryParam("query") final String query) {
final MyResponse response = new MyResponse();
// Service 1
final String firstData = firstService.getData(query);
response.setFirstData(query);
if (someCondition) {
// Service 2
final String secondData = secondService.getData(query);
response.setSecondData(query);
}
// more Service calls maybe
return Response.status(Response.Status.OK).entity(response).build();
}
}