作者 tangxvhui

获取我发布的文章列表

... ... @@ -65,6 +65,9 @@ type (
type (
MiniArticleSearchMeRequest {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
Page int `json:"page"`
Size int `json:"size"`
}
MiniArticleSearchMeResponse {
... ...
... ... @@ -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 MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -18,6 +19,9 @@ func MiniArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := article.NewMiniArticleSearchMeLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.AuthorId = token.UserId
req.CompanyId = token.CompanyId
resp, err := l.MiniArticleSearchMe(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
... ... @@ -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 MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
... ... @@ -16,8 +17,10 @@ func MiniCreateArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.ErrorCtx(r.Context(), w, err)
return
}
token := contextdata.GetUserTokenFromCtx(r.Context())
l := article.NewMiniCreateArticleLogic(r.Context(), svcCtx)
req.AuthorId = token.UserId
resp, err := l.MiniCreateArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
... ... @@ -18,6 +18,7 @@ func MiniGetArticleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := article.NewMiniGetArticleLogic(r.Context(), svcCtx)
resp, err := l.MiniGetArticle(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
... ... @@ -5,6 +5,8 @@ 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"
)
... ... @@ -23,8 +25,36 @@ func NewMiniArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
// MiniArticleSearchMe 获取我发布的文章
func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("authorId", req.AuthorId)
cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
if err != nil {
return &types.MiniArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
}
resp = &types.MiniArticleSearchMeResponse{
Total: int(cnt),
List: make([]types.ArticleSearchMe, len(articleList)),
}
for i := range articleList {
images := []string{}
for _, val2 := range articleList[i].Images {
images = append(images, val2.Url)
}
resp.List[i] = types.ArticleSearchMe{
Id: articleList[i].Id,
Title: articleList[i].Title,
Images: images,
CreatedAt: articleList[i].CreatedAt,
CountLove: articleList[i].CountLove,
CountComment: articleList[i].CountComment,
Show: int(articleList[i].Show),
}
}
return
}
... ...
... ... @@ -288,6 +288,9 @@ type MiniArticleGetResponse struct {
type MiniArticleSearchMeRequest struct {
AuthorId int64 `json:"-"`
CompanyId int64 `json:"-"`
Page int `json:"page"`
Size int `json:"size"`
}
type MiniArticleSearchMeResponse struct {
... ...
... ... @@ -28,6 +28,7 @@ type Article struct {
CountLove int // 点赞数量
CountRead int // 浏览数量
CountComment int // 评论数量
Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
Show int // 评论的展示状态(0显示、1不显示)
}
... ...
... ... @@ -111,7 +111,7 @@ func (repository *ArticleRepository) FindOne(ctx context.Context, conn transacti
return repository.ModelToDomainModel(m)
}
func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*domain.Article, error) {
var (
tx = conn.DB()
ms []*models.Article
... ... @@ -119,7 +119,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx = tx.Model(&ms).Order("id desc").Where("company_id=?", companyId)
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id = ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -125,10 +125,10 @@ func (repository *ArticleTagRepository) Find(ctx context.Context, conn transacti
Order("id desc")
if v, ok := queryOptions["name"]; ok {
tx.Where("id like ?", v)
tx = tx.Where("name like ?", v)
}
if v, ok := queryOptions["group"]; ok {
tx.Where("group like ?", v)
tx = tx.Where("group like ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
... ...
... ... @@ -26,7 +26,7 @@ type Article struct {
CountComment int `json:"countComment"` // 评论数量
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示)
Tags []int64 `json:"tags"`
Tags []int64 `json:"tags"` // 定性标签
// ...more
}
... ... @@ -36,7 +36,7 @@ type ArticleRepository interface {
Delete(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Article, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error)
}
type ArticleTarget int
... ... @@ -74,6 +74,7 @@ func (a ArticleShow) Named() string {
return ""
}
// 设置文章的备份数据
func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
b := ArticleBackup{
Id: 0,
... ...