From 4313de612079fca393ac3e68db2ff9c27a0a97eb Mon Sep 17 00:00:00 2001 From: MvaugustoESEI <56920396+MvaugustoESEI@users.noreply.github.com> Date: Wed, 18 Mar 2020 11:51:58 +0100 Subject: [PATCH] Ejercicio previo terminado DAAExample --- db/mysql-with-inserts.sql | 8 +++++++ db/mysql.sql | 8 +++++++ .../uvigo/esei/daa/DAAExampleApplication.java | 4 +++- .../java/es/uvigo/esei/daa/dao/PeopleDAO.java | 2 +- .../uvigo/esei/daa/rest/PeopleResource.java | 5 +++-- src/main/webapp/js/view/people.js | 12 ++++++++++ src/main/webapp/main.html | 22 +++++++++++++++++++ .../esei/daa/filters/AuthorizationFilter.java | 7 +++++- .../esei/daa/suites/IntegrationTestSuite.java | 4 +++- .../uvigo/esei/daa/suites/UnitTestSuite.java | 4 +++- src/test/resources/datasets/dataset-add.xml | 5 +++++ .../resources/datasets/dataset-delete.xml | 6 +++++ .../resources/datasets/dataset-modify.xml | 6 +++++ src/test/resources/datasets/dataset.dtd | 9 +++++++- src/test/resources/datasets/dataset.xml | 5 +++++ src/test/resources/db/hsqldb-drop.sql | 3 ++- src/test/resources/db/hsqldb.sql | 8 +++++++ 17 files changed, 109 insertions(+), 9 deletions(-) diff --git a/db/mysql-with-inserts.sql b/db/mysql-with-inserts.sql index 147500d..39b3f7a 100644 --- a/db/mysql-with-inserts.sql +++ b/db/mysql-with-inserts.sql @@ -14,6 +14,14 @@ CREATE TABLE `daaexample`.`users` ( PRIMARY KEY (`login`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `daaexample`.`pets`( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `owner_id` int NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`owner_id`) REFERENCES `people`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CREATE USER 'daa'@'localhost' IDENTIFIED BY 'daa'; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost'; diff --git a/db/mysql.sql b/db/mysql.sql index fc0f895..4853990 100644 --- a/db/mysql.sql +++ b/db/mysql.sql @@ -14,5 +14,13 @@ CREATE TABLE `daaexample`.`users` ( PRIMARY KEY (`login`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `daaexample`.`pets`( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `owner_id` int NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`owner_id`) REFERENCES `people`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + CREATE USER 'daa'@'localhost' IDENTIFIED BY 'daa'; GRANT ALL ON `daaexample`.* TO 'daa'@'localhost'; diff --git a/src/main/java/es/uvigo/esei/daa/DAAExampleApplication.java b/src/main/java/es/uvigo/esei/daa/DAAExampleApplication.java index 2a67f22..18f4b96 100644 --- a/src/main/java/es/uvigo/esei/daa/DAAExampleApplication.java +++ b/src/main/java/es/uvigo/esei/daa/DAAExampleApplication.java @@ -11,6 +11,7 @@ import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; import es.uvigo.esei.daa.rest.PeopleResource; +import es.uvigo.esei.daa.rest.PetsResource; import es.uvigo.esei.daa.rest.UsersResource; /** @@ -26,7 +27,8 @@ public class DAAExampleApplication extends Application { public Set> getClasses() { return Stream.of( PeopleResource.class, - UsersResource.class + UsersResource.class, + PetsResource.class ).collect(toSet()); } diff --git a/src/main/java/es/uvigo/esei/daa/dao/PeopleDAO.java b/src/main/java/es/uvigo/esei/daa/dao/PeopleDAO.java index 1d99edb..858ca03 100644 --- a/src/main/java/es/uvigo/esei/daa/dao/PeopleDAO.java +++ b/src/main/java/es/uvigo/esei/daa/dao/PeopleDAO.java @@ -1,10 +1,10 @@ package es.uvigo.esei.daa.dao; +import java.sql.Statement; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import java.util.LinkedList; import java.util.List; import java.util.logging.Level; diff --git a/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java b/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java index 09b8834..9c4fdc7 100644 --- a/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java +++ b/src/main/java/es/uvigo/esei/daa/rest/PeopleResource.java @@ -17,6 +17,7 @@ import javax.ws.rs.core.Response; import es.uvigo.esei.daa.dao.DAOException; import es.uvigo.esei.daa.dao.PeopleDAO; import es.uvigo.esei.daa.entities.Person; +import es.uvigo.esei.daa.dao.PetsDAO; /** * REST resource for managing people. @@ -34,11 +35,11 @@ public class PeopleResource { * Constructs a new instance of {@link PeopleResource}. */ public PeopleResource() { - this(new PeopleDAO()); + this(new PeopleDAO(), new PetsDAO()); } // Needed for testing purposes - PeopleResource(PeopleDAO dao) { + PeopleResource(PeopleDAO dao, PetsDAO petsDao) { this.dao = dao; } diff --git a/src/main/webapp/js/view/people.js b/src/main/webapp/js/view/people.js index 802d6b2..f4c5615 100644 --- a/src/main/webapp/js/view/people.js +++ b/src/main/webapp/js/view/people.js @@ -105,6 +105,13 @@ var PeopleView = (function() { ); } }; + + this.listPets = function(id){ + var person = this.getPersonInRow(id); + var petsView = new PetsView(new PetsDAO(id), 'modal-pets', person.name + ' ' + person.surname); + petsView.init(); + $('#modal-pets').modal('show'); + }; this.isEditing = function() { return $(formQuery + ' input[name="id"]').val() != ""; @@ -166,6 +173,7 @@ var PeopleView = (function() { ' + person.name + '\ ' + person.surname + '\ \ + Mascotas\ Editar\ Eliminar\ \ @@ -184,6 +192,10 @@ var PeopleView = (function() { $('#person-' + person.id + ' a.delete').click(function() { self.deletePerson(person.id); }); + + $('#person-' + person.id + ' a.pets').click(function() { + self.listPets(person.id); + }); }; var appendToTable = function(person) { diff --git a/src/main/webapp/main.html b/src/main/webapp/main.html index c2e28f1..788638c 100644 --- a/src/main/webapp/main.html +++ b/src/main/webapp/main.html @@ -26,10 +26,32 @@ + + + + +