add: resController
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled

This commit is contained in:
2026-02-14 12:46:58 -04:00
parent 8890b72f19
commit 5f1c8f93fd

View File

@@ -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);
}
}