Fixing errors and adding comments

parent 2059c645
......@@ -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`)
......
......@@ -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';
......@@ -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() {
......
......@@ -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 = "<select id=dueno class=form-control>";
var cont = 0
var i = 0;
for (i = 0; i < humans.length; i++) {
toret += "<option value=" + humans[i].id + ">" + humans[i].name + " " + humans[i].surname + "</option>";
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>DAA Example</title>
<title>DAA Example [Alejandro Gómez González]</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
......@@ -13,7 +13,7 @@
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-between">
<a href="#" class="navbar-brand d-flex align-items-center">
<strong>DAA Example</strong>
<strong>DAA Example [Alejandro Gómez González]</strong>
</a>
<button id="mascotas" class="btn btn-white">Mascotas</button>
<button id="personas" class="btn btn-white">Personas</button>
......@@ -42,7 +42,7 @@
event.preventDefault();
doLogout();
});
//Si click en botón mascotas, show all de Mascotas
$('#mascotas').click(function(event) {
document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Mascotas</h1>";
......@@ -50,7 +50,7 @@
'people-container', 'people-container','all');
view.init();
});
//Si click en botón mascotas, show all de Personas
$('#personas').click(function(event) {
document.getElementById("people-container").innerHTML = "<h1 class=display-5 mt-3 mb-3>Personas</h1>";
var view = new PeopleView(new PeopleDAO(),
......
......@@ -9,63 +9,66 @@ import java.util.function.Predicate;
import es.uvigo.esei.daa.entities.Pet;
public final class PetDataset {
private PetDataset() {}
public static Pet[] pets() {
return new Pet[] {
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 ->
binarySearch(ids, pet.getId()) < 0;
return stream(pets())
.filter(hasValidId)
.toArray(Pet[]::new);
}
public static Pet pet(int id) {
return stream(pets())
.filter(pet -> pet.getId() == id)
.findAny()
.orElseThrow(IllegalArgumentException::new);
}
public static int existentId() {
return 4;
}
public static int nonExistentId() {
return 1234;
}
public static Pet existentPet() {
return pet(existentId());
}
public static Pet nonExistentPet() {
return new Pet(nonExistentId(), "Lolo", "Vaca",4);
}
public static String newName() {
return "Lucky";
}
public static String newType() {
return "Anaconda";
}
public static int newPeopleID() {
return 5;
}
public static Pet newPet() {
return new Pet(pets().length + 1, newName(), newType(),newPeopleID());
}
private PetDataset() {
}
public static Pet[] pets() {
return new Pet[]{
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
-> binarySearch(ids, pet.getId()) < 0;
return stream(pets())
.filter(hasValidId)
.toArray(Pet[]::new);
}
public static Pet pet(int id) {
return stream(pets())
.filter(pet -> pet.getId() == id)
.findAny()
.orElseThrow(IllegalArgumentException::new);
}
public static int existentId() {
return 4;
}
public static int nonExistentId() {
return 1234;
}
public static Pet existentPet() {
return pet(existentId());
}
public static Pet nonExistentPet() {
return new Pet(nonExistentId(), "Lolo", "Vaca", 4);
}
public static String newName() {
return "Lucky";
}
public static String newType() {
return "Anaconda";
}
public static int newPeopleID() {
return 5;
}
public static Pet newPet() {
return new Pet(pets().length + 1, newName(), newType(), newPeopleID());
}
}
......@@ -35,10 +35,6 @@ public class PetUnitTest {
public void testPersonIntStringStringNullType() {
new Pet(1, "Casper",null,1);
}
/* public void testPersonIntStringStringNullPeopleID() {
new Pet(1, "Casper","Type",null);
}*/
@Test
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