作者 tangxvhui

人员设置点赞标识

@@ -146,9 +146,12 @@ type ( @@ -146,9 +146,12 @@ type (
146 MiniSetUserLikeRequset { 146 MiniSetUserLikeRequset {
147 ArticleId int64 `json:"articleId"` //文章id 147 ArticleId int64 `json:"articleId"` //文章id
148 CommentId int64 `json:"commentId"` //评论id 148 CommentId int64 `json:"commentId"` //评论id
  149 + UserId int64 `json:"-"` //操作人
149 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞 150 Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
150 } 151 }
151 MiniSetUserLikeResponse { 152 MiniSetUserLikeResponse {
152 - Id int64 `json:"id"` 153 + ArticleId int64 `json:"articleId"` //文章id
  154 + CommentId int64 `json:"commentId"` //评论id
  155 + Count int `json:"count"` //现有的点赞数量
153 } 156 }
154 ) 157 )
  1 +package article
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  11 +)
  12 +
  13 +func MiniSetUserLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.MiniSetUserLikeRequset
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := article.NewMiniSetUserLikeLogic(r.Context(), svcCtx)
  22 + token := contextdata.GetUserTokenFromCtx(r.Context())
  23 + req.UserId = token.UserId
  24 + resp, err := l.MiniSetUserLike(&req)
  25 + if err != nil {
  26 + httpx.ErrorCtx(r.Context(), w, err)
  27 + } else {
  28 + httpx.OkJsonCtx(r.Context(), w, resp)
  29 + }
  30 + }
  31 +}
  1 +package article
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  10 +)
  11 +
  12 +func MiniUserLikeArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniUserLikeArticleRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := article.NewMiniUserLikeArticleLogic(r.Context(), svcCtx)
  21 + resp, err := l.MiniUserLikeArticle(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -192,6 +192,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -192,6 +192,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
192 Path: "/article/:id", 192 Path: "/article/:id",
193 Handler: article.MiniGetArticleHandler(serverCtx), 193 Handler: article.MiniGetArticleHandler(serverCtx),
194 }, 194 },
  195 + {
  196 + Method: http.MethodPost,
  197 + Path: "/article/user_like/list",
  198 + Handler: article.MiniUserLikeArticleHandler(serverCtx),
  199 + },
  200 + {
  201 + Method: http.MethodPost,
  202 + Path: "/article/user_like/set",
  203 + Handler: article.MiniSetUserLikeHandler(serverCtx),
  204 + },
