MCPcopy Index your code
hub / github.com/apache/answer / UpdateComment

Method UpdateComment

internal/service/comment/comment_service.go:303–340  ·  view source on GitHub ↗

UpdateComment update comment

(ctx context.Context, req *schema.UpdateCommentReq)

Source from the content-addressed store, hash-verified

301
302// UpdateComment update comment
303func (cs *CommentService) UpdateComment(ctx context.Context, req *schema.UpdateCommentReq) (
304 resp *schema.UpdateCommentResp, err error) {
305 old, exist, err := cs.commentCommonRepo.GetComment(ctx, req.CommentID)
306 if err != nil {
307 return nil, err
308 }
309 if !exist {
310 return nil, errors.BadRequest(reason.CommentNotFound)
311 }
312 // user can't edit the comment that was posted by others except admin
313 if !req.IsAdmin && req.UserID != old.UserID {
314 return nil, errors.BadRequest(reason.CommentNotFound)
315 }
316
317 // user can edit the comment that was posted by himself before deadline.
318 // admin can edit it at any time
319 if !req.IsAdmin && (time.Now().After(old.CreatedAt.Add(constant.CommentEditDeadline))) {
320 return nil, errors.BadRequest(reason.CommentCannotEditAfterDeadline)
321 }
322
323 if err = cs.commentRepo.UpdateCommentContent(ctx, old.ID, req.OriginalText, req.ParsedText); err != nil {
324 return nil, err
325 }
326 resp = &schema.UpdateCommentResp{
327 CommentID: old.ID,
328 OriginalText: req.OriginalText,
329 ParsedText: req.ParsedText,
330 }
331 cs.eventQueueService.Send(ctx, schema.NewEvent(constant.EventCommentUpdate, req.UserID).TID(old.ID).
332 CID(old.ID, old.UserID))
333 if old.ObjectID == old.QuestionID {
334 cs.vectorSyncService.Send(ctx, &vector_sync.Task{Action: vector_sync.ActionUpsert, ObjectType: vector_sync.ObjectTypeQuestion, ObjectID: old.QuestionID})
335 } else {
336 cs.vectorSyncService.Send(ctx, &vector_sync.Task{Action: vector_sync.ActionUpsert, ObjectType: vector_sync.ObjectTypeAnswer, ObjectID: old.ObjectID})
337 cs.vectorSyncService.Send(ctx, &vector_sync.Task{Action: vector_sync.ActionUpsert, ObjectType: vector_sync.ObjectTypeQuestion, ObjectID: old.QuestionID})
338 }
339 return resp, nil
340}
341
342// GetComment get comment one
343func (cs *CommentService) GetComment(ctx context.Context, req *schema.GetCommentReq) (resp *schema.GetCommentResp, err error) {

Callers 1

Calls 7

NewEventFunction · 0.92
CIDMethod · 0.80
TIDMethod · 0.80
GetCommentMethod · 0.65
AddMethod · 0.65
UpdateCommentContentMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected