正在显示
8 个修改的文件
包含
200 行增加
和
12 行删除
@@ -70,9 +70,12 @@ service Core { | @@ -70,9 +70,12 @@ service Core { | ||
70 | @doc "取消关注" | 70 | @doc "取消关注" |
71 | @handler miniUserUnFollow | 71 | @handler miniUserUnFollow |
72 | post /mini/user/unfollow (FollowRequest) | 72 | post /mini/user/unfollow (FollowRequest) |
73 | - @doc "我点赞的文章或评论" | 73 | + @doc "我点赞的-文章或评论列表" |
74 | @handler miniMyLike | 74 | @handler miniMyLike |
75 | post /mini/user/mylike (MiniMyLikeRequest)returns (MiniMyLikeResponse) | 75 | post /mini/user/mylike (MiniMyLikeRequest)returns (MiniMyLikeResponse) |
76 | + @doc "我被点赞-文章或评论列表" | ||
77 | + @handler miniMyBeLiked | ||
78 | + post /mini/user/mybeliked (MiniBeLikedRequest)returns (MiniBeLikedResponse) | ||
76 | } | 79 | } |
77 | 80 | ||
78 | type( | 81 | type( |
@@ -220,7 +223,7 @@ type( | @@ -220,7 +223,7 @@ type( | ||
220 | 223 | ||
221 | 224 | ||
222 | 225 | ||
223 | -// 我点赞的文章或评论 | 226 | +// 1.我点赞的文章或评论 2.我的文章或评论被点赞 |
224 | type ( | 227 | type ( |
225 | MiniMyLikeRequest{ | 228 | MiniMyLikeRequest{ |
226 | Page int `json:"page"` | 229 | Page int `json:"page"` |
@@ -249,6 +252,28 @@ type ( | @@ -249,6 +252,28 @@ type ( | ||
249 | CountComment int `json:"countComment"` // 评论数量 | 252 | CountComment int `json:"countComment"` // 评论数量 |
250 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 253 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
251 | } | 254 | } |
255 | + | ||
256 | + | ||
257 | + MiniBeLikedRequest{ | ||
258 | + Page int `json:"page"` | ||
259 | + Size int `json:"size"` | ||
260 | + } | ||
261 | + | ||
262 | + MiniBeLikedResponse { | ||
263 | + List []MyBeLikedItem `json:"list"` | ||
264 | + Total int64 `json:"total"` | ||
265 | + } | ||
266 | + | ||
267 | + MyBeLikedItem { | ||
268 | + UserId int64 `json:"userId"` // 点赞人id | ||
269 | + ArticleId int64 `json:"articleId"` // 文章id | ||
270 | + CommentId int64 `json:"commentId"` // 评论id | ||
271 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
272 | + User *SimpleUser `json:"user"` // 点赞人 | ||
273 | + Article *SimpleArticle `json:"article"` // 文章 | ||
274 | + Comment *SimpleComment `json:"comment"` // 评论 | ||
275 | + } | ||
276 | + | ||
252 | ) | 277 | ) |
253 | 278 | ||
254 | 279 |
@@ -275,6 +275,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -275,6 +275,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
275 | Path: "/mini/user/mylike", | 275 | Path: "/mini/user/mylike", |
276 | Handler: user.MiniMyLikeHandler(serverCtx), | 276 | Handler: user.MiniMyLikeHandler(serverCtx), |
277 | }, | 277 | }, |
278 | + { | ||
279 | + Method: http.MethodPost, | ||
280 | + Path: "/mini/user/mybeliked", | ||
281 | + Handler: user.MiniMyBeLikedHandler(serverCtx), | ||
282 | + }, | ||
278 | }..., | 283 | }..., |
279 | ), | 284 | ), |
280 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 285 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
11 | +) | ||
12 | + | ||
13 | +func MiniMyBeLikedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
15 | + var req types.MiniBeLikedRequest | ||
16 | + if err := httpx.Parse(r, &req); err != nil { | ||
17 | + result.ParamErrorResult(r, w, err) | ||
18 | + return | ||
19 | + } | ||
20 | + | ||
21 | + l := user.NewMiniMyBeLikedLogic(r.Context(), svcCtx) | ||
22 | + resp, err := l.MiniMyBeLiked(&req) | ||
23 | + result.HttpResult(r, w, resp, err) | ||
24 | + } | ||
25 | +} |
@@ -199,6 +199,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma | @@ -199,6 +199,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma | ||
199 | Content: v.Content, | 199 | Content: v.Content, |
200 | CountLove: v.CountUserLove, | 200 | CountLove: v.CountUserLove, |
201 | CountComment: v.CountReply, | 201 | CountComment: v.CountReply, |
202 | + Show: int(v.Show), | ||
202 | } | 203 | } |
203 | } | 204 | } |
204 | 205 |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/samber/lo" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
8 | + | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
11 | + | ||
12 | + "github.com/zeromicro/go-zero/core/logx" | ||
13 | +) | ||
14 | + | ||
15 | +type MiniMyBeLikedLogic struct { | ||
16 | + logx.Logger | ||
17 | + ctx context.Context | ||
18 | + svcCtx *svc.ServiceContext | ||
19 | +} | ||
20 | + | ||
21 | +func NewMiniMyBeLikedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyBeLikedLogic { | ||
22 | + return &MiniMyBeLikedLogic{ | ||
23 | + Logger: logx.WithContext(ctx), | ||
24 | + ctx: ctx, | ||
25 | + svcCtx: svcCtx, | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
29 | +func (l *MiniMyBeLikedLogic) MiniMyBeLiked(req *types.MiniBeLikedRequest) (resp *types.MiniBeLikedResponse, err error) { | ||
30 | + var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
31 | + var conn = l.svcCtx.DefaultDBConn() | ||
32 | + | ||
33 | + total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
34 | + WithOffsetLimit(req.Page, req.Size). | ||
35 | + WithKV("commentId", userToken.CompanyId). | ||
36 | + WithKV("toUserId", userToken.UserId)) | ||
37 | + if err != nil { | ||
38 | + return nil, err | ||
39 | + } | ||
40 | + | ||
41 | + resp = &types.MiniBeLikedResponse{} | ||
42 | + resp.Total = total | ||
43 | + resp.List = make([]types.MyBeLikedItem, 0) | ||
44 | + if total == 0 || len(list) == 0 { | ||
45 | + return resp, nil | ||
46 | + } | ||
47 | + | ||
48 | + var userMap = make(map[int64]*domain.User) | ||
49 | + var articleMap = make(map[int64]*domain.Article) | ||
50 | + var commentMap = make(map[int64]*domain.ArticleComment) | ||
51 | + | ||
52 | + lo.ForEach(list, func(item *domain.UserLoveFlag, index int) { | ||
53 | + var ( | ||
54 | + user *domain.User | ||
55 | + article *domain.Article | ||
56 | + comment *domain.ArticleComment | ||
57 | + ) | ||
58 | + user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.UserId, l.svcCtx.UserRepository.FindOne) | ||
59 | + article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | ||
60 | + // 点赞评论 | ||
61 | + if item.CommentId != 0 { | ||
62 | + comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne) | ||
63 | + } | ||
64 | + | ||
65 | + resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment)) | ||
66 | + }) | ||
67 | + | ||
68 | + return resp, nil | ||
69 | +} | ||
70 | + | ||
71 | +func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyBeLikedItem { | ||
72 | + item := types.MyBeLikedItem{ | ||
73 | + UserId: love.UserId, | ||
74 | + ArticleId: love.ArticleId, | ||
75 | + CommentId: love.CommentId, | ||
76 | + CreatedAt: love.CreatedAt, | ||
77 | + } | ||
78 | + | ||
79 | + if user != nil { | ||
80 | + item.User = &types.SimpleUser{ | ||
81 | + Id: user.Id, | ||
82 | + CompanyId: user.CompanyId, | ||
83 | + Name: user.Name, | ||
84 | + Avatar: user.Avatar, | ||
85 | + Position: user.Position, | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + if article != nil { | ||
90 | + item.Article = &types.SimpleArticle{ | ||
91 | + Id: article.Id, | ||
92 | + Title: article.Title, | ||
93 | + Summary: article.Summary, | ||
94 | + CountLove: article.CountLove, | ||
95 | + CountComment: article.CountComment, | ||
96 | + Show: int(article.Show), | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + if comment != nil { | ||
101 | + item.Comment = &types.SimpleComment{ | ||
102 | + Id: comment.Id, | ||
103 | + Content: comment.Content, | ||
104 | + CountLove: comment.CountUserLove, | ||
105 | + CountComment: comment.CountReply, | ||
106 | + Show: int(comment.Show), | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + return item | ||
111 | +} |
@@ -32,6 +32,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | @@ -32,6 +32,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | ||
32 | 32 | ||
33 | total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | 33 | total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
34 | WithOffsetLimit(req.Page, req.Size). | 34 | WithOffsetLimit(req.Page, req.Size). |
35 | + WithKV("commentId", userToken.CompanyId). | ||
35 | WithKV("userId", userToken.UserId)) | 36 | WithKV("userId", userToken.UserId)) |
36 | if err != nil { | 37 | if err != nil { |
37 | return nil, err | 38 | return nil, err |
@@ -54,25 +55,22 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | @@ -54,25 +55,22 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types. | ||
54 | article *domain.Article | 55 | article *domain.Article |
55 | comment *domain.ArticleComment | 56 | comment *domain.ArticleComment |
56 | ) | 57 | ) |
57 | - | ||
58 | - if item.CommentId != 0 { // 点赞评论 | ||
59 | - user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne) | 58 | + user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ToUserId, l.svcCtx.UserRepository.FindOne) |
60 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | 59 | article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) |
60 | + // 点赞评论 | ||
61 | + if item.CommentId != 0 { | ||
61 | comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne) | 62 | comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne) |
62 | - } else { | ||
63 | - user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne) | ||
64 | - article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | ||
65 | } | 63 | } |
66 | 64 | ||
67 | - resp.List = append(resp.List, NewItemSimple(item, user, article, comment)) | 65 | + resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment)) |
68 | }) | 66 | }) |
69 | 67 | ||
70 | - return | 68 | + return resp, nil |
71 | } | 69 | } |
72 | 70 | ||
73 | -func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem { | 71 | +func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem { |
74 | item := types.MyLikeItem{ | 72 | item := types.MyLikeItem{ |
75 | - UserId: love.UserId, | 73 | + UserId: love.ToUserId, |
76 | ArticleId: love.ArticleId, | 74 | ArticleId: love.ArticleId, |
77 | CommentId: love.CommentId, | 75 | CommentId: love.CommentId, |
78 | CreatedAt: love.CreatedAt, | 76 | CreatedAt: love.CreatedAt, |
@@ -587,6 +587,26 @@ type SimpleComment struct { | @@ -587,6 +587,26 @@ type SimpleComment struct { | ||
587 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 587 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
588 | } | 588 | } |
589 | 589 | ||
590 | +type MiniBeLikedRequest struct { | ||
591 | + Page int `json:"page"` | ||
592 | + Size int `json:"size"` | ||
593 | +} | ||
594 | + | ||
595 | +type MiniBeLikedResponse struct { | ||
596 | + List []MyBeLikedItem `json:"list"` | ||
597 | + Total int64 `json:"total"` | ||
598 | +} | ||
599 | + | ||
600 | +type MyBeLikedItem struct { | ||
601 | + UserId int64 `json:"userId"` // 点赞人id | ||
602 | + ArticleId int64 `json:"articleId"` // 文章id | ||
603 | + CommentId int64 `json:"commentId"` // 评论id | ||
604 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
605 | + User *SimpleUser `json:"user"` // 点赞人 | ||
606 | + Article *SimpleArticle `json:"article"` // 文章 | ||
607 | + Comment *SimpleComment `json:"comment"` // 评论 | ||
608 | +} | ||
609 | + | ||
590 | type SystemUserInfoRequest struct { | 610 | type SystemUserInfoRequest struct { |
591 | Token string `header:"x-mmm-accesstoken"` | 611 | Token string `header:"x-mmm-accesstoken"` |
592 | } | 612 | } |
@@ -132,6 +132,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac | @@ -132,6 +132,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac | ||
132 | if v, ok := queryOptions["userId"]; ok { | 132 | if v, ok := queryOptions["userId"]; ok { |
133 | tx = tx.Where("user_id=?", v) | 133 | tx = tx.Where("user_id=?", v) |
134 | } | 134 | } |
135 | + if v, ok := queryOptions["toUserId"]; ok { | ||
136 | + tx = tx.Where("to_user_id=?", v) | ||
137 | + } | ||
135 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 138 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
136 | return dms, tx.Error | 139 | return dms, tx.Error |
137 | } | 140 | } |
-
请 注册 或 登录 后发表评论