作者 tangxvhui

调整创建内容的接口

... ... @@ -30,13 +30,13 @@ service Core {
@handler MiniSetUserLike
post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
@doc "小程序获取文章的编辑记录"
@handler MiniArticleBackupSearch
post /article_backup/search (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse)
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章的编辑记录"
@handler MiniArticleBackupSearch
post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse)
}
... ...
... ... @@ -135,14 +135,15 @@ type (
CompanyId int64 `json:",optional"` // 服务端自动获取
}
MiniArticleBackupSearchResponse {
Total int `json:"total"`
Total int64 `json:"total"`
List []MiniArticleBackupItem `json:"list"`
}
MiniArticleBackupItem {
Id int `json:"id"`
Id int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Images []string `json:"images"`
CreatedAt int `json:"createdAt"`
CreatedAt int64 `json:"createdAt"`
Location Location `json:"location"`
}
)
... ...
... ... @@ -13,15 +13,14 @@ import (
func MiniArticleBackupSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniArticleSearchMeRequest
var req types.MiniArticleBackupSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewMiniArticleBackupSearchLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
l := article.NewMiniArticleBackupSearchLogic(r.Context(), svcCtx)
resp, err := l.MiniArticleBackupSearch(&req)
result.HttpResult(r, w, resp, err)
}
... ...
... ... @@ -199,13 +199,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/article_backup/search",
Handler: article.MiniArticleBackupSearchHandler(serverCtx),
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
Path: "/article_backup/search",
Handler: article.MiniArticleBackupSearchHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
... ...
... ... @@ -2,9 +2,12 @@ package article
import (
"context"
"strings"
"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 +26,44 @@ func NewMiniArticleBackupSearchLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
}
func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniArticleSearchMeRequest) (resp *types.MiniArticleSearchMeResponse, err error) {
// todo: add your logic here and delete this line
func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniArticleBackupSearchRequest) (resp *types.MiniArticleBackupSearchResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
return
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("article_id", req.ArticleId).
MustWithKV("company_id", req.CompanyId)
cnt, backupList, err := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return &types.MiniArticleBackupSearchResponse{}, xerr.NewErrMsgErr("获取编辑记录列表失败", err)
}
resp = &types.MiniArticleBackupSearchResponse{
Total: cnt,
List: make([]types.MiniArticleBackupItem, len(backupList)),
}
for i := range backupList {
content := strings.Builder{}
for _, val2 := range backupList[i].Section {
content.WriteString(val2.Content)
}
images := []string{}
for _, val2 := range backupList[i].Images {
images = append(images, val2.Url)
}
resp.List[i] = types.MiniArticleBackupItem{
Id: backupList[i].Id,
Title: backupList[i].Title,
Content: content.String(),
Images: images,
CreatedAt: backupList[i].CreatedAt,
Location: types.Location{
Longitude: backupList[i].Location.Longitude,
Latitude: backupList[i].Location.Latitude,
Descript: backupList[i].Location.Descript,
},
}
}
return resp, nil
}
... ...
... ... @@ -168,6 +168,20 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
if len(whoRead) > 0 {
newArticle.TargetUser = domain.ArticleTargetLimit
}
//设置内容概要
if len(sectionList) > 0 {
// 截取内容 30个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range sectionList[0].Content {
if runeNumber > 30 {
break
}
runeNumber += 1
stringIndex = i
}
newArticle.Summary = sectionList[0].Content[0:stringIndex]
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
... ...
... ... @@ -392,15 +392,16 @@ type MiniArticleBackupSearchRequest struct {
}
type MiniArticleBackupSearchResponse struct {
Total int `json:"total"`
Total int64 `json:"total"`
List []MiniArticleBackupItem `json:"list"`
}
type MiniArticleBackupItem struct {
Id int `json:"id"`
Id int64 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
Images []string `json:"images"`
CreatedAt int `json:"createdAt"`
CreatedAt int64 `json:"createdAt"`
Location Location `json:"location"`
}
... ...
... ... @@ -30,6 +30,7 @@ type Article struct {
CountComment int // 评论数量
Tags []int64 `gorm:"type:jsonb;serializer:json"` //定性标签
Show int // 评论的展示状态(0显示、1不显示)
Summary string // 内容概要
}
func (m *Article) TableName() string {
... ...
... ... @@ -17,7 +17,8 @@ type ArticleBackup struct {
DeletedAt int64
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
Version int
Operator domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 操作人
Operator domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 操作人
ArticleId int64
Title string // 标题
Section []domain.ArticleSection `gorm:"type:jsonb;serializer:json"` // 分段内容
Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
... ... @@ -25,6 +26,7 @@ type ArticleBackup struct {
WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
Tags []int64 `gorm:"type:jsonb;serializer:json"` // 标签
Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
TargetUser int // 分发方式 0 分发给所有人 1 分发给指定的人
}
... ...
... ... @@ -149,14 +149,16 @@ func (repository *ArticleBackupRepository) ModelToDomainModel(from *models.Artic
DeletedAt: from.DeletedAt,
Version: from.Version,
Operator: from.Operator,
ArticleId: from.ArticleId,
Title: from.Title,
Section: from.Section,
Images: from.Images,
Action: from.Action,
TargetUser: domain.ArticleTarget(from.TargetUser),
Location: from.Location,
WhoRead: from.WhoRead,
WhoReview: from.WhoReview,
Tags: from.Tags,
TargetUser: domain.ArticleTarget(from.TargetUser),
}
// err := copier.Copy(to, from)
return to, nil
... ... @@ -169,14 +171,17 @@ func (repository *ArticleBackupRepository) DomainModelToModel(from *domain.Artic
CreatedAt: from.CreatedAt,
UpdatedAt: from.CreatedAt,
DeletedAt: from.DeletedAt,
IsDel: 0,
Version: from.Version,
Operator: from.Operator,
ArticleId: from.ArticleId,
Title: from.Title,
Section: from.Section,
Images: from.Images,
Action: from.Action,
WhoRead: from.WhoRead,
WhoReview: from.WhoReview,
Location: from.Location,
Tags: from.Tags,
TargetUser: int(from.TargetUser),
}
... ...
... ... @@ -169,6 +169,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
CountRead: from.CountRead,
Show: domain.ArticleShow(from.Show),
Tags: from.Tags,
Summary: from.Summary,
}
return to, nil
}
... ... @@ -195,6 +196,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
CountComment: from.CountComment,
Show: int(from.Show),
Tags: from.Tags,
Summary: from.Summary,
}
// err := copier.Copy(to, from)
return to, nil
... ...
... ... @@ -27,6 +27,7 @@ type Article struct {
CountRead int `json:"countRead"` // 浏览数量
Show ArticleShow `json:"show"` // 评论的展示状态(0显示、1不显示)
Tags []int64 `json:"tags"` // 定性标签
Summary string `json:"summary"` // 内容概要
// ...more
}
... ... @@ -87,6 +88,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art
DeletedAt: 0,
Version: 0,
Operator: operator,
ArticleId: m.Id,
Title: m.Title,
Section: section,
Images: m.Images,
... ...
... ... @@ -14,12 +14,14 @@ type ArticleBackup struct {
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
Operator UserSimple `json:"operator"` // 操作人
Operator UserSimple `json:"operator"` // 操作人
ArticleId int64 `json:"articleId"`
Title string `json:"title"` // 标题
Section []ArticleSection `json:"section"` // 分段内容
Images []Image `json:"images"` // 图片
Action string `json:"action"` // 操作
TargetUser ArticleTarget `json:"targetUser"` // 分发方式 0 分发给所有人 1 分发给指定的人
Location Location `json:"location"` // 定位坐标
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Tags []int64 `json:"tags"` // 标签
... ...