Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
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
675e0851
authored
Apr 20, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [UsuariosController]: Añadida la función para obtener las recoemndaciones
parent
5292b214
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/UsuariosController.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/UsuariosController.java
View file @
675e0851
package
com
.
ujaen
.
tfg
.
mangaffinity
.
rest
;
import
com.ujaen.tfg.mangaffinity.entidades.BibliotecaPersonal
;
import
com.ujaen.tfg.mangaffinity.entidades.Recurso
;
import
com.ujaen.tfg.mangaffinity.entidades.Usuario
;
import
com.ujaen.tfg.mangaffinity.excepciones.NombreUsuarioYaCogido
;
import
com.ujaen.tfg.mangaffinity.excepciones.UsuarioNoExiste
;
import
com.ujaen.tfg.mangaffinity.excepciones.UsuarioYaRegistrado
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.*
;
import
com.ujaen.tfg.mangaffinity.servicios.ServicioRecursos
;
import
com.ujaen.tfg.mangaffinity.servicios.ServicioUsuarios
;
import
jakarta.validation.ConstraintViolationException
;
import
jakarta.validation.Valid
;
...
...
@@ -13,7 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"/usuarios"
)
...
...
@@ -21,6 +27,8 @@ public class UsuariosController {
@Autowired
private
ServicioUsuarios
servicioUsuarios
;
@Autowired
private
ServicioRecursos
servicioRecursos
;
@Autowired
private
Mapper
mapper
;
...
...
@@ -142,4 +150,29 @@ public class UsuariosController {
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"error inesperado"
);
}
}
@GetMapping
(
"/{usuarioId}/recomendaciones"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
obtenerRecomendaciones
(
@PathVariable
Long
usuarioId
)
{
try
{
List
<
Recurso
>
recomendados
=
servicioRecursos
.
obtenerRecomendacionesParaUsuario
(
usuarioId
);
List
<
DTORecurso
>
dto
=
recomendados
.
stream
()
.
map
(
r
->
new
DTORecurso
(
r
.
getId
(),
r
.
getTitulo
(),
r
.
getDescripcion
(),
r
.
getFechaPublicacion
(),
r
.
getAutor
(),
(
r
.
getFoto
()
!=
null
)
?
"data:image/jpeg;base64,"
+
Base64
.
getEncoder
().
encodeToString
(
r
.
getFoto
())
:
null
,
r
.
getGeneros
(),
r
.
getMediaEstrellas
()
))
.
collect
(
Collectors
.
toList
());
return
ResponseEntity
.
ok
(
dto
);
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
}
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