作者 tangxvhui

首页搜索文章列表

... ... @@ -511,7 +511,7 @@ type (
}
//
MiniSearchArticleResponse {
Total int `json:"total"`
Total int `json:"total"`
List []MiniSearchArticleItem `json:"list"`
}
//
... ...
... ... @@ -7,8 +7,11 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
)
// 小程序端搜索
func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSearchArticleRequest
... ... @@ -18,11 +21,10 @@ func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := article.NewMiniSearchArticlePageLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.UserId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniSearchArticlePage(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -32,7 +33,7 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
cnt, articleList, err := l.svcCtx.ArticleRepository.CustomSearchBy(l.ctx, conn, req.UserId, req.CompanyId,
req.TagCategory, req.TagId, [2]int64{req.BeginTime, req.EndTime}, req.SearchWord, req.Page, req.Size)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章列表", err)
return nil, xerr.NewErrMsgErr("获取文章列表失败", err)
}
articleIds := []int64{}
... ... @@ -40,8 +41,43 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch
articleIds = append(articleIds, val.Id)
}
readFlag := map[int64]struct{}{}
if len(articleIds) > 0 {
queryOption := domain.NewQueryOptions().WithFindOnly().
MustWithKV("userId", req.UserId).MustWithKV("articleIds", articleIds)
_, userReadFlag, err := l.svcCtx.UserReadArticleRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章列表失败", err)
}
for _, val := range userReadFlag {
readFlag[val.ArticleId] = struct{}{}
}
}
resp = &types.MiniSearchArticleResponse{
Total: int(cnt),
List: make([]types.MiniSearchArticleItem, len(articleList)),
}
return
for i, val := range articleList {
item := types.MiniSearchArticleItem{
ArticleId: val.Id,
Title: val.Title,
Author: val.Author.Name,
Images: []string{},
CreatedAt: val.CreatedAt,
MeReadFlag: 0,
}
if _, ok := readFlag[val.Id]; ok {
item.MeReadFlag = 1
}
for _, img := range val.Images {
item.Images = append(item.Images, img.Url)
}
resp.List[i] = item
}
return resp, nil
}
... ...