2022-09-27 17:59:05 +08:00
|
|
|
package comment_common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/reason"
|
|
|
|
"github.com/answerdev/answer/internal/entity"
|
|
|
|
"github.com/answerdev/answer/internal/schema"
|
2022-09-27 17:59:05 +08:00
|
|
|
"github.com/segmentfault/pacman/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CommentCommonRepo comment repository
|
|
|
|
type CommentCommonRepo interface {
|
|
|
|
GetComment(ctx context.Context, commentID string) (comment *entity.Comment, exist bool, err error)
|
2022-11-02 15:50:32 +08:00
|
|
|
GetCommentCount(ctx context.Context) (count int64, err error)
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CommentCommonService user service
|
|
|
|
type CommentCommonService struct {
|
|
|
|
commentRepo CommentCommonRepo
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewCommentCommonService new comment service
|
|
|
|
func NewCommentCommonService(
|
|
|
|
commentRepo CommentCommonRepo) *CommentCommonService {
|
|
|
|
return &CommentCommonService{
|
|
|
|
commentRepo: commentRepo,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetComment get comment one
|
|
|
|
func (cs *CommentCommonService) GetComment(ctx context.Context, commentID string) (resp *schema.GetCommentResp, err error) {
|
|
|
|
comment, exist, err := cs.commentRepo.GetComment(ctx, commentID)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !exist {
|
2023-07-13 16:01:13 +08:00
|
|
|
return nil, errors.BadRequest(reason.CommentNotFound)
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resp = &schema.GetCommentResp{}
|
|
|
|
resp.SetFromComment(comment)
|
|
|
|
return resp, nil
|
|
|
|
}
|