add: resController
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.example.fercoganbackend.controller;
|
||||
|
||||
import com.example.fercoganbackend.entity.Roles;
|
||||
import com.example.fercoganbackend.repository.RolesRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/roles")
|
||||
public class RolesController {
|
||||
|
||||
final RolesRepository rolesRepository;
|
||||
|
||||
RolesController(RolesRepository rolesRepository){
|
||||
this.rolesRepository=rolesRepository;
|
||||
}
|
||||
public List<Roles> getRoles(){
|
||||
return rolesRepository.findAll();
|
||||
}
|
||||
|
||||
public Roles setRoles(Roles roles){
|
||||
return rolesRepository.save(roles);
|
||||
}
|
||||
@PutMapping("/{id}")
|
||||
public Roles updateRoles(@PathVariable Long id, @RequestBody Roles updatedRole) {
|
||||
|
||||
Roles role = rolesRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Rol no encontrado"));
|
||||
|
||||
role.setName(updatedRole.getName());
|
||||
|
||||
return rolesRepository.save(role);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user