refactor: 메서드 분리
This commit is contained in:
@@ -70,11 +70,7 @@ public class PolicyService extends AbstractService {
|
|||||||
*/
|
*/
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public PolicyResponseDto findById(Long id) {
|
public PolicyResponseDto findById(Long id) {
|
||||||
Policy policy = policyRepository.findById(id)
|
Policy policy = findPolicy(id);
|
||||||
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return new PolicyResponseDto(policy);
|
return new PolicyResponseDto(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +92,7 @@ public class PolicyService extends AbstractService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long update(Long id, PolicyUpdateRequestDto updateRequestDto) {
|
public Long update(Long id, PolicyUpdateRequestDto updateRequestDto) {
|
||||||
Policy policy = policyRepository.findById(id)
|
Policy policy = findPolicy(id);
|
||||||
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
|
|
||||||
|
|
||||||
policy.update(updateRequestDto.getTitle(), updateRequestDto.getIsUse(), updateRequestDto.getContents());
|
policy.update(updateRequestDto.getTitle(), updateRequestDto.getIsUse(), updateRequestDto.getContents());
|
||||||
|
|
||||||
@@ -110,8 +105,7 @@ public class PolicyService extends AbstractService {
|
|||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
Policy policy = policyRepository.findById(id)
|
Policy policy = findPolicy(id);
|
||||||
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
|
|
||||||
policyRepository.delete(policy);
|
policyRepository.delete(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,14 +117,18 @@ public class PolicyService extends AbstractService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long updateIsUse(Long id, boolean isUse) {
|
public Long updateIsUse(Long id, boolean isUse) {
|
||||||
Policy policy = policyRepository.findById(id)
|
Policy policy = findPolicy(id);
|
||||||
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
|
|
||||||
|
|
||||||
policy.updateIsUSe(isUse);
|
policy.updateIsUSe(isUse);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Policy findPolicy(Long id) {
|
||||||
|
return policyRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("policy")}) + " ID= " + id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user