GetComment get comment one
(ctx context.Context, req *schema.GetCommentReq)
| 341 | |
| 342 | // GetComment get comment one |
| 343 | func (cs *CommentService) GetComment(ctx context.Context, req *schema.GetCommentReq) (resp *schema.GetCommentResp, err error) { |
| 344 | comment, exist, err := cs.commentCommonRepo.GetComment(ctx, req.ID) |
| 345 | if err != nil { |
| 346 | return |
| 347 | } |
| 348 | if !exist { |
| 349 | return nil, errors.BadRequest(reason.CommentNotFound) |
| 350 | } |
| 351 | objInfo, err := cs.objectInfoService.GetInfo(ctx, comment.ObjectID) |
| 352 | if err != nil { |
| 353 | return nil, err |
| 354 | } |
| 355 | if err := objInfo.CheckVisibility(req.UserID, req.IsAdminModerator); err != nil { |
| 356 | return nil, err |
| 357 | } |
| 358 | |
| 359 | resp = &schema.GetCommentResp{ |
| 360 | CommentID: comment.ID, |
| 361 | CreatedAt: comment.CreatedAt.Unix(), |
| 362 | UserID: comment.UserID, |
| 363 | ReplyUserID: comment.GetReplyUserID(), |
| 364 | ReplyCommentID: comment.GetReplyCommentID(), |
| 365 | ObjectID: comment.ObjectID, |
| 366 | VoteCount: comment.VoteCount, |
| 367 | OriginalText: comment.OriginalText, |
| 368 | ParsedText: comment.ParsedText, |
| 369 | } |
| 370 | |
| 371 | // get comment user info |
| 372 | if len(resp.UserID) > 0 { |
| 373 | commentUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.UserID) |
| 374 | if err != nil { |
| 375 | return nil, err |
| 376 | } |
| 377 | if exist { |
| 378 | resp.Username = commentUser.Username |
| 379 | resp.UserDisplayName = commentUser.DisplayName |
| 380 | resp.UserAvatar = commentUser.Avatar |
| 381 | resp.UserStatus = commentUser.Status |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // get reply user info |
| 386 | if len(resp.ReplyUserID) > 0 { |
| 387 | replyUser, exist, err := cs.userCommon.GetUserBasicInfoByID(ctx, resp.ReplyUserID) |
| 388 | if err != nil { |
| 389 | return nil, err |
| 390 | } |
| 391 | if exist { |
| 392 | resp.ReplyUsername = replyUser.Username |
| 393 | resp.ReplyUserDisplayName = replyUser.DisplayName |
| 394 | resp.ReplyUserStatus = replyUser.Status |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | // check if current user vote this comment |
| 399 | resp.IsVote = cs.checkIsVote(ctx, req.UserID, resp.CommentID) |
| 400 |
nothing calls this directly
no test coverage detected