Commit c07ce0ea authored by cyanide4all's avatar cyanide4all

class

parent 3f752435
......@@ -20,17 +20,20 @@ import es.uvigo.esei.daa.entities.Pet;
*/
public class PetDAO extends DAO {
private final static Logger LOG = Logger.getLogger(PetDAO.class.getName());
//TODO junto con lo de justo debajo
//TODO está puesto a 1 para testeos
private int ownerID = 1;
public int getOwnerID(){
return ownerID;
}
/*//TODO ESTO IGUAL NO FUNCIONA LO TESTEO LUEGO
public PetDAO(int ownerID){
public void setOwnerID(int ownerID) {this.ownerID=ownerID;}
public PetDAO(int ownerID) {
this.ownerID = ownerID;
}
*/
public PetDAO(){}
/**
* Returns a pet stored persisted in the system.
*
......@@ -70,9 +73,11 @@ public class PetDAO extends DAO {
*/
public List<Pet> list() throws DAOException {
try (final Connection conn = this.getConnection()) {
final String query = "SELECT * FROM pet";
final String query = "SELECT * FROM pet WHERE ownerID=?";
try (final PreparedStatement statement = conn.prepareStatement(query)) {
statement.setInt(1, ownerID);
try (final ResultSet result = statement.executeQuery()) {
final List<Pet> petList = new LinkedList<>();
......@@ -193,9 +198,7 @@ public class PetDAO extends DAO {
return new Pet(
row.getInt("id"),
row.getString("name"),
//TODO EXTREMO ESTO ES PROVISIONAL
ownerID
//TODO REPITO PROVISIONAL MECA
);
}
}
var PetDAO = (function() {
var PetDAO = (function(ownerID) {
var resourcePath = "rest/pet/";
var requestByAjax = function(data, done, fail, always) {
done = typeof done !== 'undefined' ? done : function() {};
......@@ -11,6 +11,18 @@ var PetDAO = (function() {
.always(always);
};
var setOwnerIDPetDAO = function(ownerID, done, fail, always) {
var query = window.location.search.substring(1);
var split = query.split("=");
var getID = decodeURIComponent(split[1]);
//alert(getID);
requestByAjax({
url: resourcePath + getID,
type: 'POST',
data: getID
}, done, fail, always);
}();
function PetDAO() {
this.listPets = function(done, fail, always) {
requestByAjax({
......@@ -19,6 +31,18 @@ var PetDAO = (function() {
}, done, fail, always);
};
this.setOwnerIDPetDAO = function(ownerID, done, fail, always) {
var query = window.location.search.substring(1);
var split = query.split("=");
var getID = decodeURIComponent(split[1]);
//alert(getID);
requestByAjax({
url: resourcePath + getID,
type: 'POST',
data: getID
}, done, fail, always);
};
this.addPet = function(pet, done, fail, always) {
requestByAjax({
url: resourcePath,
......
......@@ -13,7 +13,7 @@ var PetView = (function() {
function PetView(petDao, formContainerId, listContainerId) {
dao = petDao;
self = this;
dao.setOwnerIDPetDAO();
insertPetForm($('#' + formContainerId));
insertPetList($('#' + listContainerId));
......
......@@ -7,7 +7,7 @@
<body>
<div id="pet-container">
<h1>People</h1>
<a id="#logout" href="logout">Logout</a>
<a id="#logout" href="logout">Logout</a> <a id="#atras" href="main.html">Back</a>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
......@@ -15,6 +15,7 @@
<script type="text/javascript" src="js/view/pet.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var view = new PetView(new PetDAO(), 'pet-container', 'pet-container');
view.init();
......
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