作者 tangxvhui

获取文章详情

... ... @@ -22,6 +22,7 @@ type Author {
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
}
//小程序端创建发布文章
... ... @@ -44,20 +45,29 @@ type (
type (
MiniArticleGetRequest {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
}
MiniArticleGetResponse {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
AuthorId int64 `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Section []ArticleSection `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
ArticleSection {
Id int64 `json:"id"` //段落id
Content string `json:"content"` // 文本内容
SortBy int `json:"sortBy"` // 排序
TotalComment int `json:"totalComment"` // 评论的数量
}
)
... ...
... ... @@ -7,6 +7,7 @@ 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"
)
func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,7 +19,8 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
... ... @@ -46,7 +46,9 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Company: "",
CompanyId: author.CompanyId,
}
if len(req.Images) > 9 {
return nil, xerr.NewErrMsg("图片数量最多9张")
}
//TODO 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
... ... @@ -56,6 +58,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Height: 0,
})
}
//检查文章可被哪些人查看
whoRead := []int64{}
if len(req.WhoRead) > 0 {
... ...
... ... @@ -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
}
... ...
... ... @@ -262,6 +262,7 @@ type Author struct {
Avatar string `json:"avatar"` // 人员头像URL
Group string `json:"group"` // 人员的分组
Position string `json:"position"` // 职位
Company string `json:"company"` // 公司
}
type MiniArticleCreateRequest struct {
... ... @@ -280,21 +281,31 @@ type MiniArticleCreateResponse struct {
type MiniArticleGetRequest struct {
Id int64 `path:"id"` //id
CompanyId int64 `path:"-"`
}
type MiniArticleGetResponse struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int `json:"authorId"` //发布人id
AuthorId int64 `json:"authorId"` //发布人id
Author Author `json:"author"` //发布人
CreatedAt int64 `json:"createdAt"` //文章的发布时间
Section []string `json:"section"` //文章的文本内容
Section []ArticleSection `json:"section"` //文章的文本内容
Images []string `json:"images"` //图片
WhoRead []int64 `json:"whoRead"` //谁可查看
WhoReview []int64 `json:"whoReview"` //谁可评论
Location Location `json:"location"` //定位坐标
CountLove int `json:"countLove"` // 点赞数量
CountComment int `json:"countComment"` // 评论数量
Show int `json:"showState"` // 评论的展示状态(0显示、1不显示)
CountRead int `json:"countRead"` // 浏览数量
Show int `json:"show"` // 评论的展示状态(0显示、1不显示)
}
type ArticleSection struct {
Id int64 `json:"id"` //段落id
Content string `json:"content"` // 文本内容
SortBy int `json:"sortBy"` // 排序
TotalComment int `json:"totalComment"` // 评论的数量
}
type MiniArticleSearchMeRequest struct {
... ...
... ... @@ -120,6 +120,10 @@ func (repository *ArticleSectionRepository) Find(ctx context.Context, conn trans
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...