Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alvaro Ordóñez Romero
/
DAE-aha00026-aor00039
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7450594b
authored
Nov 08, 2023
by
Alvaro Ordóñez Romero
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Modificación clase Usuario
parent
64600afb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
src/main/java/com/carpooling/carpoolingaoraha/entidades/Usuario.java
src/main/java/com/carpooling/carpoolingaoraha/entidades/Usuario.java
View file @
7450594b
...
@@ -24,7 +24,7 @@ public class Usuario {
...
@@ -24,7 +24,7 @@ public class Usuario {
private
int
telefono
;
private
int
telefono
;
private
String
email
;
private
String
email
;
private
String
claveAcceso
;
private
String
claveAcceso
;
private
int
puntuacion
;
private
ArrayList
<
Integer
>
puntuacion
;
private
Rol
rol
;
private
Rol
rol
;
@Transient
@Transient
private
ArrayList
<
Integer
>
viajesOfertados
;
private
ArrayList
<
Integer
>
viajesOfertados
;
...
@@ -41,7 +41,7 @@ public class Usuario {
...
@@ -41,7 +41,7 @@ public class Usuario {
this
.
telefono
=
telefono
;
this
.
telefono
=
telefono
;
this
.
email
=
email
;
this
.
email
=
email
;
this
.
claveAcceso
=
claveAcceso
;
this
.
claveAcceso
=
claveAcceso
;
this
.
puntuacion
=
0
;
this
.
puntuacion
=
new
ArrayList
<>()
;
this
.
rol
=
rol
;
this
.
rol
=
rol
;
if
(
rol
==
CONDUCTOR
){
if
(
rol
==
CONDUCTOR
){
this
.
viajesOfertados
=
new
ArrayList
<>();
this
.
viajesOfertados
=
new
ArrayList
<>();
...
@@ -213,4 +213,22 @@ public class Usuario {
...
@@ -213,4 +213,22 @@ public class Usuario {
return
viajesDisponibles
;
return
viajesDisponibles
;
}
}
public
void
actualizarPuntuacion
(
Usuario
usuario
,
int
nuevaPuntuacion
)
{
// Carga el usuario desde la base de datos
Usuario
usuarioExistente
=
usuarioRepository
.
findById
(
usuario
.
getId
()).
orElse
(
null
);
if
(
usuarioExistente
!=
null
)
{
// Agrega la nueva puntuación
usuarioExistente
.
getPuntuaciones
().
add
(
nuevaPuntuacion
);
// Calcula la puntuación media
List
<
Integer
>
puntuaciones
=
usuarioExistente
.
getPuntuaciones
();
double
puntuacionMedia
=
puntuaciones
.
stream
().
mapToInt
(
Integer:
:
intValue
).
average
().
orElse
(
0.0
);
usuarioExistente
.
setPuntuacionMedia
(
puntuacionMedia
);
// Guarda el usuario actualizado (sin duplicar)
usuarioRepository
.
save
(
usuarioExistente
);
}
}
}
}
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