195 }, 205 },
196 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 206 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
197 rest.WithPrefix("/v1/mini"), 207 rest.WithPrefix("/v1/mini"),
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 +
  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/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type MiniSetUserLikeLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewMiniSetUserLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSetUserLikeLogic {
  22 + return &MiniSetUserLikeLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +// 设置点赞操作
  30 +func (l *MiniSetUserLikeLogic) MiniSetUserLike(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
  31 + //取消点赞文章
  32 + if req.Flag == 2 && req.CommentId == 0 {
  33 + return l.cancelSetUserLikeArticle(req)
  34 + }
  35 + // 取消点赞评论
  36 + if req.Flag == 2 && req.CommentId > 0 {
  37 + return l.cancelSetUserLikeComment(req)
  38 + }
  39 + // 设置点赞文章
  40 + if req.Flag == 1 && req.CommentId == 0 {
  41 + return l.setUserLikeArticle(req)
  42 + }
  43 + // 设置点赞评论
  44 + if req.Flag == 1 && req.CommentId > 0 {
  45 + return l.setUserLikeComment(req)
  46 + }
  47 +
  48 + return nil, xerr.NewErrMsg("操作失败")
  49 +}
  50 +
  51 +// 取消文章点赞
  52 +func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
  53 + var conn = l.svcCtx.DefaultDBConn()
  54 +
  55 + // 检查id
  56 + userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
  57 + if err != nil {
  58 + //无法确认 文章的id
  59 + return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
  60 + }
  61 + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  62 + if err != nil {
  63 + //无法确认 文章的id
  64 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  65 + }
  66 + if userInfo.CompanyId != articleInfo.CompanyId {
  67 + // 公司无法对应
  68 + return nil, xerr.NewErrMsg("没有操作权限")
  69 + }
  70 + queryOption := domain.NewQueryOptions().
  71 + WithFindOnly().
  72 + MustWithKV("articleId", req.ArticleId).
  73 + MustWithKV("commentId", req.CommentId).
  74 + MustWithKV("userId", req.UserId)
  75 + _, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  76 + if err != nil {
  77 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  78 + }
  79 + if len(flagList) == 0 {
  80 + //没有记录
  81 + resp = &types.MiniSetUserLikeResponse{
  82 + ArticleId: req.ArticleId,
  83 + CommentId: req.CommentId,
  84 + Count: articleInfo.CountLove,
  85 + }
  86 + return resp, nil
  87 + }
  88 + flagInfo := flagList[0]
  89 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  90 + // 去除点赞标识
  91 + _, err = l.svcCtx.UserLoveFlagRepository.Delete(ctx, c, flagInfo)
  92 + if err != nil {
  93 + return err
  94 + }
  95 + // 减少文章的点赞数量
  96 + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo)
  97 + if err != nil {
  98 + return err
  99 + }
  100 + return nil
  101 + }, true)
  102 + if err != nil {
  103 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  104 + }
  105 + articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  106 + if err == nil {
  107 + return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
  108 + }
  109 + resp = &types.MiniSetUserLikeResponse{
  110 + ArticleId: req.ArticleId,
  111 + CommentId: req.CommentId,
  112 + Count: articleInfo.CountLove,
  113 + }
  114 + return resp, nil
  115 +}
  116 +
  117 +// 取消评论点赞
  118 +func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
  119 + var conn = l.svcCtx.DefaultDBConn()
  120 + // 检查id
  121 + userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
  122 + if err != nil {
  123 + //无法确认 文章的id
  124 + return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
  125 + }
  126 + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  127 + if err != nil {
  128 + //无法确认 文章的id
  129 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  130 + }
  131 + if userInfo.CompanyId != articleInfo.CompanyId {
  132 + // 文章和人员的公司无法对应
  133 + return nil, xerr.NewErrMsg("没有操作权限")
  134 + }
  135 + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
  136 + if err != nil {
  137 + return nil, xerr.NewErrMsgErr("无法确认评论信息", err)
  138 + }
  139 + if commentInfo.ArticleId != articleInfo.Id {
  140 + return nil, xerr.NewErrMsg("评论和文章不能对应")
  141 + }
  142 +
  143 + queryOption := domain.NewQueryOptions().
  144 + WithFindOnly().
  145 + MustWithKV("articleId", req.ArticleId).
  146 + MustWithKV("commentId", req.CommentId).
  147 + MustWithKV("userId", req.UserId)
  148 + _, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  149 + if err != nil {
  150 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  151 + }
  152 + if len(flagList) == 0 {
  153 + //没有记录
  154 + resp = &types.MiniSetUserLikeResponse{
  155 + ArticleId: req.ArticleId,
  156 + CommentId: req.CommentId,
  157 + Count: commentInfo.CountUserLove,
  158 + }
  159 + return resp, nil
  160 + }
  161 + flagInfo := flagList[0]
  162 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  163 + // 去除点赞标识
  164 + _, err = l.svcCtx.UserLoveFlagRepository.Delete(ctx, c, flagInfo)
  165 + if err != nil {
  166 + return err
  167 + }
  168 + // 减少评论的点赞数量
  169 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo)
  170 + if err != nil {
  171 + return err
  172 + }
  173 + return nil
  174 + }, true)
  175 + if err != nil {
  176 + return nil, xerr.NewErrMsgErr("取消点赞标识失败", err)
  177 + }
  178 + commentInfo, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
  179 + if err != nil {
  180 + return nil, xerr.NewErrMsgErr("获取评论的点赞数量失败", err)
  181 + }
  182 + resp = &types.MiniSetUserLikeResponse{
  183 + ArticleId: req.ArticleId,
  184 + CommentId: req.CommentId,
  185 + Count: commentInfo.CountUserLove,
  186 + }
  187 + return resp, nil
  188 +}
  189 +
  190 +// 设置文章点赞
  191 +func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
  192 + var conn = l.svcCtx.DefaultDBConn()
  193 +
  194 + // 检查id
  195 + userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
  196 + if err != nil {
  197 + //无法确认 文章的id
  198 + return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
  199 + }
  200 + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  201 + if err != nil {
  202 + //无法确认 文章的id
  203 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  204 + }
  205 + if userInfo.CompanyId != articleInfo.CompanyId {
  206 + // 公司无法对应
  207 + return nil, xerr.NewErrMsg("没有操作权限")
  208 + }
  209 + queryOption := domain.NewQueryOptions().
  210 + WithFindOnly().
  211 + MustWithKV("articleId", req.ArticleId).
  212 + MustWithKV("commentId", req.CommentId).
  213 + MustWithKV("userId", req.UserId)
  214 + _, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  215 + if err != nil {
  216 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  217 + }
  218 + if len(flagList) > 0 {
  219 + //已经有记录
  220 + resp = &types.MiniSetUserLikeResponse{
  221 + ArticleId: req.ArticleId,
  222 + CommentId: req.CommentId,
  223 + Count: articleInfo.CountLove,
  224 + }
  225 + return resp, nil
  226 + }
  227 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  228 + flagInfo := domain.UserLoveFlag{
  229 + Id: 0,
  230 + ArticleId: req.ArticleId,
  231 + CommentId: req.CommentId,
  232 + UserId: req.UserId,
  233 + }
  234 + // 去除点赞标识
  235 + _, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo)
  236 + if err != nil {
  237 + return err
  238 + }
  239 + // 增加文章的点赞数量
  240 + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo)
  241 + if err != nil {
  242 + return err
  243 + }
  244 + return nil
  245 + }, true)
  246 + if err != nil {
  247 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  248 + }
  249 + articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  250 + if err == nil {
  251 + return nil, xerr.NewErrMsgErr("获取点赞数量失败", err)
  252 + }
  253 + resp = &types.MiniSetUserLikeResponse{
  254 + ArticleId: req.ArticleId,
  255 + CommentId: req.CommentId,
  256 + Count: articleInfo.CountLove,
  257 + }
  258 + return resp, nil
  259 +}
  260 +
  261 +// 设置评论点赞
  262 +func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequset) (resp *types.MiniSetUserLikeResponse, err error) {
  263 + var conn = l.svcCtx.DefaultDBConn()
  264 + // 检查id
  265 + userInfo, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId)
  266 + if err != nil {
  267 + //无法确认 文章的id
  268 + return nil, xerr.NewErrMsgErr("无法确认操作人员信息", err)
  269 + }
  270 + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  271 + if err != nil {
  272 + //无法确认 文章的id
  273 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  274 + }
  275 + if userInfo.CompanyId != articleInfo.CompanyId {
  276 + // 文章和人员的公司无法对应
  277 + return nil, xerr.NewErrMsg("没有操作权限")
  278 + }
  279 + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
  280 + if err != nil {
  281 + return nil, xerr.NewErrMsgErr("无法确认评论信息", err)
  282 + }
  283 + if commentInfo.ArticleId != articleInfo.Id {
  284 + return nil, xerr.NewErrMsg("评论和文章不能对应")
  285 + }
  286 +
  287 + queryOption := domain.NewQueryOptions().
  288 + WithFindOnly().
  289 + MustWithKV("articleId", req.ArticleId).
  290 + MustWithKV("commentId", req.CommentId).
  291 + MustWithKV("userId", req.UserId)
  292 + _, flagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  293 + if err != nil {
  294 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  295 + }
  296 + if len(flagList) > 0 {
  297 + //已经有记录
  298 + resp = &types.MiniSetUserLikeResponse{
  299 + ArticleId: req.ArticleId,
  300 + CommentId: req.CommentId,
  301 + Count: commentInfo.CountUserLove,
  302 + }
  303 + return resp, nil
  304 + }
  305 +
  306 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
  307 + flagInfo := domain.UserLoveFlag{
  308 + Id: 0,
  309 + ArticleId: req.ArticleId,
  310 + CommentId: req.CommentId,
  311 + UserId: req.UserId,
  312 + }
  313 + // 设置赞标识
  314 + _, err = l.svcCtx.UserLoveFlagRepository.Insert(ctx, c, &flagInfo)
  315 + if err != nil {
  316 + return err
  317 + }
  318 + // 增加评论的点赞数量
  319 + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo)
  320 + if err != nil {
  321 + return err
  322 + }
  323 + return nil
  324 + }, true)
  325 + if err != nil {
  326 + return nil, xerr.NewErrMsgErr("设置点赞标识失败", err)
  327 + }
  328 + commentInfo, err = l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
  329 + if err != nil {
  330 + return nil, xerr.NewErrMsgErr("获取评论的点赞数量失败", err)
  331 + }
  332 + resp = &types.MiniSetUserLikeResponse{
  333 + ArticleId: req.ArticleId,
  334 + CommentId: req.CommentId,
  335 + Count: commentInfo.CountUserLove,
  336 + }
  337 + return resp, nil
  338 +}
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 +
  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/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type MiniUserLikeArticleLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniUserLikeArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniUserLikeArticleLogic {
  19 + return &MiniUserLikeArticleLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniUserLikeArticleLogic) MiniUserLikeArticle(req *types.MiniUserLikeArticleRequest) (resp *types.MiniUserLikeArticleResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -329,3 +329,36 @@ type ArticleSearchMe struct { @@ -329,3 +329,36 @@ type ArticleSearchMe struct {
329 CountComment int `json:"CountComment"` //评论数量 329 CountComment int `json:"CountComment"` //评论数量
330 Show int `json:"show"` //是否隐藏 [0显示、1不显示] 330 Show int `json:"show"` //是否隐藏 [0显示、1不显示]
331 } 331 }
  332 +
  333 +type MiniUserLikeArticleRequest struct {
  334 + ArticleId int64 `json:"articleId"` // 文章id
  335 + CompanyId int64 `json:"-"` //公司id
  336 + Page int `json:"page"` //分页,第几页
  337 + Size int `json:"size"` //分页,每页几条
  338 +}
  339 +
  340 +type MiniUserLikeArticleResponse struct {
  341 + Total int `json:"total"` //总数
  342 + List []WhichUserLikeArticle `json:"list"` //列表
  343 +}
  344 +
  345 +type WhichUserLikeArticle struct {
  346 + ArticleId int64 `json:"articleId"` // 文章id
  347 + UserId int64 `json:"userId"` // 人员id
  348 + Name string `json:"name"` // 人员名称
  349 + Avatar string `json:"avatar"` // 人员头像
  350 + CreatedAt int64 `json:"createdAt"` // 点赞记录的时间
  351 +}
  352 +
  353 +type MiniSetUserLikeRequset struct {
  354 + ArticleId int64 `json:"articleId"` //文章id
  355 + CommentId int64 `json:"commentId"` //评论id
  356 + UserId int64 `json:"-"` //操作人
  357 + Flag int `json:"flag"` //点赞标志 1、点赞 2 、取消点赞
  358 +}
  359 +
  360 +type MiniSetUserLikeResponse struct {
  361 + ArticleId int64 `json:"articleId"` //文章id
  362 + CommentId int64 `json:"commentId"` //评论id
  363 + Count int `json:"count"` //现有的点赞数量
  364 +}
@@ -194,6 +194,11 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti @@ -194,6 +194,11 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
194 return to, nil 194 return to, nil
195 } 195 }
196 196
  197 +// TODO 点赞数量变动
  198 +func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
  199 + return nil
  200 +}
  201 +
