diff --git a/src/main/java/com/runtimematrix/controller/RoleController.java b/src/main/java/com/runtimematrix/controller/RoleController.java new file mode 100644 index 0000000..ea78029 --- /dev/null +++ b/src/main/java/com/runtimematrix/controller/RoleController.java @@ -0,0 +1,61 @@ +package com.runtimematrix.controller; + +import com.runtimematrix.controller.dto.RoleResponse; +import com.runtimematrix.domain.model.Role; +import com.runtimematrix.service.RoleService; +import com.runtimematrix.service.command.CreateRoleCommand; +import com.runtimematrix.service.command.UpdateRoleCommand; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.net.URI; +import java.util.List; + +/** + * 역할 관리 REST 컨트롤러. + * ADR-001 Controller 경계: HTTP 처리, 검증, DTO 변환만 수행. 비즈니스 로직 없음. + */ +@RestController +@RequestMapping("/api/v1/roles") +public class RoleController { + + private final RoleService roleService; + + public RoleController(RoleService roleService) { + this.roleService = roleService; + } + + @PostMapping + public ResponseEntity createRole(@Valid @RequestBody CreateRoleRequest request) { + CreateRoleCommand command = new CreateRoleCommand(request.name(), request.description()); + Role created = roleService.createRole(command); + return ResponseEntity.created(URI.create("/api/v1/roles/" + created.getId())) + .body(RoleResponse.from(created)); + } + + @GetMapping("/{roleId}") + public ResponseEntity getRole(@PathVariable String roleId) { + return ResponseEntity.ok(RoleResponse.from(roleService.getRole(roleId))); + } + + @GetMapping + public ResponseEntity> getAllRoles() { + return ResponseEntity.ok(roleService.getAllRoles().stream() + .map(RoleResponse::from).toList()); + } + + @PutMapping("/{roleId}") + public ResponseEntity updateRole( + @PathVariable String roleId, + @Valid @RequestBody UpdateRoleRequest request) { + UpdateRoleCommand command = new UpdateRoleCommand(request.name(), request.description()); + return ResponseEntity.ok(RoleResponse.from(roleService.updateRole(roleId, command))); + } + + @DeleteMapping("/{roleId}") + public ResponseEntity deleteRole(@PathVariable String roleId) { + roleService.deleteRole(roleId); + return ResponseEntity.noContent().build(); + } +}