From d761265996bfa0f1b6a5e4838d1eae93157af702 Mon Sep 17 00:00:00 2001 From: aggonzalez Date: Sun, 4 Apr 2021 22:43:03 +0200 Subject: [PATCH] Fixing errors and adding comments --- db/mysql-with-inserts.sql | 9 +- db/mysql.sql | 5 +- .../java/es/uvigo/esei/daa/entities/Pet.java | 2 +- src/main/webapp/js/view/pets.js | 41 +++--- src/main/webapp/main.html | 8 +- .../es/uvigo/esei/daa/dataset/PetDataset.java | 121 +++++++++--------- .../uvigo/esei/daa/entities/PetUnitTest.java | 4 - 7 files changed, 95 insertions(+), 95 deletions(-) diff --git a/db/mysql-with-inserts.sql b/db/mysql-with-inserts.sql index daa0d59..8cd2de8 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 6e04bef..9e80560 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 c51f68a..ad352a4 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 7d94780..58d79cb 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 = "