作者 tangxvhui
... ... @@ -70,9 +70,12 @@ service Core {
@doc "取消关注"
@handler miniUserUnFollow
post /mini/user/unfollow (FollowRequest)
@doc "我点赞的文章或评论"
@doc "我点赞的-文章或评论列表"
@handler miniMyLike
post /mini/user/mylike (MiniMyLikeRequest)returns (MiniMyLikeResponse)
@doc "我被点赞-文章或评论列表"
@handler miniMyBeLiked
post /mini/user/mybeliked (MiniBeLikedRequest)returns (MiniBeLikedResponse)
}
type(
... ... @@ -220,7 +223,7 @@ type(
// 我点赞的文章或评论
// 1.我点赞的文章或评论 2.我的文章或评论被点赞
type (
MiniMyLikeRequest{
Page int `json:"page"`
... ... @@ -249,6 +252,28 @@ type (
CountComment int `json:"countComment"` // 评论数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
MiniBeLikedRequest{
Page int `json:"page"`
Size int `json:"size"`
}
MiniBeLikedResponse {
List []MyBeLikedItem `json:"list"`
Total int64 `json:"total"`
}
MyBeLikedItem {
UserId int64 `json:"userId"` // 点赞人id
ArticleId int64 `json:"articleId"` // 文章id
CommentId int64 `json:"commentId"` // 评论id
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 点赞人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论
}
)
... ...
... ... @@ -275,6 +275,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/mini/user/mylike",
Handler: user.MiniMyLikeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/mybeliked",
Handler: user.MiniMyBeLikedHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniMyBeLikedHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniBeLikedRequest
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := user.NewMiniMyBeLikedLogic(r.Context(), svcCtx)
resp, err := l.MiniMyBeLiked(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -199,6 +199,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageRequest, msgType doma
Content: v.Content,
CountLove: v.CountUserLove,
CountComment: v.CountReply,
Show: int(v.Show),
}
}
... ...
package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniMyBeLikedLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniMyBeLikedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyBeLikedLogic {
return &MiniMyBeLikedLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniMyBeLikedLogic) MiniMyBeLiked(req *types.MiniBeLikedRequest) (resp *types.MiniBeLikedResponse, err error) {
var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
var conn = l.svcCtx.DefaultDBConn()
total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("commentId", userToken.CompanyId).
WithKV("toUserId", userToken.UserId))
if err != nil {
return nil, err
}
resp = &types.MiniBeLikedResponse{}
resp.Total = total
resp.List = make([]types.MyBeLikedItem, 0)
if total == 0 || len(list) == 0 {
return resp, nil
}
var userMap = make(map[int64]*domain.User)
var articleMap = make(map[int64]*domain.Article)
var commentMap = make(map[int64]*domain.ArticleComment)
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
var (
user *domain.User
article *domain.Article
comment *domain.ArticleComment
)
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.UserId, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
// 点赞评论
if item.CommentId != 0 {
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne)
}
resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment))
})
return resp, nil
}
func (l *MiniMyBeLikedLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyBeLikedItem {
item := types.MyBeLikedItem{
UserId: love.UserId,
ArticleId: love.ArticleId,
CommentId: love.CommentId,
CreatedAt: love.CreatedAt,
}
if user != nil {
item.User = &types.SimpleUser{
Id: user.Id,
CompanyId: user.CompanyId,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
}
}
if article != nil {
item.Article = &types.SimpleArticle{
Id: article.Id,
Title: article.Title,
Summary: article.Summary,
CountLove: article.CountLove,
CountComment: article.CountComment,
Show: int(article.Show),
}
}
if comment != nil {
item.Comment = &types.SimpleComment{
Id: comment.Id,
Content: comment.Content,
CountLove: comment.CountUserLove,
CountComment: comment.CountReply,
Show: int(comment.Show),
}
}
return item
}
... ...
... ... @@ -32,6 +32,7 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.
total, list, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("commentId", userToken.CompanyId).
WithKV("userId", userToken.UserId))
if err != nil {
return nil, err
... ... @@ -54,25 +55,22 @@ func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.
article *domain.Article
comment *domain.ArticleComment
)
if item.CommentId != 0 { // 点赞评论
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne)
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ToUserId, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
// 点赞评论
if item.CommentId != 0 {
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.ArticleCommentRepository.FindOne)
} else {
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.ArticleAuthor, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
}
resp.List = append(resp.List, NewItemSimple(item, user, article, comment))
resp.List = append(resp.List, l.NewItemSimple(item, user, article, comment))
})
return
return resp, nil
}
func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem {
func (l *MiniMyLikeLogic) NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.ArticleComment) types.MyLikeItem {
item := types.MyLikeItem{
UserId: love.UserId,
UserId: love.ToUserId,
ArticleId: love.ArticleId,
CommentId: love.CommentId,
CreatedAt: love.CreatedAt,
... ...
... ... @@ -587,6 +587,26 @@ type SimpleComment struct {
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
type MiniBeLikedRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type MiniBeLikedResponse struct {
List []MyBeLikedItem `json:"list"`
Total int64 `json:"total"`
}
type MyBeLikedItem struct {
UserId int64 `json:"userId"` // 点赞人id
ArticleId int64 `json:"articleId"` // 文章id
CommentId int64 `json:"commentId"` // 评论id
CreatedAt int64 `json:"createdAt"` // 创建时间
User *SimpleUser `json:"user"` // 点赞人
Article *SimpleArticle `json:"article"` // 文章
Comment *SimpleComment `json:"comment"` // 评论
}
type SystemUserInfoRequest struct {
Token string `header:"x-mmm-accesstoken"`
}
... ...
... ... @@ -132,6 +132,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
if v, ok := queryOptions["userId"]; ok {
tx = tx.Where("user_id=?", v)
}
if v, ok := queryOptions["toUserId"]; ok {
tx = tx.Where("to_user_id=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...