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
840c9f07
authored
Feb 23, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [RecursosController]: Implementadas las funciones para las búsquedas en el controlador
parent
96261045
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/rest/RecursosController.java
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/RecursosController.java
View file @
840c9f07
package
com
.
ujaen
.
tfg
.
mangaffinity
.
rest
;
package
com
.
ujaen
.
tfg
.
mangaffinity
.
rest
;
import
com.ujaen.tfg.mangaffinity.entidades.Genero
;
import
com.ujaen.tfg.mangaffinity.entidades.Recurso
;
import
com.ujaen.tfg.mangaffinity.entidades.Recurso
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTORecurso
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.DTORecurso
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.Mapper
;
import
com.ujaen.tfg.mangaffinity.rest.DTO.Mapper
;
...
@@ -10,6 +11,11 @@ import org.springframework.http.HttpStatus;
...
@@ -10,6 +11,11 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.time.LocalDate
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RestController
@RequestMapping
(
"/recursos"
)
@RequestMapping
(
"/recursos"
)
public
class
RecursosController
{
public
class
RecursosController
{
...
@@ -29,4 +35,43 @@ public class RecursosController {
...
@@ -29,4 +35,43 @@ public class RecursosController {
return
ResponseEntity
.
status
(
HttpStatus
.
UNAUTHORIZED
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
UNAUTHORIZED
).
build
();
}
}
}
}
@GetMapping
(
"/titulo/{titulo}"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
buscarPorTitulo
(
@PathVariable
String
titulo
)
{
List
<
Recurso
>
recursos
=
servicioRecursos
.
buscarRecursoPorTitulo
(
titulo
);
if
(
recursos
.
isEmpty
())
{
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
(
Collections
.
emptyList
());
}
return
ResponseEntity
.
ok
(
recursos
.
stream
().
map
(
mapper:
:
dto
).
toList
());
}
@GetMapping
(
"/genero/{genero}"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
buscarPorGenero
(
@PathVariable
Genero
genero
)
{
List
<
Recurso
>
recursos
=
servicioRecursos
.
buscarRecursoPorGenero
(
genero
);
if
(
recursos
.
isEmpty
())
{
return
ResponseEntity
.
ok
(
Collections
.
emptyList
());
// ✅ Devuelve []
}
return
ResponseEntity
.
ok
(
recursos
.
stream
().
map
(
mapper:
:
dto
).
toList
());
}
@GetMapping
(
"/fecha"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
buscarPorRangoFechas
(
@RequestParam
LocalDate
inicio
,
@RequestParam
LocalDate
fin
)
{
List
<
Recurso
>
recursos
=
servicioRecursos
.
buscarRecursoPorRangoFechas
(
inicio
,
fin
);
if
(
recursos
.
isEmpty
())
{
return
ResponseEntity
.
ok
(
Collections
.
emptyList
());
// ✅ Devuelve []
}
return
ResponseEntity
.
ok
(
recursos
.
stream
().
map
(
mapper:
:
dto
).
toList
());
}
@GetMapping
(
"/autor/{autor}"
)
public
ResponseEntity
<
List
<
DTORecurso
>>
buscarPorAutor
(
@PathVariable
String
autor
)
{
List
<
Recurso
>
recursos
=
servicioRecursos
.
buscarRecursoPorAutor
(
autor
);
if
(
recursos
.
isEmpty
())
{
return
ResponseEntity
.
ok
(
Collections
.
emptyList
());
// ✅ Devuelve []
}
return
ResponseEntity
.
ok
(
recursos
.
stream
().
map
(
mapper:
:
dto
).
toList
());
}
}
}
\ No newline at end of file
src/main/java/com/ujaen/tfg/mangaffinity/seguridad/ServicioSeguridad.java
View file @
840c9f07
...
@@ -30,6 +30,10 @@ public class ServicioSeguridad {
...
@@ -30,6 +30,10 @@ public class ServicioSeguridad {
.
authorizeHttpRequests
(
request
->
request
.
authorizeHttpRequests
(
request
->
request
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/{email}"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/usuarios/"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/titulo/**"
).
permitAll
()
// 🔓 Permitir búsquedas
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/autor/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/genero/**"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
GET
,
"/recursos/fecha"
).
permitAll
()
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/"
).
hasAuthority
(
"ROLE_ADMIN"
)
// <--- Aquí usamos ROLE_ADMIN
.
requestMatchers
(
HttpMethod
.
POST
,
"/recursos/"
).
hasAuthority
(
"ROLE_ADMIN"
)
// <--- Aquí usamos ROLE_ADMIN
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
)
)
...
...
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