TA 역할 Spring 경계 smoke #3

Open
forge-bot wants to merge 9 commits from forge/role-ta-live-1522-001-attempt-1-run-6e84b72613b1 into main
Showing only changes of commit ae4f99668d - Show all commits

View file

@ -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<RoleResponse> 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<RoleResponse> getRole(@PathVariable String roleId) {
return ResponseEntity.ok(RoleResponse.from(roleService.getRole(roleId)));
}
@GetMapping
public ResponseEntity<List<RoleResponse>> getAllRoles() {
return ResponseEntity.ok(roleService.getAllRoles().stream()
.map(RoleResponse::from).toList());
}
@PutMapping("/{roleId}")
public ResponseEntity<RoleResponse> 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<Void> deleteRole(@PathVariable String roleId) {
roleService.deleteRole(roleId);
return ResponseEntity.noContent().build();
}
}