Skip to content

Commit 775b2ca

Browse files
committed
Delete child comments when comment deleted
1 parent 86a40bb commit 775b2ca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

code/services/comment-service/src/server.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ func (s *CommentServer) DeleteComment(ctx context.Context, req *commentpb.Delete
160160
return nil, err
161161
}
162162

163+
// find all child comments
164+
comments, err := s.ListComments(ctx, &commentpb.ListCommentsRequest{
165+
ThreadId: &res.Id,
166+
})
167+
if err != nil {
168+
return nil, err
169+
}
170+
171+
// delete child comments
172+
for _, comment := range comments.Comments {
173+
_, err = s.DeleteComment(ctx, &commentpb.DeleteCommentRequest{
174+
Id: comment.Id,
175+
})
176+
if err != nil {
177+
return nil, err
178+
}
179+
}
180+
163181
// delete comment
164182
_, err = s.DBClient.DeleteComment(ctx, &dbpb.DeleteCommentRequest{
165183
Id: req.Id,

0 commit comments

Comments
 (0)