Skip to content

Commit

Permalink
[refactor] : 검증로직 함수 추출
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun2371 committed Jan 10, 2025
1 parent 93f24f6 commit fd7b8cd
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ public UpdateQuestionPostResponse updateQuestionPost(
@Transactional
public DeleteQuestionPostResponse deleteQuestionPost(
Long questionPostId
){
) {
QuestionPost questionPost = questionPostRepository.findById(questionPostId)
.orElseThrow(() -> new NotFoundException(QuestionPostErrorCode.NOT_FOUND_QUESTION_POST));
if (answerRepository.existsByQuestionPostId(questionPostId)) {
throw new ValidationException(QuestionPostErrorCode.CAN_NOT_DELETE_QUESTION_POST);
}
validateIfQuestionPostExists(questionPostId);
refundDeletedQuestionPost(questionPost);
questionPostRepository.deleteById(questionPostId);

Expand All @@ -149,6 +147,12 @@ private void updateQuestionPostImages(QuestionPost questionPost, List<String> im
}
}

private void validateIfQuestionPostExists(Long questionPostId) {
if (answerRepository.existsByQuestionPostId(questionPostId)) {
throw new ValidationException(QuestionPostErrorCode.CAN_NOT_DELETE_QUESTION_POST);
}
}

private void deleteImages(QuestionPost questionPost) {
questionPostImageRepository.deleteByQuestionPost(questionPost);
questionPost.clearPostImages();
Expand Down Expand Up @@ -188,7 +192,7 @@ private void refundClosedQuestionPosts() {
});
}

private void saveRefundCreditHistory(Member member, int reward){
private void saveRefundCreditHistory(Member member, int reward) {
memberRepository.save(member);

creditHistoryService.saveCreditHistory(
Expand Down

0 comments on commit fd7b8cd

Please sign in to comment.