Implementing Sub-Resources for REST API
The next important task now is to implement the sub resources of the students and the courses resource. We want all the registrations of a particular student and all the registrations for a particular course.
Add the following method in the Course
class,
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/{courseid}/registrations")
public List<Registration> getRegistrationWithCourseID(@PathParam("courseid") int courseID)
{
return registrationService.getRegistrationForCourse(courseID);
}
and, add the following method in the Student
class,
@Produces(MediaType.APPLICATION_XML)
@Path("/{studentid}/registrations")
public List<Registration> getRegistrationWithStudentsID(@PathParam("studentid") int studentID)
{
return registraionService.getRegistrationsForStudent(studentID);
}