正在显示
4 个修改的文件
包含
85 行增加
和
3 行删除
| @@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "context" | 4 | "context" |
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message" | ||
| 5 | 6 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| @@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | @@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | ||
| 97 | if err != nil { | 98 | if err != nil { |
| 98 | return err | 99 | return err |
| 99 | } | 100 | } |
| 101 | + | ||
| 102 | + // 删除点赞文章消息 | ||
| 103 | + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx) | ||
| 104 | + err = messageLogic.UnLikeArticle(c, articleInfo.Id) | ||
| 105 | + if err != nil { | ||
| 106 | + return err | ||
| 107 | + } | ||
| 108 | + | ||
| 100 | return nil | 109 | return nil |
| 101 | }, true) | 110 | }, true) |
| 102 | if err != nil { | 111 | if err != nil { |
| @@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | @@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | ||
| 170 | if err != nil { | 179 | if err != nil { |
| 171 | return err | 180 | return err |
| 172 | } | 181 | } |
| 182 | + | ||
| 183 | + // 删除点赞评论消息 | ||
| 184 | + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx) | ||
| 185 | + err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id) | ||
| 186 | + if err != nil { | ||
| 187 | + return err | ||
| 188 | + } | ||
| 189 | + | ||
| 173 | return nil | 190 | return nil |
| 174 | }, true) | 191 | }, true) |
| 175 | if err != nil { | 192 | if err != nil { |
| @@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | @@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | ||
| 243 | if err != nil { | 260 | if err != nil { |
| 244 | return err | 261 | return err |
| 245 | } | 262 | } |
| 263 | + | ||
| 264 | + // 创建点赞消息 | ||
| 265 | + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx) | ||
| 266 | + err = messageLogic.LikeArticle(c, articleInfo.Id, articleInfo.AuthorId) | ||
| 267 | + if err != nil { | ||
| 268 | + return err | ||
| 269 | + } | ||
| 270 | + | ||
| 246 | return nil | 271 | return nil |
| 247 | }, true) | 272 | }, true) |
| 248 | if err != nil { | 273 | if err != nil { |
| @@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | @@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | ||
| 324 | if err != nil { | 349 | if err != nil { |
| 325 | return err | 350 | return err |
| 326 | } | 351 | } |
| 352 | + | ||
| 353 | + // 创建点赞消息 | ||
| 354 | + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx) | ||
| 355 | + err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId) | ||
| 356 | + if err != nil { | ||
| 357 | + return err | ||
| 358 | + } | ||
| 359 | + | ||
| 327 | return nil | 360 | return nil |
| 328 | }, true) | 361 | }, true) |
| 329 | if err != nil { | 362 | if err != nil { |
| @@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, | @@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, | ||
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | // LikeComment 点赞评论 | 224 | // LikeComment 点赞评论 |
| 225 | -func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) { | ||
| 226 | - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at}) | 225 | +func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) { |
| 226 | + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, 0, commentId, "", []int64{at}) | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | +// UnLikeArticle 取消点赞文章 | ||
| 230 | +func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64) (err error) { | ||
| 231 | + return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0) | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +// UnLikeComment 取消点赞评论 | ||
| 235 | +func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64) (err error) { | ||
| 236 | + return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId) | ||
| 227 | } | 237 | } |
| 228 | 238 | ||
| 229 | func (l *MiniBusinessLogic) createMessage( | 239 | func (l *MiniBusinessLogic) createMessage( |
| @@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage( | @@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage( | ||
| 257 | } | 267 | } |
| 258 | return nil | 268 | return nil |
| 259 | } | 269 | } |
| 270 | + | ||
| 271 | +func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64) (err error) { | ||
| 272 | + var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 273 | + | ||
| 274 | + queryOption := domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1). | ||
| 275 | + MustWithKV("type", domain.MsgTypeLike). | ||
| 276 | + MustWithKV("optType", optType). | ||
| 277 | + MustWithKV("companyId", userToken.CompanyId). | ||
| 278 | + MustWithKV("recipientId", userToken.UserId). | ||
| 279 | + MustWithKV("articleId", articleId). | ||
| 280 | + MustWithKV("commentId", commentId) | ||
| 281 | + | ||
| 282 | + _, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, queryOption) | ||
| 283 | + if err != nil { | ||
| 284 | + return err | ||
| 285 | + } | ||
| 286 | + for i := range list { | ||
| 287 | + _, err = l.svcCtx.MessageBusinessRepository.Delete(l.ctx, conn, list[i]) | ||
| 288 | + if err != nil { | ||
| 289 | + return err | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + return nil | ||
| 293 | +} |
| @@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | @@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | ||
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | tx = tx.Model(&ms).Order("id desc") | 123 | tx = tx.Model(&ms).Order("id desc") |
| 124 | + if v, ok := queryOptions["type"]; ok { | ||
| 125 | + tx.Where("type = ?", v) | ||
| 126 | + } | ||
| 127 | + if v, ok := queryOptions["optType"]; ok { | ||
| 128 | + tx.Where("opt_type = ?", v) | ||
| 129 | + } | ||
| 124 | if v, ok := queryOptions["companyId"]; ok { | 130 | if v, ok := queryOptions["companyId"]; ok { |
| 125 | tx.Where("company_id = ?", v) | 131 | tx.Where("company_id = ?", v) |
| 126 | } | 132 | } |
| 133 | + if v, ok := queryOptions["recipientId"]; ok { | ||
| 134 | + tx.Where("recipient_id = ?", v) | ||
| 135 | + } | ||
| 136 | + if v, ok := queryOptions["articleId"]; ok { | ||
| 137 | + tx.Where("article_id = ?", v) | ||
| 138 | + } | ||
| 139 | + if v, ok := queryOptions["commentId"]; ok { | ||
| 140 | + tx.Where("comment_id = ?", v) | ||
| 141 | + } | ||
| 127 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 142 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 128 | return dms, tx.Error | 143 | return dms, tx.Error |
| 129 | } | 144 | } |
| @@ -36,7 +36,7 @@ const ( | @@ -36,7 +36,7 @@ const ( | ||
| 36 | 36 | ||
| 37 | const ( | 37 | const ( |
| 38 | OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 | 38 | OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 |
| 39 | - OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论() | 39 | + OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论 |
| 40 | OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 | 40 | OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 |
| 41 | ) | 41 | ) |
| 42 | 42 |
-
请 注册 或 登录 后发表评论