Commit fc669a00 by Rubén Ramírez

feat: [RecursosController]:Implementada la función de modificar recurso en el controlador

parent e403fa55
......@@ -121,6 +121,22 @@ public class RecursosController {
}
}
@PutMapping("/{id}")
public ResponseEntity<DTORecurso> modificarRecurso(@PathVariable Long id, @RequestBody DTORecurso dtoRecurso) {
try {
Recurso nuevosDatos = mapper.entity(dtoRecurso);
Recurso recursoModificado = servicioRecursos.modificarRecurso(id, nuevosDatos);
return ResponseEntity.ok(mapper.dto(recursoModificado));
} catch (RecursoNoExiste e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} catch (SecurityException e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
......
......@@ -34,9 +34,11 @@ public class ServicioSeguridad {
.requestMatchers(HttpMethod.GET, "/recursos/autor/**").permitAll()
.requestMatchers(HttpMethod.GET, "/recursos/genero/**").permitAll()
.requestMatchers(HttpMethod.GET, "/recursos/fecha").permitAll()
.requestMatchers(HttpMethod.GET, "/recursos/{id}").permitAll() // ✅ Nueva ruta para buscar por ID
.requestMatchers(HttpMethod.GET, "/recursos/{id}").permitAll()
.requestMatchers(HttpMethod.POST, "/recursos/").hasAuthority("ROLE_ADMIN")
.requestMatchers(HttpMethod.DELETE, "/recursos/{id}").hasAuthority("ROLE_ADMIN") // ✅ Solo admins pueden borrar
.requestMatchers(HttpMethod.PUT, "/recursos/{id}").hasAuthority("ROLE_ADMIN")
.requestMatchers(HttpMethod.DELETE, "/recursos/{id}").hasAuthority("ROLE_ADMIN")
.anyRequest().authenticated()
)
.addFilterBefore(new JwtFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment