Skip to content

Commit

Permalink
Merge pull request #145 from songhee1/feature/#144-discussion
Browse files Browse the repository at this point in the history
Feat : ๋Œ€๋Œ“๊ธ€ ์‚ญ์ œ ๋ฒ„๊ทธ ์ˆ˜์ •(#144)
  • Loading branch information
songhee1 authored Feb 12, 2024
2 parents f85f6d9 + 19caa92 commit fbe0286
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,10 @@ public BaseResponse<String> deleteComment(@PathVariable Long subjectId,
@ApiImplicitParam(name = "commentId", value = "ํ† ๋ก  ๋Œ“๊ธ€์˜ id", required = true, paramType = "path"),
@ApiImplicitParam(name = "recommentId", value = "ํ† ๋ก  ๋Œ€๋Œ“๊ธ€์˜ id", required = true, paramType = "path")
})
@DeleteMapping("/recomment/{subjectId}/{commentId}/{recommentId}")
@DeleteMapping("/recomment/{recommentId}")
public BaseResponse<String> deleteRecomment(
@PathVariable Long subjectId,
@PathVariable Long commentId,
@PathVariable Long recommentId) throws NotFoundException {
replyService.deleteRecomment(subjectId, commentId, recommentId);
replyService.deleteRecomment(recommentId);
return BaseResponse.success("์„ฑ๊ณต์ ์œผ๋กœ ํ† ๋ก ๋Œ€๋Œ“๊ธ€์„ ์‚ญ์ œํ•˜์˜€์Šต๋‹ˆ๋‹ค.");
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tavebalak/OTTify/community/entity/Reply.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ public ReplyCommentEditorDTO toEditor() {
public void edit(ReplyCommentEditorDTO c) {
this.content = c.getComment();
}

public void cancelChildReply(Reply reply) {
if (child.contains(reply)) {
child.remove(reply);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ReplyService {

void deleteComment(Long subjectId, Long commentId);

void deleteRecomment(Long subjectId, Long commentId, Long recommentId);
void deleteRecomment(Long recommentId);

List<CommentDTO> getComment(Long commentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tavebalak.OTTify.error.exception.UnauthorizedException;
import tavebalak.OTTify.oauth.jwt.SecurityUtil;
import tavebalak.OTTify.user.entity.User;
import tavebalak.OTTify.user.repository.LikedReplyRepository;
import tavebalak.OTTify.user.repository.UserRepository;

@Service
Expand All @@ -34,6 +35,7 @@ public class ReplyServiceImpl implements ReplyService {
private final CommunityRepository communityRepository;
private final ReplyRepository replyRepository;
private final UserRepository userRepository;
private final LikedReplyRepository likedReplyRepository;

@Override
public Reply saveComment(ReplyCommentCreateDTO c) {
Expand Down Expand Up @@ -126,18 +128,14 @@ public void deleteComment(Long subjectId, Long commentId) {
throw new BadRequestException(ErrorCode.CAN_NOT_OTHER_COMMENT_DELETE_REQUEST);
}

likedReplyRepository.deleteAllByReply(savedReply);
replyRepository.delete(savedReply);

}

@Override
public void deleteRecomment(Long subjectId, Long commentId, Long recommentId) {
communityRepository.findById(subjectId).orElseThrow(
() -> new NotFoundException(ErrorCode.COMMUNITY_NOT_FOUND)
);
replyRepository.findById(commentId).orElseThrow(
() -> new NotFoundException(ErrorCode.REPLY_NOT_FOUND)
);
public void deleteRecomment(Long recommentId) {

Reply savedReply = replyRepository.findById(recommentId).orElseThrow(
() -> new NotFoundException(ErrorCode.REPLY_NOT_FOUND)
);
Expand All @@ -146,7 +144,10 @@ public void deleteRecomment(Long subjectId, Long commentId, Long recommentId) {
throw new BadRequestException(ErrorCode.CAN_NOT_OTHER_COMMENT_DELETE_REQUEST);
}

replyRepository.delete(savedReply);
Reply parent = savedReply.getParent();
parent.cancelChildReply(savedReply);

likedReplyRepository.deleteAllByReply(savedReply);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import tavebalak.OTTify.community.entity.Reply;
import tavebalak.OTTify.user.entity.LikedReply;

public interface LikedReplyRepository extends JpaRepository<LikedReply, Long> {

Optional<LikedReply> findByUserIdAndReplyIdAndCommunityId(Long userId, Long replyId, Long communityId);
Optional<LikedReply> findByUserIdAndReplyIdAndCommunityId(Long userId, Long replyId,
Long communityId);

List<LikedReply> findByCommunityIdAndReplyId(Long communityId, Long replyId);

int countByCommunityId(Long communityId);

void deleteAllByReply(Reply reply);
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void getFailBadIdTestRecommentContent() throws Exception, NotFoundExcepti
@DisplayName("DELETE ํ† ๋ก  ๋Œ€๋Œ“๊ธ€ ์‚ญ์ œ ์ปจํŠธ๋กค๋Ÿฌ ์„ฑ๊ณต")
public void ๋Œ€๋Œ“๊ธ€_์‚ญ์ œ_์„ฑ๊ณต() throws NotFoundException, Exception {
//given
doNothing().when(replyService).deleteRecomment(anyLong(), anyLong(), anyLong());
doNothing().when(replyService).deleteRecomment(anyLong());

//when
ResultActions resultActions = mockMvc.perform(
Expand Down

0 comments on commit fbe0286

Please sign in to comment.