Fixing errors and adding comments

parent 2059c645
...@@ -37,14 +37,15 @@ INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'María','Nu ...@@ -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,'Alba','Fernández');
INSERT INTO `daaexample`.`people` (`id`,`name`,`surname`) VALUES (0,'Asunción','Jiménez'); 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, 'Cato', 'Gato', 1),
(0, 'Trosky', 'Perro', 2), (0, 'Trosky', 'Perro', 2),
(0, 'DAA mascota', 'Perro', 4), (0, 'Umma', 'Gato', 4),
(0, 'Python', 'Anaconda', 4),
(0, 'Casper', 'Conejo', 7); (0, 'Casper', 'Conejo', 7);
ALTER TABLE `pets` ALTER TABLE `daaexample`.`pets`
ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `people` (`id`); 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". -- 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`) INSERT INTO `daaexample`.`users` (`login`,`password`,`role`)
......
...@@ -24,9 +24,8 @@ CREATE TABLE `daaexample`.`pets` ( ...@@ -24,9 +24,8 @@ CREATE TABLE `daaexample`.`pets` (
KEY `peopleID` (`peopleID`) KEY `peopleID` (`peopleID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE `pets` ALTER TABLE `daaexample`.`pets`
ADD CONSTRAINT `pets_ibfk_1` FOREIGN KEY (`peopleID`) REFERENCES `people` (`id`); 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'; CREATE USER IF NOT EXISTS 'daa'@'localhost' IDENTIFIED WITH mysql_native_password BY 'daa';
GRANT ALL ON `daaexample`.* TO 'daa'@'localhost'; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost';
...@@ -33,7 +33,7 @@ public class Pet { ...@@ -33,7 +33,7 @@ public class Pet {
} }
public void setType(String type) { 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() { public String getName() {
......
...@@ -15,26 +15,27 @@ var PetView = (function () { ...@@ -15,26 +15,27 @@ var PetView = (function () {
this.init = function () { this.init = function () {
var cont = 0; var cont = 0;
var humans = [] var humans = []
var humans_list = [] var humans_list = []
var daoPeople = new PeopleDAO(); var daoPeople = new PeopleDAO();
function Human(id, name, surname) { function Human(id, name, surname) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.surname = surname; this.surname = surname;
} }
daoPeople.listPeopleSync(function (people) { daoPeople.listPeopleSync(function (people) {
$.each(people, function (key, human) { $.each(people, function (key, human) {
humans[human.id] = new Human(human.id, human.name, human.surname); humans[human.id] = new Human(human.id, human.name, human.surname);
humans_list[cont] = new Human(human.id, human.name, human.surname); humans_list[cont] = new Human(human.id, human.name, human.surname);
cont++; cont++;
}); });
}, },
function () { function () {
alert('No has sido posible acceder al listado de mascotas.'); alert('No has sido posible acceder al listado de mascotas.');
}); });
insertPetForm($('#' + formContainerId), humans_list, humans); 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") { if (peopleID === "all") {
dao.listAll(function (people) { dao.listAll(function (people) {
$.each(people, function (key, pet) { $.each(people, function (key, pet) {
...@@ -45,6 +46,7 @@ var PetView = (function () { ...@@ -45,6 +46,7 @@ var PetView = (function () {
alert('No has sido posible acceder al listado de mascotas.'); alert('No has sido posible acceder al listado de mascotas.');
}); });
} else { } else {
//En caso de que solo se quiera listar las mascotas de una persona
dao.listPetsByPeopleID(peopleID, function (people) { dao.listPetsByPeopleID(peopleID, function (people) {
$.each(people, function (key, pet) { $.each(people, function (key, pet) {
appendToTable(pet, humans); appendToTable(pet, humans);
...@@ -159,7 +161,6 @@ var PetView = (function () { ...@@ -159,7 +161,6 @@ var PetView = (function () {
var returnHumansSelect = function (humans) { var returnHumansSelect = function (humans) {
var toret = "<select id=dueno class=form-control>"; var toret = "<select id=dueno class=form-control>";
var cont = 0
var i = 0; var i = 0;
for (i = 0; i < humans.length; i++) { for (i = 0; i < humans.length; i++) {
toret += "<option value=" + humans[i].id + ">" + humans[i].name + " " + humans[i].surname + "</option>"; toret += "<option value=" + humans[i].id + ">" + humans[i].name + " " + humans[i].surname + "</option>";
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>DAA Example</title> <title>DAA Example [Alejandro Gómez González]</title>
<link rel="stylesheet" <link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<div class="navbar navbar-dark bg-dark box-shadow"> <div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-between"> <div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center"> <a href="#" class="navbar-brand d-flex align-items-center">
<strong>DAA Example</strong> <strong>DAA Example [Alejandro Gómez González]</strong>
</a> </a>
<button id="mascotas" class="btn btn-white">Mascotas</button> <button id="mascotas" class="btn btn-white">Mascotas</button>
<button id="personas" class="btn btn-white">Personas</button> <button id="personas" class="btn btn-white">Personas</button>
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
event.preventDefault(); event.preventDefault();
doLogout(); doLogout();
}); });
//Si click en botón mascotas, show all de Mascotas
$('#mascotas').click(function(event) { $('#mascotas').click(function(event) {
document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Mascotas</h1>"; document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Mascotas</h1>";
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
'people-container', 'people-container','all'); 'people-container', 'people-container','all');
view.init(); view.init();
}); });
//Si click en botón mascotas, show all de Personas
$('#personas').click(function(event) { $('#personas').click(function(event) {
document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Personas</h1>"; document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Personas</h1>";
var view = new PeopleView(new PeopleDAO(), var view = new PeopleView(new PeopleDAO(),
......
...@@ -9,63 +9,66 @@ import java.util.function.Predicate; ...@@ -9,63 +9,66 @@ import java.util.function.Predicate;
import es.uvigo.esei.daa.entities.Pet; import es.uvigo.esei.daa.entities.Pet;
public final class PetDataset { public final class PetDataset {
private PetDataset() {}
public static Pet[] pets() { private PetDataset() {
return new Pet[] { }
new Pet(1, "Trotsky", "Perro",1),
new Pet(2, "Cato", "Gato",2), public static Pet[] pets() {
new Pet(3, "Hiroshi", "Conejo",1), return new Pet[]{
new Pet(4, "Jael", "Perro",3) new Pet(1, "Trotsky", "Perro", 1),
}; new Pet(2, "Cato", "Gato", 2),
} new Pet(3, "Hiroshi", "Conejo", 1),
new Pet(4, "Jael", "Perro", 3)
public static Pet[] petsWithout(int ... ids) { };
Arrays.sort(ids); }
final Predicate<Pet> hasValidId = pet -> public static Pet[] petsWithout(int... ids) {
binarySearch(ids, pet.getId()) < 0; Arrays.sort(ids);
return stream(pets()) final Predicate<Pet> hasValidId = pet
.filter(hasValidId) -> binarySearch(ids, pet.getId()) < 0;
.toArray(Pet[]::new);
} return stream(pets())
.filter(hasValidId)
public static Pet pet(int id) { .toArray(Pet[]::new);
return stream(pets()) }
.filter(pet -> pet.getId() == id)
.findAny() public static Pet pet(int id) {
.orElseThrow(IllegalArgumentException::new); return stream(pets())
} .filter(pet -> pet.getId() == id)
.findAny()
public static int existentId() { .orElseThrow(IllegalArgumentException::new);
return 4; }
}
public static int existentId() {
public static int nonExistentId() { return 4;
return 1234; }
}
public static int nonExistentId() {
public static Pet existentPet() { return 1234;
return pet(existentId()); }
}
public static Pet existentPet() {
public static Pet nonExistentPet() { return pet(existentId());
return new Pet(nonExistentId(), "Lolo", "Vaca",4); }
}
public static Pet nonExistentPet() {
public static String newName() { return new Pet(nonExistentId(), "Lolo", "Vaca", 4);
return "Lucky"; }
}
public static String newName() {
public static String newType() { return "Lucky";
return "Anaconda"; }
}
public static String newType() {
public static int newPeopleID() { return "Anaconda";
return 5; }
}
public static int newPeopleID() {
public static Pet newPet() { return 5;
return new Pet(pets().length + 1, newName(), newType(),newPeopleID()); }
}
public static Pet newPet() {
return new Pet(pets().length + 1, newName(), newType(), newPeopleID());
}
} }
...@@ -35,10 +35,6 @@ public class PetUnitTest { ...@@ -35,10 +35,6 @@ public class PetUnitTest {
public void testPersonIntStringStringNullType() { public void testPersonIntStringStringNullType() {
new Pet(1, "Casper",null,1); new Pet(1, "Casper",null,1);
} }
/* public void testPersonIntStringStringNullPeopleID() {
new Pet(1, "Casper","Type",null);
}*/
@Test @Test
public void testSetName() { public void testSetName() {
......
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