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;
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();
}
}
}
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