作者 yangfu
... ... @@ -62,12 +62,12 @@ type (
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
User *User `json:"user"` // 操作人
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到)
}
User {
SimpleUser {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
... ... @@ -77,11 +77,10 @@ type (
}
SimpleArticle {
SimpleArticle {
Id int64 `json:"id"`
Title string `json:"title"` // 文章标题
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
}
)
\ No newline at end of file
... ...
... ... @@ -54,6 +54,9 @@ service Core {
@doc "取消关注"
@handler miniUserUnFollow
post /mini/user/unfollow (FollowRequest)
@doc "我点赞的文章或评论"
@handler miniMyLike
post /user/mylike (MiniMyLikeRequest)returns (MiniMyLikeResponse)
}
type(
... ... @@ -169,6 +172,38 @@ type(
)
// 我点赞的文章或评论
type (
MiniMyLikeRequest{
Page int `json:"page"`
Size int `json:"size"`
}
MiniMyLikeResponse {
List []MyLikeItem `json:"list"`
Total int64 `json:"total"`
}
MyLikeItem {
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"` // 评论
}
SimpleComment {
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
}
)
// 后台接口
//@server(
// prefix: v1
... ...
... ... @@ -153,6 +153,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/mini/user/unfollow",
Handler: user.MiniUserUnFollowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/user/mylike",
Handler: user.MiniMyLikeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
... ...
package user
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"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"
)
func MiniMyLikeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniMyLikeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniMyLikeLogic(r.Context(), svcCtx)
resp, err := l.MiniMyLike(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -169,7 +169,7 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
}
if v, ok := userIdMap[item.UserId]; ok {
to.User = &types.User{
to.User = &types.SimpleUser{
Id: v.Id,
CompanyId: v.CompanyId,
Position: v.Position,
... ...
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 MiniMyLikeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniMyLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniMyLikeLogic {
return &MiniMyLikeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniMyLikeLogic) MiniMyLike(req *types.MiniMyLikeRequest) (resp *types.MiniMyLikeResponse, 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("userId", userToken.UserId))
if err != nil {
return nil, err
}
resp = &types.MiniMyLikeResponse{}
resp.Total = total
resp.List = make([]types.MyLikeItem, 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.Comment)
lo.ForEach(list, func(item *domain.UserLoveFlag, index int) {
var (
user *domain.User
article *domain.Article
comment *domain.Comment
)
if item.CommentId != 0 { // 点赞评论
user, _ = domain.LazyLoad(userMap, l.ctx, conn, item.CommentAuthor, l.svcCtx.UserRepository.FindOne)
article, _ = domain.LazyLoad(articleMap, l.ctx, conn, item.ArticleId, l.svcCtx.ArticleRepository.FindOne)
comment, _ = domain.LazyLoad(commentMap, l.ctx, conn, item.CommentId, l.svcCtx.CommentRepository.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))
})
return
}
func NewItemSimple(love *domain.UserLoveFlag, user *domain.User, article *domain.Article, comment *domain.Comment) types.MyLikeItem {
item := types.MyLikeItem{
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,
CountLove: article.CountLove,
CountComment: article.CountComment,
}
}
if comment != nil {
item.Comment = &types.SimpleComment{
Id: comment.Id,
//Content: comment.Content,
//CountLove: comment.CountLove,
//CountComment: comment.CountComment,
}
}
return item
}
... ...
... ... @@ -53,12 +53,12 @@ type MessageBusinessItem struct {
DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
Content string `json:"content"` // 消息内容
CreatedAt int64 `json:"createdAt"` // 创建时间
User *User `json:"user"` // 操作人
User *SimpleUser `json:"user"` // 操作人
Article *SimpleArticle `json:"article"` // 文章
Comment *Comment `json:"comment"` // 评论(不一定是自己,可能是被人@到)
}
type User struct {
type SimpleUser struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
... ... @@ -266,6 +266,33 @@ type UserFollowItem struct {
MutualFollowed bool `json:"mutualFollowed"` // 互相关注标识
}
type MiniMyLikeRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type MiniMyLikeResponse struct {
List []MyLikeItem `json:"list"`
Total int64 `json:"total"`
}
type MyLikeItem 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 SimpleComment struct {
Id int64 `json:"id"`
Content string `json:"content"` // 评论内容
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
}
type CompanySearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ...
... ... @@ -120,7 +120,7 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("created_at desc")
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
... ...
... ... @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("created_at desc") // 创建时间降序
tx = tx.Model(&ms).Order("id desc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...