diff --git a/db/mysql-with-inserts.sql b/db/mysql-with-inserts.sql index daa0d59d382ac09274b23d98b07df1806d2aa229..8cd2de8f42103ba02723aac00cea964bfcb086da 100644 --- a/db/mysql-with-inserts.sql +++ b/db/mysql-with-inserts.sql @@ -37,14 +37,15 @@ INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'María','Nu INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Alba','Fernández'); INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Asunción','Jiménez'); -INSERT INTO `pets` (`id`, `name`, `type`, `peopleID`) VALUES +INSERT INTO `daaexample`.`pets` (`id`, `name`, `type`, `peopleID`) VALUES (0, 'Cato', 'Gato', 1), (0, 'Trosky', 'Perro', 2), -(0, 'DAA mascota', 'Perro', 4), +(0, 'Umma', 'Gato', 4), +(0, 'Python', 'Anaconda', 4), (0, 'Casper', 'Conejo', 7); -ALTER TABLE `pets` - ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `people` (`id`); +ALTER TABLE `daaexample`.`pets` + ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `daaexample`.`people` (`id`); -- The password for each user is its login suffixed with "pass". For example, user "admin" has the password "adminpass". INSERT INTO `daaexample`.`users` (`login`,`password`,`role`) diff --git a/db/mysql.sql b/db/mysql.sql index 6e04bef3be7bbcfd858236cd0435581a293524a8..9e8056082e27a510236cb2f64792d6b5164629e0 100644 --- a/db/mysql.sql +++ b/db/mysql.sql @@ -24,9 +24,8 @@ CREATE TABLE `daaexample`.`pets` ( KEY `peopleID` (`peopleID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -ALTER TABLE `pets` - ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `people` (`id`); - +ALTER TABLE `daaexample`.`pets` + ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `daaexample`.`people` (`id`); CREATE USER IF NOT EXISTS 'daa'@'localhost' IDENTIFIED WITH mysql_native_password BY 'daa'; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost'; diff --git a/src/main/java/es/uvigo/esei/daa/entities/Pet.java b/src/main/java/es/uvigo/esei/daa/entities/Pet.java index c51f68a455963feea38f87a9b84f6f1faf886033..ad352a4c2059e3aaf80ea272a5f3fd17a267b85c 100644 --- a/src/main/java/es/uvigo/esei/daa/entities/Pet.java +++ b/src/main/java/es/uvigo/esei/daa/entities/Pet.java @@ -33,7 +33,7 @@ public class Pet { } public void setType(String type) { - this.type = requireNonNull(type, "Name can't be null"); + this.type = requireNonNull(type, "Type can't be null"); } public String getName() { diff --git a/src/main/webapp/js/view/pets.js b/src/main/webapp/js/view/pets.js index 7d94780e6e15b5b91496286ef4798f80c9080783..58d79cb3c546fe73c6de4e6ce6d0b905a76438de 100644 --- a/src/main/webapp/js/view/pets.js +++ b/src/main/webapp/js/view/pets.js @@ -15,26 +15,27 @@ var PetView = (function () { this.init = function () { var cont = 0; - var humans = [] - var humans_list = [] - var daoPeople = new PeopleDAO(); - function Human(id, name, surname) { - this.id = id; - this.name = name; - this.surname = surname; - } - daoPeople.listPeopleSync(function (people) { - $.each(people, function (key, human) { - humans[human.id] = new Human(human.id, human.name, human.surname); - humans_list[cont] = new Human(human.id, human.name, human.surname); - cont++; - }); - }, - function () { - alert('No has sido posible acceder al listado de mascotas.'); - }); + var humans = [] + var humans_list = [] + var daoPeople = new PeopleDAO(); + function Human(id, name, surname) { + this.id = id; + this.name = name; + this.surname = surname; + } + daoPeople.listPeopleSync(function (people) { + $.each(people, function (key, human) { + humans[human.id] = new Human(human.id, human.name, human.surname); + humans_list[cont] = new Human(human.id, human.name, human.surname); + cont++; + }); + }, + function () { + alert('No has sido posible acceder al listado de mascotas.'); + }); insertPetForm($('#' + formContainerId), humans_list, humans); - insertPetList($('#' + listContainerId)); + insertPetList($('#' + listContainerId)); + //Opción en el caso de que se quieran listar todas las mascotas de todos los dueños if (peopleID === "all") { dao.listAll(function (people) { $.each(people, function (key, pet) { @@ -45,6 +46,7 @@ var PetView = (function () { alert('No has sido posible acceder al listado de mascotas.'); }); } else { + //En caso de que solo se quiera listar las mascotas de una persona dao.listPetsByPeopleID(peopleID, function (people) { $.each(people, function (key, pet) { appendToTable(pet, humans); @@ -159,7 +161,6 @@ var PetView = (function () { var returnHumansSelect = function (humans) { var toret = "