197 func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { 202 func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
198 return &ArticleCommentRepository{CachedRepository: cache} 203 return &ArticleCommentRepository{CachedRepository: cache}
199 } 204 }
@@ -198,6 +198,24 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* @@ -198,6 +198,24 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
198 return to, nil 198 return to, nil
199 } 199 }
200 200
  201 +// 点赞数量变动
  202 +func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
  203 + //
  204 + return nil
  205 +}
  206 +
  207 +// 浏览数量变动
  208 +func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
  209 + //
  210 + return nil
  211 +}
  212 +
  213 +// 评论数量变动
  214 +func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
  215 + //
  216 + return nil
  217 +}
  218 +
201 func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository { 219 func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository {
202 return &ArticleRepository{CachedRepository: cache} 220 return &ArticleRepository{CachedRepository: cache}
203 } 221 }
@@ -120,6 +120,15 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac @@ -120,6 +120,15 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
120 ) 120 )
121 queryFunc := func() (interface{}, error) { 121 queryFunc := func() (interface{}, error) {
122 tx = tx.Model(&ms).Order("id desc") 122 tx = tx.Model(&ms).Order("id desc")
  123 + if v, ok := queryOptions["articleId"]; ok {
  124 + tx = tx.Where("article_id=?", v)
  125 + }
  126 + if v, ok := queryOptions["commentId"]; ok {
  127 + tx = tx.Where("comment_id=?", v)
  128 + }
  129 + if v, ok := queryOptions["userId"]; ok {
  130 + tx = tx.Where("user_id=?", v)
  131 + }
123 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 132 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
124 return dms, tx.Error 133 return dms, tx.Error
125 } 134 }
@@ -37,6 +37,9 @@ type ArticleRepository interface { @@ -37,6 +37,9 @@ type ArticleRepository interface {
37 UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) 37 UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
38 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) 38 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
39 Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error) 39 Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
  40 + IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动
  41 + IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动
  42 + IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动
40 } 43 }
41 44
42 type ArticleTarget int 45 type ArticleTarget int
@@ -46,4 +46,5 @@ type ArticleCommentRepository interface { @@ -46,4 +46,5 @@ type ArticleCommentRepository interface {
46 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) 46 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
47 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) 47 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error)
48 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) 48 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error)
  49 + IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动
49 } 50 }