...
|
...
|
@@ -2,9 +2,12 @@ package article |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"sort"
|
|
|
|
|
|
"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"
|
|
|
)
|
...
|
...
|
@@ -24,7 +27,76 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi |
|
|
}
|
|
|
|
|
|
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
// 获取文章内容
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
|
|
|
}
|
|
|
if articleInfo.CompanyId != req.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("没有查看权限")
|
|
|
}
|
|
|
|
|
|
if articleInfo.Show == domain.ArticleShowDisable {
|
|
|
resp = &types.MiniArticleGetResponse{
|
|
|
Id: articleInfo.Id,
|
|
|
Title: articleInfo.Title,
|
|
|
Show: int(domain.ArticleShowDisable),
|
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
queryOption := domain.NewQueryOptions().
|
|
|
WithFindOnly().
|
|
|
MustWithKV("articleId", articleInfo.Id)
|
|
|
|
|
|
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
|
|
|
}
|
|
|
sortBy := domain.SortArticleSection(sectionList)
|
|
|
sort.Sort(sortBy)
|
|
|
articleSection := []types.ArticleSection{}
|
|
|
|
|
|
for _, val := range sortBy {
|
|
|
articleSection = append(articleSection, types.ArticleSection{
|
|
|
Id: val.Id,
|
|
|
Content: val.Content,
|
|
|
SortBy: val.SortBy,
|
|
|
TotalComment: val.TotalComment,
|
|
|
})
|
|
|
}
|
|
|
resp = &types.MiniArticleGetResponse{
|
|
|
Id: articleInfo.Id,
|
|
|
Title: articleInfo.Title,
|
|
|
AuthorId: articleInfo.AuthorId,
|
|
|
Author: types.Author{
|
|
|
Id: articleInfo.Author.Id,
|
|
|
Name: articleInfo.Author.Name,
|
|
|
Avatar: articleInfo.Author.Avatar,
|
|
|
Group: articleInfo.Author.Group,
|
|
|
Position: articleInfo.Author.Position,
|
|
|
Company: articleInfo.Author.Company,
|
|
|
},
|
|
|
CreatedAt: articleInfo.CreatedAt,
|
|
|
Section: articleSection,
|
|
|
Images: []string{},
|
|
|
WhoRead: articleInfo.WhoRead,
|
|
|
WhoReview: articleInfo.WhoReview,
|
|
|
Location: types.Location{
|
|
|
Longitude: articleInfo.Location.Longitude,
|
|
|
Latitude: articleInfo.Location.Latitude,
|
|
|
Descript: articleInfo.Location.Descript,
|
|
|
},
|
|
|
CountLove: articleInfo.CountLove,
|
|
|
CountComment: articleInfo.CountComment,
|
|
|
CountRead: articleInfo.CountRead,
|
|
|
Show: int(articleInfo.Show),
|
|
|
}
|
|
|
|
|
|
for _, val := range articleInfo.Images {
|
|
|
resp.Images = append(resp.Images, val.Url)
|
|
|
}
|
|
|
|
|
|
return
|
|
|
} |
...
|
...
|
|