Commit 6a7ab6bc authored by Iago Gómez Salgado's avatar Iago Gómez Salgado

Add /people/{id}/pets to PeopleResource

parent b0b6f85c
...@@ -16,6 +16,7 @@ import javax.ws.rs.core.Response; ...@@ -16,6 +16,7 @@ import javax.ws.rs.core.Response;
import es.uvigo.esei.daa.dao.DAOException; import es.uvigo.esei.daa.dao.DAOException;
import es.uvigo.esei.daa.dao.PeopleDAO; import es.uvigo.esei.daa.dao.PeopleDAO;
import es.uvigo.esei.daa.dao.PetsDAO;
import es.uvigo.esei.daa.entities.Person; import es.uvigo.esei.daa.entities.Person;
/** /**
...@@ -29,6 +30,7 @@ public class PeopleResource { ...@@ -29,6 +30,7 @@ public class PeopleResource {
private final static Logger LOG = Logger.getLogger(PeopleResource.class.getName()); private final static Logger LOG = Logger.getLogger(PeopleResource.class.getName());
private final PeopleDAO dao; private final PeopleDAO dao;
private PetsDAO pets;
/** /**
* Constructs a new instance of {@link PeopleResource}. * Constructs a new instance of {@link PeopleResource}.
...@@ -203,6 +205,29 @@ public class PeopleResource { ...@@ -203,6 +205,29 @@ public class PeopleResource {
} catch (DAOException e) { } catch (DAOException e) {
LOG.log(Level.SEVERE, "Error deleting a person", e); LOG.log(Level.SEVERE, "Error deleting a person", e);
return Response.serverError()
.entity(e.getMessage())
.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() return Response.serverError()
.entity(e.getMessage()) .entity(e.getMessage())
.build(); .build();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment