Commit c07ce0ea authored by cyanide4all's avatar cyanide4all

class

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