TA 역할 Spring 경계 smoke (role-ta-live-1522-001)
This commit is contained in:
parent
e110ee1836
commit
ae4f99668d
1 changed files with 61 additions and 0 deletions
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue