作者 郑周

1 点赞文章、评论 通知消息

2. 取消点赞          通知消息
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
if err != nil {
return err
}
// 删除点赞文章消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeArticle(c, articleInfo.Id)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
if err != nil {
return err
}
// 删除点赞评论消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
if err != nil {
return err
}
// 创建点赞消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.LikeArticle(c, articleInfo.Id, articleInfo.AuthorId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ... @@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
if err != nil {
return err
}
// 创建点赞消息
var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId)
if err != nil {
return err
}
return nil
}, true)
if err != nil {
... ...
... ... @@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64,
}
// LikeComment 点赞评论
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, 0, commentId, "", []int64{at})
}
// UnLikeArticle 取消点赞文章
func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0)
}
// UnLikeComment 取消点赞评论
func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64) (err error) {
return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId)
}
func (l *MiniBusinessLogic) createMessage(
... ... @@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage(
}
return nil
}
func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64) (err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
queryOption := domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).
MustWithKV("type", domain.MsgTypeLike).
MustWithKV("optType", optType).
MustWithKV("companyId", userToken.CompanyId).
MustWithKV("recipientId", userToken.UserId).
MustWithKV("articleId", articleId).
MustWithKV("commentId", commentId)
_, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return err
}
for i := range list {
_, err = l.svcCtx.MessageBusinessRepository.Delete(l.ctx, conn, list[i])
if err != nil {
return err
}
}
return nil
}
... ...
... ... @@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["type"]; ok {
tx.Where("type = ?", v)
}
if v, ok := queryOptions["optType"]; ok {
tx.Where("opt_type = ?", v)
}
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["recipientId"]; ok {
tx.Where("recipient_id = ?", v)
}
if v, ok := queryOptions["articleId"]; ok {
tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["commentId"]; ok {
tx.Where("comment_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -36,7 +36,7 @@ const (
const (
OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论
OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
)
... ...