diff --git a/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java b/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java index 09b8834c7b71d5176e012bcd6076d36eb275bb29..459acc2a58aacf90673b712e5fb0a20e581ac746 100644 --- a/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java +++ b/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java @@ -16,6 +16,7 @@ import javax.ws.rs.core.Response; import es.uvigo.esei.daa.dao.DAOException; import es.uvigo.esei.daa.dao.PeopleDAO; +import es.uvigo.esei.daa.dao.PetsDAO; import es.uvigo.esei.daa.entities.Person; /** @@ -29,6 +30,7 @@ public class PeopleResource { private final static Logger LOG = Logger.getLogger(PeopleResource.class.getName()); private final PeopleDAO dao; + private PetsDAO pets; /** * Constructs a new instance of {@link PeopleResource}. @@ -208,4 +210,27 @@ public class PeopleResource { .build(); } } + + @GET + @Path("/{id}/pets/") + public Response personsPets( + @PathParam("id") int id + ) { + this.pets = new PetsDAO(); + try { + return Response.ok(this.pets.peoplePets(id)).build(); + } catch (IllegalArgumentException iae) { + LOG.log(Level.FINE, "Invalid pet id in get method", iae); + + return Response.status(Response.Status.BAD_REQUEST) + .entity(iae.getMessage()) + .build(); + } catch (DAOException e) { + LOG.log(Level.SEVERE, "Error getting a pet", e); + + return Response.serverError() + .entity(e.getMessage()) + .build(); + } + } }