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
f0aaca12
authored
Apr 20, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [BibliotecaPersonalController]: Añadidas las funciones para la gestión de favoritos
parent
44d94794
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/BibliotecaPersonalController.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/BibliotecaPersonalController.java
View file @
f0aaca12
...
...
@@ -4,6 +4,8 @@ import com.ujaen.tfg.mangaffinity.entidades.BibliotecaPersonal;
import
com.ujaen.tfg.mangaffinity.entidades.BibliotecaPersonalRecurso
;
import
com.ujaen.tfg.mangaffinity.entidades.Categoria
;
import
com.ujaen.tfg.mangaffinity.entidades.Recurso
;
import
com.ujaen.tfg.mangaffinity.excepciones.NumeroMaximoFavoritos
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTORecurso
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTORecursoEnBiblioteca
;
import
com.ujaen.tfg.mangaffinity.servicios.ServicioBibliotecaPersonal
;
import
com.ujaen.tfg.mangaffinity.servicios.ServicioRecursos
;
...
...
@@ -198,4 +200,70 @@ public class BibliotecaPersonalController {
}
}
@PutMapping
(
"/{usuarioId}/favoritos/{recursoId}"
)
public
ResponseEntity
<
Void
>
anadirAFavoritos
(
@PathVariable
Long
usuarioId
,
@PathVariable
Long
recursoId
)
{
try
{
BibliotecaPersonal
biblioteca
=
servicioUsuarios
.
obtenerBibliotecaDeUsuario
(
usuarioId
);
if
(
biblioteca
==
null
)
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
servicioBibliotecaPersonal
.
anadirFavorito
(
biblioteca
.
getId
(),
recursoId
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
catch
(
NumeroMaximoFavoritos
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
CONFLICT
).
build
();
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
@DeleteMapping
(
"/{usuarioId}/favoritos/{recursoId}"
)
public
ResponseEntity
<
Void
>
eliminarDeFavoritos
(
@PathVariable
Long
usuarioId
,
@PathVariable
Long
recursoId
)
{
try
{
BibliotecaPersonal
biblioteca
=
servicioUsuarios
.
obtenerBibliotecaDeUsuario
(
usuarioId
);
if
(
biblioteca
==
null
)
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
servicioBibliotecaPersonal
.
eliminarFavorito
(
biblioteca
.
getId
(),
recursoId
);
return
ResponseEntity
.
status
(
HttpStatus
.
NO_CONTENT
).
build
();
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
@GetMapping
(
"/{usuarioId}/favoritos"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
obtenerFavoritos
(
@PathVariable
Long
usuarioId
)
{
try
{
BibliotecaPersonal
biblioteca
=
servicioUsuarios
.
obtenerBibliotecaDeUsuario
(
usuarioId
);
if
(
biblioteca
==
null
)
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
List
<
Long
>
ids
=
servicioBibliotecaPersonal
.
obtenerFavoritos
(
biblioteca
.
getId
());
List
<
DTORecurso
>
favoritos
=
ids
.
stream
()
.
map
(
servicioRecursos:
:
buscarRecursoPorId
)
.
filter
(
r
->
r
!=
null
)
.
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
(
favoritos
);
}
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