TA 역할 Spring 경계 smoke #7

Open
forge-bot wants to merge 9 commits from forge/role-ta-live-1522-001-attempt-3-run-12d03ada6afe into main
Showing only changes of commit bc492baab3 - Show all commits

View file

@ -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<RoleResponse> 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);
}
}