Skip to content

Commit

Permalink
#385 [feat] 삭제로직 서비스 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
parkheeddong committed Jun 13, 2024
1 parent 95daaa7 commit a21c29a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.config.filter.PrincipalHandler;
import com.mile.dto.SuccessResponse;
import com.mile.exception.message.SuccessMessage;
import com.mile.moim.service.MoimDeleteService;
import com.mile.moim.service.MoimService;
import com.mile.moim.service.dto.BestMoimListResponse;
import com.mile.moim.service.dto.ContentListResponse;
Expand Down Expand Up @@ -57,6 +58,7 @@
public class MoimController implements MoimControllerSwagger {

private final MoimService moimService;
private final MoimDeleteService moimDeleteService;
private final PrincipalHandler principalHandler;

@Override
Expand Down Expand Up @@ -283,9 +285,8 @@ public ResponseEntity<SuccessResponse> deleteMoim(
@MoimIdPathVariable final Long moimId,
@PathVariable("moimId") final String moimUrl
) {
moimService.deleteMoim(moimId, principalHandler.getUserIdFromPrincipal());
moimDeleteService.deleteMoim(moimId, principalHandler.getUserIdFromPrincipal());
return ResponseEntity.ok(SuccessResponse.of(SuccessMessage.MOIM_DELETE_SUCCESS));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.mile.moim.service;

import com.mile.comment.domain.Comment;
import com.mile.comment.service.CommentService;
import com.mile.commentreply.service.CommentReplyService;
import com.mile.curious.service.CuriousService;
import com.mile.moim.domain.Moim;
import com.mile.moim.repository.MoimRepository;
import com.mile.post.domain.Post;
import com.mile.post.service.PostDeleteService;
import com.mile.post.service.PostGetService;
import com.mile.topic.domain.Topic;
import com.mile.topic.service.TopicService;
import com.mile.writername.service.WriterNameDeleteService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@RequiredArgsConstructor
public class MoimDeleteService {

private final MoimService moimService;
private final TopicService topicService;
private final PostGetService postGetService;
private final CommentReplyService commentReplyService;
private final PostDeleteService postDeleteService;
private final CommentService commentService;
private final CuriousService curiousService;
private final MoimRepository moimRepository;
private final WriterNameDeleteService writerNameDeleteService;

@Transactional
public void deleteMoim(
final Long moimId,
final Long userId
) {
moimService.getAuthenticateOwnerOfMoim(moimId, userId);
Moim moim = moimService.findById(moimId);
List<Topic> topics = topicService.findTopicListByMoimId(moimId);
List<Post> posts = postGetService.findAllByTopics(topics);
List<Comment> comments = commentService.findAllByPosts(posts);

commentReplyService.deleteRepliesByComments(comments);
commentService.deleteComments(comments);
curiousService.deleteAllByPosts(posts);
postDeleteService.deletePosts(posts);
topicService.deleteTopics(topics);
writerNameDeleteService.deleteWriterNamesByMoim(moim);
moimRepository.delete(moim);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ public class MoimService {
private final MoimRepository moimRepository;
private final PostDeleteService postDeleteService;
private final PostAuthenticateService postAuthenticateService;
private final CommentReplyService commentReplyService;
private final CuriousService curiousService;
private final PostGetService postGetService;
private final SecureUrlUtil secureUrlUtil;
private final CommentService commentService;
private final WriterNameDeleteService writerNameDeleteService;
private static final int WRITER_NAME_MAX_VALUE = 8;
private static final int MOIM_NAME_MAX_VALUE = 10;
private static final int BEST_MOIM_DEFAULT_NUMBER = 3;
Expand Down Expand Up @@ -255,7 +251,7 @@ public MoimTopicInfoListResponse getMoimTopicList(
return topicService.getTopicListFromMoim(moimId, page);
}

private void getAuthenticateOwnerOfMoim(
public void getAuthenticateOwnerOfMoim(
final Long moimId,
final Long userId
) {
Expand Down Expand Up @@ -366,24 +362,4 @@ public MoimPublicStatusResponse getPublicStatusOfMoim(
return MoimPublicStatusResponse.of(findById(moimId).isPublic());
}

@Transactional
public void deleteMoim(
final Long moimId,
final Long userId
) {
getAuthenticateOwnerOfMoim(moimId, userId);
Moim moim = findById(moimId);
List<Topic> topics = topicService.findTopicListByMoimId(moimId);
List<Post> posts = postGetService.findAllByTopics(topics);
List<Comment> comments = commentService.findAllByPosts(posts);

commentReplyService.deleteRepliesByComments(comments);
commentService.deleteComments(comments);
curiousService.deleteAllByPosts(posts);
postDeleteService.deletePosts(posts);
topicService.deleteTopics(topics);
writerNameDeleteService.deleteWriterNamesByMoim(moim);
moimRepository.delete(moim);

}
}

0 comments on commit a21c29a

Please sign in to comment.