正在显示
9 个修改的文件
包含
210 行增加
和
9 行删除
| @@ -62,12 +62,12 @@ type ( | @@ -62,12 +62,12 @@ type ( | ||
| 62 | DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | 62 | DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID |
| 63 | Content string `json:"content"` // 消息内容 | 63 | Content string `json:"content"` // 消息内容 |
| 64 | CreatedAt int64 `json:"createdAt"` // 创建时间 | 64 | CreatedAt int64 `json:"createdAt"` // 创建时间 |
| 65 | - User *User `json:"user"` // 操作人 | 65 | + User *SimpleUser `json:"user"` // 操作人 |
| 66 | Article *SimpleArticle `json:"article"` // 文章 | 66 | Article *SimpleArticle `json:"article"` // 文章 |
| 67 | Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到) | 67 | Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到) |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | - User { | 70 | + SimpleUser { |
| 71 | Id int64 `json:"id"` | 71 | Id int64 `json:"id"` |
| 72 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 72 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 73 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 73 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| @@ -77,11 +77,10 @@ type ( | @@ -77,11 +77,10 @@ type ( | ||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | - SimpleArticle { | 80 | + SimpleArticle { |
| 81 | Id int64 `json:"id"` | 81 | Id int64 `json:"id"` |
| 82 | Title string `json:"title"` // 文章标题 | 82 | Title string `json:"title"` // 文章标题 |
| 83 | CountLove int `json:"countLove"` // 点赞数量 | 83 | CountLove int `json:"countLove"` // 点赞数量 |
| 84 | CountComment int `json:"countComment"` // 评论数量 | 84 | CountComment int `json:"countComment"` // 评论数量 |
| 85 | } | 85 | } |
| 86 | ) | 86 | ) |
| 87 | - |
| @@ -51,6 +51,9 @@ service Core { | @@ -51,6 +51,9 @@ service Core { | ||
| 51 | @doc "取消关注" | 51 | @doc "取消关注" |
| 52 | @handler miniUserUnFollow | 52 | @handler miniUserUnFollow |
| 53 | post /mini/user/unfollow (FollowRequest) | 53 | post /mini/user/unfollow (FollowRequest) |
| 54 | + @doc "我点赞的文章或评论" | ||
| 55 | + @handler miniMyLike | ||
| 56 | + post /user/mylike (MiniMyLikeRequest)returns (MiniMyLikeResponse) | ||
| 54 | } | 57 | } |
| 55 | 58 | ||
| 56 | type( | 59 | type( |
| @@ -153,6 +156,38 @@ type( | @@ -153,6 +156,38 @@ type( | ||
| 153 | ) | 156 | ) |
| 154 | 157 | ||
| 155 | 158 | ||
| 159 | + | ||
| 160 | +// 我点赞的文章或评论 | ||
| 161 | +type ( | ||
| 162 | + MiniMyLikeRequest{ | ||
| 163 | + Page int `json:"page"` | ||
| 164 | + Size int `json:"size"` | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + MiniMyLikeResponse { | ||
| 168 | + List []MyLikeItem `json:"list"` | ||
| 169 | + Total int64 `json:"total"` | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + MyLikeItem { | ||
| 173 | + UserId int64 `json:"userId"` // 发布人id | ||
| 174 | + ArticleId int64 `json:"articleId"` // 文章id | ||
| 175 | + CommentId int64 `json:"commentId"` // 评论id | ||
| 176 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
| 177 | + User *SimpleUser `json:"user"` // 发布人 | ||
| 178 | + Article *SimpleArticle `json:"article"` // 文章 | ||
| 179 | + Comment *SimpleComment `json:"comment"` // 评论 | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + SimpleComment { | ||
| 183 | + Id int64 `json:"id"` | ||
| 184 | + Content string `json:"content"` // 评论内容 | ||
| 185 | + CountLove int `json:"countLove"` // 点赞数量 | ||
| 186 | + CountComment int `json:"countComment"` // 评论数量 | ||
| 187 | + } | ||
| 188 | +) | ||
| 189 | + | ||
| 190 | + | ||
| 156 | // 后台接口 | 191 | // 后台接口 |
| 157 | //@server( | 192 | //@server( |
| 158 | // prefix: v1 | 193 | // prefix: v1 |
| @@ -147,6 +147,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -147,6 +147,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 147 | Path: "/mini/user/unfollow", | 147 | Path: "/mini/user/unfollow", |
| 148 | Handler: user.MiniUserUnFollowHandler(serverCtx), | 148 | Handler: user.MiniUserUnFollowHandler(serverCtx), |
| 149 | }, | 149 | }, |
| 150 | + { | ||
| 151 | + Method: http.MethodPost, | ||
| 152 | + Path: "/user/mylike", | ||
| 153 | + Handler: user.MiniMyLikeHandler(serverCtx), | ||
| 154 | + }, | ||
| 150 | }, | 155 | }, |
| 151 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 156 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
| 152 | rest.WithPrefix("/v1"), | 157 | rest.WithPrefix("/v1"), |
| 1 | +package user | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 7 | + "net/http" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func MiniMyLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 15 | + var req types.MiniMyLikeRequest | ||
| 16 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 17 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + l := user.NewMiniMyLikeLogic(r.Context(), svcCtx) | ||
| 22 | + resp, err := l.MiniMyLike(&req) | ||
| 23 | + result.HttpResult(r, w, resp, err) | ||
| 24 | + } | ||
| 25 | +} |
| @@ -169,7 +169,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | @@ -169,7 +169,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res | ||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | if v, ok := userIdMap[item.UserId]; ok { | 171 | if v, ok := userIdMap[item.UserId]; ok { |
| 172 | - to.User = &types.User{ | 172 | + to.User = &types.SimpleUser{ |
| 173 | Id: v.Id, | 173 | Id: v.Id, |
| 174 | CompanyId: v.CompanyId, | 174 | CompanyId: v.CompanyId, |
| 175 | Position: v.Position, | 175 | Position: v.Position, |
| 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 MiniMyLikeLogic struct { | ||
| 16 | + logx.Logger | ||
| 17 | + ctx context.Context | ||
| 18 | + svcCtx *svc.ServiceContext | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func NewMiniMyLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyLikeLogic { | ||
| 22 | + return &MiniMyLikeLogic{ | ||
| 23 | + Logger: logx.WithContext(ctx), | ||
| 24 | + ctx: ctx, | ||
| 25 | + svcCtx: svcCtx, | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.MiniMyLikeResponse, 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("userId", userToken.UserId)) | ||
| 36 | + if err != nil { | ||
| 37 | + return nil, err | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + resp = &types.MiniMyLikeResponse{} | ||
| 41 | + resp.Total = total | ||
| 42 | + resp.List = make([]types.MyLikeItem, 0) | ||
| 43 | + if total == 0 || len(list) == 0 { | ||
| 44 | + return resp, nil | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + var userMap = make(map[int64]*domain.User) | ||
| 48 | + var articleMap = make(map[int64]*domain.Article) | ||
| 49 | + var commentMap = make(map[int64]*domain.Comment) | ||
| 50 | + | ||
| 51 | + lo.ForEach(list, func(item *domain.UserLoveFlag, index int) { | ||
| 52 | + var ( | ||
| 53 | + user *domain.User | ||
| 54 | + article *domain.Article | ||
| 55 | + comment *domain.Comment | ||
| 56 | + ) | ||
| 57 | + | ||
| 58 | + if item.CommentId != 0 { // 点赞评论 | ||
| 59 | + user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne) | ||
| 60 | + article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne) | ||
| 61 | + comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.CommentRepository.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 | + } | ||
| 66 | + | ||
| 67 | + resp.List = append(resp.List, NewItemSimple(item, user, article, comment)) | ||
| 68 | + }) | ||
| 69 | + | ||
| 70 | + return | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.Comment) types.MyLikeItem { | ||
| 74 | + item := types.MyLikeItem{ | ||
| 75 | + UserId: love.UserId, | ||
| 76 | + ArticleId: love.ArticleId, | ||
| 77 | + CommentId: love.CommentId, | ||
| 78 | + CreatedAt: love.CreatedAt, | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + if user != nil { | ||
| 82 | + item.User = &types.SimpleUser{ | ||
| 83 | + Id: user.Id, | ||
| 84 | + CompanyId: user.CompanyId, | ||
| 85 | + Name: user.Name, | ||
| 86 | + Avatar: user.Avatar, | ||
| 87 | + Position: user.Position, | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + if article != nil { | ||
| 92 | + item.Article = &types.SimpleArticle{ | ||
| 93 | + Id: article.Id, | ||
| 94 | + Title: article.Title, | ||
| 95 | + CountLove: article.CountLove, | ||
| 96 | + CountComment: article.CountComment, | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + if comment != nil { | ||
| 101 | + item.Comment = &types.SimpleComment{ | ||
| 102 | + Id: comment.Id, | ||
| 103 | + //Content: comment.Content, | ||
| 104 | + //CountLove: comment.CountLove, | ||
| 105 | + //CountComment: comment.CountComment, | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + return item | ||
| 110 | +} |
| @@ -53,12 +53,12 @@ type MessageBusinessItem struct { | @@ -53,12 +53,12 @@ type MessageBusinessItem struct { | ||
| 53 | DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID | 53 | DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID |
| 54 | Content string `json:"content"` // 消息内容 | 54 | Content string `json:"content"` // 消息内容 |
| 55 | CreatedAt int64 `json:"createdAt"` // 创建时间 | 55 | CreatedAt int64 `json:"createdAt"` // 创建时间 |
| 56 | - User *User `json:"user"` // 操作人 | 56 | + User *SimpleUser `json:"user"` // 操作人 |
| 57 | Article *SimpleArticle `json:"article"` // 文章 | 57 | Article *SimpleArticle `json:"article"` // 文章 |
| 58 | Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到) | 58 | Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到) |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -type User struct { | 61 | +type SimpleUser struct { |
| 62 | Id int64 `json:"id"` | 62 | Id int64 `json:"id"` |
| 63 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID | 63 | CompanyId int64 `json:"companyId,omitempty"` // 公司ID |
| 64 | CompanyName string `json:"companyName,omitempty"` // 公司名称 | 64 | CompanyName string `json:"companyName,omitempty"` // 公司名称 |
| @@ -251,6 +251,33 @@ type UserFollowItem struct { | @@ -251,6 +251,33 @@ type UserFollowItem struct { | ||
| 251 | MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识 | 251 | MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识 |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | +type MiniMyLikeRequest struct { | ||
| 255 | + Page int `json:"page"` | ||
| 256 | + Size int `json:"size"` | ||
| 257 | +} | ||
| 258 | + | ||
| 259 | +type MiniMyLikeResponse struct { | ||
| 260 | + List []MyLikeItem `json:"list"` | ||
| 261 | + Total int64 `json:"total"` | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | +type MyLikeItem struct { | ||
| 265 | + UserId int64 `json:"userId"` // 发布人id | ||
| 266 | + ArticleId int64 `json:"articleId"` // 文章id | ||
| 267 | + CommentId int64 `json:"commentId"` // 评论id | ||
| 268 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
| 269 | + User *SimpleUser `json:"user"` // 发布人 | ||
| 270 | + Article *SimpleArticle `json:"article"` // 文章 | ||
| 271 | + Comment *SimpleComment `json:"comment"` // 评论 | ||
| 272 | +} | ||
| 273 | + | ||
| 274 | +type SimpleComment struct { | ||
| 275 | + Id int64 `json:"id"` | ||
| 276 | + Content string `json:"content"` // 评论内容 | ||
| 277 | + CountLove int `json:"countLove"` // 点赞数量 | ||
| 278 | + CountComment int `json:"countComment"` // 评论数量 | ||
| 279 | +} | ||
| 280 | + | ||
| 254 | type CompanySearchRequest struct { | 281 | type CompanySearchRequest struct { |
| 255 | Page int `json:"page"` | 282 | Page int `json:"page"` |
| 256 | Size int `json:"size"` | 283 | Size int `json:"size"` |
| @@ -120,7 +120,7 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | @@ -120,7 +120,7 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran | ||
| 120 | total int64 | 120 | total int64 |
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | - tx = tx.Model(&ms).Order("created_at desc") | 123 | + tx = tx.Model(&ms).Order("id desc") |
| 124 | if v, ok := queryOptions["companyId"]; ok { | 124 | if v, ok := queryOptions["companyId"]; ok { |
| 125 | tx.Where("company_id = ?", v) | 125 | tx.Where("company_id = ?", v) |
| 126 | } | 126 | } |
| @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | ||
| 120 | total int64 | 120 | total int64 |
| 121 | ) | 121 | ) |
| 122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
| 123 | - tx = tx.Model(&ms).Order("created_at desc") // 创建时间降序 | 123 | + tx = tx.Model(&ms).Order("id desc") |
| 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 125 | return dms, tx.Error | 125 | return dms, tx.Error |
| 126 | } | 126 | } |
-
请 注册 或 登录 后发表评论