I'm building a RESTful web api using Spring Microservices. I am following the Controller/Service/Repository Structure.
Where can I find some guidelines on what the responsibility of each class should be?
For example, say I'm implementing the following controller:
@RestController
@RequestMapping(value="v1/license")
public class LicenseController {
@Autowired
private LicenseService licenseService;
@RequestMapping(value="/{licenseId}",method = RequestMethod.GET)
public ResponseEntity<License> getLicense(@PathVariable("licenseId") String licenseId) {
License license = licenseService.getLicense(licenseId);
I would like to know, for example, if the responsibility of validating the input falls on the controller, or the service.
Before attempting to return a reply, should I check in the Controller, or the Service whether the object exists? If no object found, should I throw an exception at Service level, or Controller level?
Where can I find answers to such questions?
Thanks in advance,