Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your scenario I would put the logic for loading the appointments for person in one Resource and make it accessible from another Resource (in other words delegating the resource, what I'm assuming you doing already). The actual logic is stored in AppointmentService, so you can use it with your getPersonAppointments().</p> <p>This way you can call it:</p> <ul> <li>/person/1/appointments</li> <li>/appointments?personId=1</li> </ul> <p>Both resulting into same Response. This is maybe not the best practise, but the logic is in one place and makes it more readable and reusable. </p> <pre><code>@Path("person") public class PersonResource { @GET @Path("{personId: [0-9]+}/appointments") public AppointmentsResource loadAppointmentsForPerson(@PathParam("personId") Long personId) { return new AppointmentsResource(personId); } } @Path("apointments") class AppointmentResource { private AppointmentService service; private Long personId; public AppointmentResource() { } public AppointmentResource(Long personId) { this.personId = personId; } @GET public Response loadAppointmentsForPerson(@QueryParam("personId") Long personId) { Long personIdToUse = null; if (this.personId != null) { personIdToUse = this.personId; } else if (personId != null) { personIdToUse = personId; } else { //no input, bad request } List&lt;Appointment&gt; appointments = service.getPersonAppointments(personIdToUse) //create your response from appointments } } </code></pre> <p>Of course in your AppointmentResource, you'll then have another stuff, like loading the appointment by specific ID.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload