From bc492baab30808c504403013aa38b6da933721d7 Mon Sep 17 00:00:00 2001 From: forge-bot Date: Tue, 14 Jul 2026 06:58:59 +0000 Subject: [PATCH] =?UTF-8?q?TA=20=EC=97=AD=ED=95=A0=20Spring=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=84=20smoke=20(role-ta-live-1522-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/service/RoleMatrixService.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main/java/com/klaroworks/runtime/service/RoleMatrixService.java diff --git a/src/main/java/com/klaroworks/runtime/service/RoleMatrixService.java b/src/main/java/com/klaroworks/runtime/service/RoleMatrixService.java new file mode 100644 index 0000000..e473322 --- /dev/null +++ b/src/main/java/com/klaroworks/runtime/service/RoleMatrixService.java @@ -0,0 +1,53 @@ +package com.klaroworks.runtime.service; + +import com.klaroworks.runtime.dto.RoleCreateRequest; +import com.klaroworks.runtime.dto.RoleResponse; +import com.klaroworks.runtime.entity.Role; +import com.klaroworks.runtime.exception.DuplicateResourceException; +import com.klaroworks.runtime.exception.RoleNotFoundException; +import com.klaroworks.runtime.repository.RoleRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class RoleMatrixService { + + private final RoleRepository roleRepository; + + @Transactional + public RoleResponse createRole(RoleCreateRequest request) { + if (roleRepository.existsByName(request.getName())) { + throw new DuplicateResourceException("Role", request.getName()); + } + Role role = Role.create(request.getName(), request.getDescription()); + return RoleResponse.from(roleRepository.save(role)); + } + + public RoleResponse getRoleById(Long id) { + return roleRepository.findById(id) + .map(RoleResponse::from) + .orElseThrow(() -> new RoleNotFoundException(id)); + } + + public List getAllRoles() { + return roleRepository.findAll().stream().map(RoleResponse::from).toList(); + } + + @Transactional + public RoleResponse updateRole(Long id, RoleCreateRequest request) { + Role role = roleRepository.findById(id) + .orElseThrow(() -> new RoleNotFoundException(id)); + role.update(request.getName(), request.getDescription()); + return RoleResponse.from(role); + } + + @Transactional + public void deleteRole(Long id) { + if (!roleRepository.existsById(id)) throw new RoleNotFoundException(id); + roleRepository.deleteById(id); + } +}