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
4da14105
authored
Feb 24, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [BibliotecaPersonalController]: Creadas funciones en el controlador con su test
parent
25ef7c1b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/BibliotecaPersonalController.java
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestBibliotecaPersonalController.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/BibliotecaPersonalController.java
View file @
4da14105
...
@@ -50,16 +50,24 @@ public class BibliotecaPersonalController {
...
@@ -50,16 +50,24 @@ public class BibliotecaPersonalController {
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
}
boolean
yaExiste
=
servicioBibliotecaPersonal
.
listarPorCategoria
(
biblioteca
.
getId
(),
dtoRecursoEnBiblioteca
.
getCategoria
())
.
stream
()
.
anyMatch
(
bpr
->
bpr
.
getRecurso
().
getId
().
equals
(
recursoId
));
if
(
yaExiste
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
CONFLICT
).
build
();
}
servicioBibliotecaPersonal
.
anadirRecursoBiblioteca
(
biblioteca
,
recurso
,
dtoRecursoEnBiblioteca
.
getCategoria
());
servicioBibliotecaPersonal
.
anadirRecursoBiblioteca
(
biblioteca
,
recurso
,
dtoRecursoEnBiblioteca
.
getCategoria
());
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
build
();
}
catch
(
RecursoNoExiste
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
}
}
@GetMapping
(
"/{usuarioId}/recursos/categoria/{categoria}"
)
@GetMapping
(
"/{usuarioId}/recursos/categoria/{categoria}"
)
public
ResponseEntity
<
List
<
DTORecursoEnBiblioteca
>>
listarRecursosPorCategoria
(
@PathVariable
Long
usuarioId
,
@PathVariable
Categoria
categoria
)
{
public
ResponseEntity
<
List
<
DTORecursoEnBiblioteca
>>
listarRecursosPorCategoria
(
@PathVariable
Long
usuarioId
,
@PathVariable
Categoria
categoria
)
{
try
{
try
{
...
@@ -89,7 +97,7 @@ public class BibliotecaPersonalController {
...
@@ -89,7 +97,7 @@ public class BibliotecaPersonalController {
}
}
servicioBibliotecaPersonal
.
eliminarRecurso
(
biblioteca
.
getId
(),
recursoId
);
servicioBibliotecaPersonal
.
eliminarRecurso
(
biblioteca
.
getId
(),
recursoId
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
b
ody
(
"Recurso eliminado correctamente"
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
b
uild
(
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
build
();
}
}
...
@@ -107,7 +115,7 @@ public class BibliotecaPersonalController {
...
@@ -107,7 +115,7 @@ public class BibliotecaPersonalController {
servicioBibliotecaPersonal
.
modificarCategoria
(
biblioteca
.
getId
(),
recursoId
,
dtoRecurso
.
getCategoria
());
servicioBibliotecaPersonal
.
modificarCategoria
(
biblioteca
.
getId
(),
recursoId
,
dtoRecurso
.
getCategoria
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
b
ody
(
"Error interno"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
b
uild
(
);
}
}
}
}
...
...
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
View file @
4da14105
...
@@ -28,6 +28,7 @@ public class ServicioSeguridad {
...
@@ -28,6 +28,7 @@ public class ServicioSeguridad {
.
httpBasic
(
httpBasic
->
httpBasic
.
realmName
(
"mangaffinity"
))
.
httpBasic
(
httpBasic
->
httpBasic
.
realmName
(
"mangaffinity"
))
.
authorizeHttpRequests
(
request
->
request
.
authorizeHttpRequests
(
request
->
request
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/usuarios/email/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/titulo/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/titulo/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/autor/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/autor/**"
).
permitAll
()
...
@@ -40,12 +41,13 @@ public class ServicioSeguridad {
...
@@ -40,12 +41,13 @@ public class ServicioSeguridad {
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/recursos/{id}"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/{id}/capitulos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/{id}/capitulos"
).
hasAuthority
(
"ROLE_ADMIN"
)
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}/capitulos"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/{id}/capitulos"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/usuarios/{usuarioId}/biblioteca"
).
permitAll
()
// 🔹 Protección de las rutas de la biblioteca (solo usuarios autenticados)
.
requestMatchers
(
HttpMethod
.
POST
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/biblioteca/{usuarioId}/recursos/categoria/{categoria}"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/biblioteca/{usuarioId}/recursos/categoria/{categoria}"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/biblioteca/{usuarioId}/recursos/{recursoId}"
).
authenticated
()
// ✅ Nueva regla
.
requestMatchers
(
HttpMethod
.
DELETE
,
"/biblioteca/{usuarioId}/recursos/{recursoId}"
).
authenticated
()
.
requestMatchers
(
HttpMethod
.
PUT
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
// ✅ Nueva regla
.
requestMatchers
(
HttpMethod
.
PUT
,
"/biblioteca/{usuarioId}/recursos/{recursoId}/categoria"
).
authenticated
()
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
)
)
...
...
src/test/java/com/ujaen/tfg/mangaffinity/rest/TestBibliotecaPersonalController.java
View file @
4da14105
This diff is collapsed.
Click to expand it.
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