mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package impl
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-sonic/sonic/consts"
|
|
"github.com/go-sonic/sonic/dal"
|
|
"github.com/go-sonic/sonic/model/entity"
|
|
"github.com/go-sonic/sonic/model/param"
|
|
"github.com/go-sonic/sonic/service"
|
|
)
|
|
|
|
type journalCommentServiceImpl struct {
|
|
service.BaseCommentService
|
|
}
|
|
|
|
func NewJournalCommentService(baseCommentService service.BaseCommentService) service.JournalCommentService {
|
|
return &journalCommentServiceImpl{
|
|
BaseCommentService: baseCommentService,
|
|
}
|
|
}
|
|
|
|
func (j *journalCommentServiceImpl) CountByStatusAndJournalID(ctx context.Context, status consts.CommentStatus, journalIDs []int32) (map[int32]int64, error) {
|
|
return j.CountByStatusAndContentIDs(ctx, status, journalIDs)
|
|
}
|
|
|
|
func (j *journalCommentServiceImpl) UpdateBy(ctx context.Context, commentID int32, commentParam *param.Comment) (*entity.Comment, error) {
|
|
if commentID == 0 {
|
|
return nil, nil
|
|
}
|
|
comment := j.BaseCommentService.ConvertParam(commentParam)
|
|
comment.ID = commentID
|
|
return j.BaseCommentService.Update(ctx, comment)
|
|
}
|
|
|
|
func (j *journalCommentServiceImpl) CountByStatus(ctx context.Context, status consts.CommentStatus) (int64, error) {
|
|
commentDAL := dal.GetQueryByCtx(ctx).Comment
|
|
count, err := commentDAL.WithContext(ctx).Where(commentDAL.Type.Eq(consts.CommentTypeJournal), commentDAL.Status.Eq(status)).Count()
|
|
if err != nil {
|
|
return 0, WrapDBErr(err)
|
|
}
|
|
return count, nil
|
|
}
|