refactor: 메서드 분리

This commit is contained in:
shinmj
2021-12-30 21:55:00 +09:00
parent e57fdea7a3
commit 90f0777802

View File

@@ -70,11 +70,7 @@ public class PolicyService extends AbstractService {
*/
@Transactional(readOnly = true)
public PolicyResponseDto findById(Long id) {
Policy policy = policyRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
Policy policy = findPolicy(id);
return new PolicyResponseDto(policy);
}
@@ -96,8 +92,7 @@ public class PolicyService extends AbstractService {
* @return
*/
public Long update(Long id, PolicyUpdateRequestDto updateRequestDto) {
Policy policy = policyRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
Policy policy = findPolicy(id);
policy.update(updateRequestDto.getTitle(), updateRequestDto.getIsUse(), updateRequestDto.getContents());
@@ -110,8 +105,7 @@ public class PolicyService extends AbstractService {
* @param id
*/
public void delete(Long id) {
Policy policy = policyRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
Policy policy = findPolicy(id);
policyRepository.delete(policy);
}
@@ -123,14 +117,18 @@ public class PolicyService extends AbstractService {
* @return
*/
public Long updateIsUse(Long id, boolean isUse) {
Policy policy = policyRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
Policy policy = findPolicy(id);
policy.updateIsUSe(isUse);
return id;
}
private Policy findPolicy(Long id) {
return policyRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
}
}