UpdateComment update comment
(ctx context.Context, req *schema.UpdateCommentReq)
| 301 | |
| 302 | // UpdateComment update comment |
| 303 | func (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 |
| 343 | func (cs *CommentService) GetComment(ctx context.Context, req *schema.GetCommentReq) (resp *schema.GetCommentResp, err error) { |
no test coverage detected