Files
pmu-bet-engine/src/main/java/com/pmu/betengine/controller/RoleController.java
2025-11-25 17:07:27 +00:00

47 lines
1.3 KiB
Java

package com.pmu.betengine.controller;
import com.pmu.betengine.model.Role;
import com.pmu.betengine.service.RoleService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/v1/roles")
@CrossOrigin
public class RoleController {
private final RoleService roleService;
public RoleController(RoleService roleService) {
this.roleService = roleService;
}
@PostMapping
public ResponseEntity<Role> create(@RequestBody Role role) {
return ResponseEntity.ok(roleService.create(role));
}
@PutMapping("/{id}")
public ResponseEntity<Role> update(@PathVariable Long id, @RequestBody Role role) {
return ResponseEntity.ok(roleService.update(id, role));
}
@GetMapping("/{id}")
public ResponseEntity<Role> getById(@PathVariable Long id) {
return ResponseEntity.ok(roleService.getById(id));
}
@GetMapping
public ResponseEntity<List<Role>> getAll() {
return ResponseEntity.ok(roleService.getAll());
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
roleService.delete(id);
return ResponseEntity.noContent().build();
}
}