Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
daaexample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alejandro Gómez González
daaexample
Commits
d7612659
Commit
d7612659
authored
Apr 04, 2021
by
Alejandro Gómez González
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing errors and adding comments
parent
2059c645
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
95 additions
and
95 deletions
+95
-95
mysql-with-inserts.sql
db/mysql-with-inserts.sql
+5
-4
mysql.sql
db/mysql.sql
+2
-3
Pet.java
src/main/java/es/uvigo/esei/daa/entities/Pet.java
+1
-1
pets.js
src/main/webapp/js/view/pets.js
+21
-20
main.html
src/main/webapp/main.html
+4
-4
PetDataset.java
src/test/java/es/uvigo/esei/daa/dataset/PetDataset.java
+62
-59
PetUnitTest.java
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
+0
-4
No files found.
db/mysql-with-inserts.sql
View file @
d7612659
...
@@ -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`
)
...
...
db/mysql.sql
View file @
d7612659
...
@@ -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'
;
src/main/java/es/uvigo/esei/daa/entities/Pet.java
View file @
d7612659
...
@@ -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
,
"
Nam
e can't be null"
);
this
.
type
=
requireNonNull
(
type
,
"
Typ
e can't be null"
);
}
}
public
String
getName
()
{
public
String
getName
()
{
...
...
src/main/webapp/js/view/pets.js
View file @
d7612659
...
@@ -35,6 +35,7 @@ var PetView = (function () {
...
@@ -35,6 +35,7 @@ var PetView = (function () {
});
});
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>"
;
...
...
src/main/webapp/main.html
View file @
d7612659
...
@@ -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
(),
...
...
src/test/java/es/uvigo/esei/daa/dataset/PetDataset.java
View file @
d7612659
...
@@ -9,21 +9,24 @@ import java.util.function.Predicate;
...
@@ -9,21 +9,24 @@ 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
()
{}
private
PetDataset
()
{
}
public
static
Pet
[]
pets
()
{
public
static
Pet
[]
pets
()
{
return
new
Pet
[]
{
return
new
Pet
[]
{
new
Pet
(
1
,
"Trotsky"
,
"Perro"
,
1
),
new
Pet
(
1
,
"Trotsky"
,
"Perro"
,
1
),
new
Pet
(
2
,
"Cato"
,
"Gato"
,
2
),
new
Pet
(
2
,
"Cato"
,
"Gato"
,
2
),
new
Pet
(
3
,
"Hiroshi"
,
"Conejo"
,
1
),
new
Pet
(
3
,
"Hiroshi"
,
"Conejo"
,
1
),
new
Pet
(
4
,
"Jael"
,
"Perro"
,
3
)
new
Pet
(
4
,
"Jael"
,
"Perro"
,
3
)
};
};
}
}
public
static
Pet
[]
petsWithout
(
int
...
ids
)
{
public
static
Pet
[]
petsWithout
(
int
...
ids
)
{
Arrays
.
sort
(
ids
);
Arrays
.
sort
(
ids
);
final
Predicate
<
Pet
>
hasValidId
=
pet
->
final
Predicate
<
Pet
>
hasValidId
=
pet
binarySearch
(
ids
,
pet
.
getId
())
<
0
;
->
binarySearch
(
ids
,
pet
.
getId
())
<
0
;
return
stream
(
pets
())
return
stream
(
pets
())
.
filter
(
hasValidId
)
.
filter
(
hasValidId
)
...
@@ -50,7 +53,7 @@ public final class PetDataset {
...
@@ -50,7 +53,7 @@ public final class PetDataset {
}
}
public
static
Pet
nonExistentPet
()
{
public
static
Pet
nonExistentPet
()
{
return
new
Pet
(
nonExistentId
(),
"Lolo"
,
"Vaca"
,
4
);
return
new
Pet
(
nonExistentId
(),
"Lolo"
,
"Vaca"
,
4
);
}
}
public
static
String
newName
()
{
public
static
String
newName
()
{
...
@@ -66,6 +69,6 @@ public final class PetDataset {
...
@@ -66,6 +69,6 @@ public final class PetDataset {
}
}
public
static
Pet
newPet
()
{
public
static
Pet
newPet
()
{
return
new
Pet
(
pets
().
length
+
1
,
newName
(),
newType
(),
newPeopleID
());
return
new
Pet
(
pets
().
length
+
1
,
newName
(),
newType
(),
newPeopleID
());
}
}
}
}
src/test/java/es/uvigo/esei/daa/entities/PetUnitTest.java
View file @
d7612659
...
@@ -36,10 +36,6 @@ public class PetUnitTest {
...
@@ -36,10 +36,6 @@ public class PetUnitTest {
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
()
{
final
int
id
=
1
;
final
int
id
=
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment