Design subressource mapping

20 views Asked by At

A lodger can have many appointment.

Currently to get appointment for a lodger i use

@RequestMapping(value = "/lodgers/{lodgerId}/appointments", method = RequestMethod.GET)
public Lodger getAppointmentsByLogderId(@PathVariable("lodgerId") long lodgerId) {
    return lodgerService.getLodger(lodgerId);
}

To get all appointment for all user in function of date i thinking we can do it from many way.

My first idea was to create a new ressource for this In the AppointmentController RestController

@RequestMapping(value = "/appointments", method = RequestMethod.GET)
public List<Appointment> getAllAppointments(@RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) {
    ...
}

But i could do it also this way i think In the LodgerController RestController

@RequestMapping(value = "/lodgers/appointments", method = RequestMethod.GET)
public Lodger getAllLodgerAppointmentsByDate(@RequestParam("startDate") Date startDate, @RequestParam("endDate") Date endDate) {
    ...
}

For creation it's the same thing

Appointment is related to a lodger

@RequestMapping(value = "/lodgers/{lodgerId}appointments", method = RequestMethod.POST)
public Lodger createAppointment(@RequestParam("lodgerId")Long lodgerId, @RequestBody Appointment appointment) {
    ...
}

@RequestMapping(value = "/appointments/", method = RequestMethod.POST)
public Lodger createAppointment(@RequestBody Appointment appointment) {
    ...
}

Witch case is better

0

There are 0 answers