Merge branch 'feat/0.5.0/timeline_ai' into test

This commit is contained in:
aichy126 2022-11-23 18:11:49 +08:00
commit f4f511e073
15 changed files with 330 additions and 23 deletions

View File

@ -120,7 +120,11 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo) answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)
questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo) questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo)
tagCommonRepo := tag_common.NewTagCommonRepo(dataData, uniqueIDRepo) tagCommonRepo := tag_common.NewTagCommonRepo(dataData, uniqueIDRepo)
objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagCommonRepo) tagRelRepo := tag.NewTagRelRepo(dataData)
revisionRepo := revision.NewRevisionRepo(dataData, uniqueIDRepo)
revisionService := revision_common.NewRevisionService(revisionRepo, userRepo)
tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, revisionService, siteInfoCommonService)
objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagCommonRepo, tagCommonService)
voteRepo := activity_common.NewVoteRepo(dataData, activityRepo) voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)
commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo) commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)
rankService := rank2.NewRankService(userCommon, userRankRepo, objService, configRepo) rankService := rank2.NewRankService(userCommon, userRankRepo, objService, configRepo)
@ -132,10 +136,6 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
voteService := service.NewVoteService(serviceVoteRepo, uniqueIDRepo, configRepo, questionRepo, answerRepo, commentCommonRepo, objService) voteService := service.NewVoteService(serviceVoteRepo, uniqueIDRepo, configRepo, questionRepo, answerRepo, commentCommonRepo, objService)
voteController := controller.NewVoteController(voteService) voteController := controller.NewVoteController(voteService)
tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo) tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)
tagRelRepo := tag.NewTagRelRepo(dataData)
revisionRepo := revision.NewRevisionRepo(dataData, uniqueIDRepo)
revisionService := revision_common.NewRevisionService(revisionRepo, userRepo)
tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, revisionService, siteInfoCommonService)
followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo) followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService) tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService)
tagController := controller.NewTagController(tagService, tagCommonService, rankService) tagController := controller.NewTagController(tagService, tagCommonService, rankService)
@ -163,7 +163,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon) searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon)
searchService := service.NewSearchService(searchParser, searchRepo) searchService := service.NewSearchService(searchParser, searchRepo)
searchController := controller.NewSearchController(searchService) searchController := controller.NewSearchController(searchService)
serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService) serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService)
revisionController := controller.NewRevisionController(serviceRevisionService) revisionController := controller.NewRevisionController(serviceRevisionService)
rankController := controller.NewRankController(rankService) rankController := controller.NewRankController(rankService)
commonRepo := common.NewCommonRepo(dataData, uniqueIDRepo) commonRepo := common.NewCommonRepo(dataData, uniqueIDRepo)

View File

@ -3069,6 +3069,50 @@ const docTemplate = `{
} }
} }
}, },
"/answer/api/v1/revisions/unreviewed": {
"get": {
"description": "get unreviewed revision list",
"produces": [
"application/json"
],
"tags": [
"Revision"
],
"summary": "get unreviewed revision list",
"parameters": [
{
"type": "string",
"description": "page id",
"name": "page",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.GetRevisionResp"
}
}
}
}
]
}
}
}
}
},
"/answer/api/v1/search": { "/answer/api/v1/search": {
"get": { "get": {
"security": [ "security": [

View File

@ -3057,6 +3057,50 @@
} }
} }
}, },
"/answer/api/v1/revisions/unreviewed": {
"get": {
"description": "get unreviewed revision list",
"produces": [
"application/json"
],
"tags": [
"Revision"
],
"summary": "get unreviewed revision list",
"parameters": [
{
"type": "string",
"description": "page id",
"name": "page",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/handler.RespBody"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.GetRevisionResp"
}
}
}
}
]
}
}
}
}
},
"/answer/api/v1/search": { "/answer/api/v1/search": {
"get": { "get": {
"security": [ "security": [

View File

@ -3494,6 +3494,32 @@ paths:
summary: get revision list summary: get revision list
tags: tags:
- Revision - Revision
/answer/api/v1/revisions/unreviewed:
get:
description: get unreviewed revision list
parameters:
- description: page id
in: query
name: page
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/handler.RespBody'
- properties:
data:
items:
$ref: '#/definitions/schema.GetRevisionResp'
type: array
type: object
summary: get unreviewed revision list
tags:
- Revision
/answer/api/v1/search: /answer/api/v1/search:
get: get:
description: search object description: search object

View File

@ -5,6 +5,7 @@ import (
"github.com/answerdev/answer/internal/base/reason" "github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/schema" "github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service" "github.com/answerdev/answer/internal/service"
"github.com/answerdev/answer/pkg/converter"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/errors"
) )
@ -41,3 +42,24 @@ func (rc *RevisionController) GetRevisionList(ctx *gin.Context) {
resp, err := rc.revisionListService.GetRevisionList(ctx, req) resp, err := rc.revisionListService.GetRevisionList(ctx, req)
handler.HandleResponse(ctx, err, resp) handler.HandleResponse(ctx, err, resp)
} }
// GetUnreviewedRevisionList godoc
// @Summary get unreviewed revision list
// @Description get unreviewed revision list
// @Tags Revision
// @Produce json
// @Param page query string true "page id"
// @Success 200 {object} handler.RespBody{data=[]schema.GetRevisionResp}
// @Router /answer/api/v1/revisions/unreviewed [get]
func (rc *RevisionController) GetUnreviewedRevisionList(ctx *gin.Context) {
pageStr := ctx.Query("page")
page := converter.StringToInt(pageStr)
req := &schema.RevisionSearch{
Page: page,
}
resp, count, err := rc.revisionListService.GetUnreviewedRevisionList(ctx, req)
handler.HandleResponse(ctx, err, gin.H{
"list": resp,
"count": count,
})
}

View File

@ -26,6 +26,10 @@ type Revision struct {
ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"` ReviewUserID int64 `xorm:"not null default 0 BIGINT(20) review_user_id"`
} }
type RevisionSearch struct {
Page int `json:"page" form:"page"` // Query number of pages
}
// TableName revision table name // TableName revision table name
func (Revision) TableName() string { func (Revision) TableName() string {
return "revision" return "revision"

View File

@ -149,3 +149,25 @@ func (rr *revisionRepo) allowRecord(objectType int) (ok bool) {
return false return false
} }
} }
func (rr *revisionRepo) SearchUnreviewedList(ctx context.Context, search *entity.RevisionSearch) ([]*entity.Revision, int64, error) {
var count int64
var err error
rows := make([]*entity.Revision, 0)
if search.Page > 0 {
search.Page = search.Page - 1
} else {
search.Page = 0
}
PageSize := 1
offset := search.Page * PageSize
session := rr.data.DB.Where("")
session = session.And("status = ?", entity.RevisionUnreviewedStatus)
session = session.OrderBy("created_at desc")
session = session.Limit(PageSize, offset)
count, err = session.FindAndCount(&rows)
if err != nil {
return rows, count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
return rows, count, nil
}

View File

@ -123,6 +123,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
//revision //revision
r.GET("/revisions", a.revisionController.GetRevisionList) r.GET("/revisions", a.revisionController.GetRevisionList)
r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)
// tag // tag
r.GET("/tags/page", a.tagController.GetTagWithPage) r.GET("/tags/page", a.tagController.GetTagWithPage)

View File

@ -26,6 +26,16 @@ type GetRevisionListReq struct {
ObjectID string `validate:"required" comment:"object_id" form:"object_id"` ObjectID string `validate:"required" comment:"object_id" form:"object_id"`
} }
type RevisionSearch struct {
Page int `json:"page" form:"page"` // Query number of pages
}
type GetUnreviewedRevisionResp struct {
Type string `json:"type"`
Info *UnreviewedRevisionInfoInfo `json:"info"`
UnreviewedInfo *GetRevisionResp `json:"unreviewed_info"`
}
// GetRevisionResp get revision response // GetRevisionResp get revision response
type GetRevisionResp struct { type GetRevisionResp struct {
// id // id

View File

@ -12,3 +12,11 @@ type SimpleObjectInfo struct {
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
} }
type UnreviewedRevisionInfoInfo struct {
ObjectID string `json:"object_id"`
Title string `json:"title"`
Content string `json:"content"`
Html string `json:"html"`
Tags []*TagResp `json:"tags"`
}

View File

@ -20,6 +20,7 @@ type ObjService struct {
questionRepo questioncommon.QuestionRepo questionRepo questioncommon.QuestionRepo
commentRepo comment_common.CommentCommonRepo commentRepo comment_common.CommentCommonRepo
tagRepo tagcommon.TagCommonRepo tagRepo tagcommon.TagCommonRepo
tagCommon *tagcommon.TagCommonService
} }
// NewObjService new object service // NewObjService new object service
@ -27,14 +28,92 @@ func NewObjService(
answerRepo answercommon.AnswerRepo, answerRepo answercommon.AnswerRepo,
questionRepo questioncommon.QuestionRepo, questionRepo questioncommon.QuestionRepo,
commentRepo comment_common.CommentCommonRepo, commentRepo comment_common.CommentCommonRepo,
tagRepo tagcommon.TagCommonRepo) *ObjService { tagRepo tagcommon.TagCommonRepo,
tagCommon *tagcommon.TagCommonService,
) *ObjService {
return &ObjService{ return &ObjService{
answerRepo: answerRepo, answerRepo: answerRepo,
questionRepo: questionRepo, questionRepo: questionRepo,
commentRepo: commentRepo, commentRepo: commentRepo,
tagRepo: tagRepo, tagRepo: tagRepo,
tagCommon: tagCommon,
} }
} }
func (os *ObjService) GetUnreviewedRevisionInfo(ctx context.Context, objectID string) (objInfo *schema.UnreviewedRevisionInfoInfo, err error) {
objInfo = &schema.UnreviewedRevisionInfoInfo{}
objectType, err := obj.GetObjectTypeStrByObjectID(objectID)
if err != nil {
return nil, err
}
switch objectType {
case constant.QuestionObjectType:
questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, objectID)
if err != nil {
return nil, err
}
if !exist {
break
}
taglist, err := os.tagCommon.GetObjectEntityTag(ctx, objectID)
if err != nil {
return nil, err
}
os.tagCommon.TagsFormatRecommendAndReserved(ctx, taglist)
tags, err := os.tagCommon.TagFormat(ctx, taglist)
if err != nil {
return nil, err
}
objInfo = &schema.UnreviewedRevisionInfoInfo{
ObjectID: questionInfo.ID,
Title: questionInfo.Title,
Content: questionInfo.OriginalText,
Html: questionInfo.ParsedText,
Tags: tags,
}
case constant.AnswerObjectType:
answerInfo, exist, err := os.answerRepo.GetAnswer(ctx, objectID)
if err != nil {
return nil, err
}
if !exist {
break
}
questionInfo, exist, err := os.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
if err != nil {
return nil, err
}
if !exist {
break
}
objInfo = &schema.UnreviewedRevisionInfoInfo{
ObjectID: answerInfo.ID,
Title: questionInfo.Title,
Content: answerInfo.OriginalText,
Html: answerInfo.ParsedText,
}
case constant.TagObjectType:
tagInfo, exist, err := os.tagRepo.GetTagByID(ctx, objectID)
if err != nil {
return nil, err
}
if !exist {
break
}
objInfo = &schema.UnreviewedRevisionInfoInfo{
ObjectID: tagInfo.ID,
Title: tagInfo.SlugName,
Content: tagInfo.OriginalText,
Html: tagInfo.ParsedText,
}
}
if objInfo == nil {
err = errors.BadRequest(reason.ObjectNotFound)
}
return objInfo, err
}
// GetInfo get object simple information // GetInfo get object simple information
func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *schema.SimpleObjectInfo, err error) { func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *schema.SimpleObjectInfo, err error) {

View File

@ -386,3 +386,17 @@ func (qs *QuestionCommon) ShowFormat(ctx context.Context, data *entity.Question)
info.Tags = make([]*schema.TagResp, 0) info.Tags = make([]*schema.TagResp, 0)
return &info return &info
} }
func (qs *QuestionCommon) ShowFormatWithTag(ctx context.Context, data *entity.QuestionWithTagsRevision) *schema.QuestionInfo {
info := qs.ShowFormat(ctx, &data.Question)
Tags := make([]*schema.TagResp, 0)
for _, tag := range data.Tags {
item := &schema.TagResp{}
item.SlugName = tag.SlugName
item.DisplayName = tag.DisplayName
item.Recommend = tag.Recommend
item.Reserved = tag.Reserved
Tags = append(Tags, item)
}
info.Tags = Tags
return info
}

View File

@ -15,4 +15,5 @@ type RevisionRepo interface {
GetRevisionList(ctx context.Context, revision *entity.Revision) (revisionList []entity.Revision, err error) GetRevisionList(ctx context.Context, revision *entity.Revision) (revisionList []entity.Revision, err error)
UpdateObjectRevisionId(ctx context.Context, revision *entity.Revision, session *xorm.Session) (err error) UpdateObjectRevisionId(ctx context.Context, revision *entity.Revision, session *xorm.Session) (err error)
ExistUnreviewedByObjectID(ctx context.Context, objectID string) (revision *entity.Revision, exist bool, err error) ExistUnreviewedByObjectID(ctx context.Context, objectID string) (revision *entity.Revision, exist bool, err error)
SearchUnreviewedList(ctx context.Context, search *entity.RevisionSearch) ([]*entity.Revision, int64, error)
} }

View File

@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/base/constant" "github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/entity" "github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/schema" "github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/object_info"
questioncommon "github.com/answerdev/answer/internal/service/question_common" questioncommon "github.com/answerdev/answer/internal/service/question_common"
"github.com/answerdev/answer/internal/service/revision" "github.com/answerdev/answer/internal/service/revision"
usercommon "github.com/answerdev/answer/internal/service/user_common" usercommon "github.com/answerdev/answer/internal/service/user_common"
@ -15,25 +16,56 @@ import (
// RevisionService user service // RevisionService user service
type RevisionService struct { type RevisionService struct {
revisionRepo revision.RevisionRepo revisionRepo revision.RevisionRepo
userCommon *usercommon.UserCommon userCommon *usercommon.UserCommon
questionCommon *questioncommon.QuestionCommon questionCommon *questioncommon.QuestionCommon
answerService *AnswerService answerService *AnswerService
objectInfoService *object_info.ObjService
} }
func NewRevisionService( func NewRevisionService(
revisionRepo revision.RevisionRepo, revisionRepo revision.RevisionRepo,
userCommon *usercommon.UserCommon, userCommon *usercommon.UserCommon,
questionCommon *questioncommon.QuestionCommon, questionCommon *questioncommon.QuestionCommon,
answerService *AnswerService) *RevisionService { answerService *AnswerService,
objectInfoService *object_info.ObjService,
) *RevisionService {
return &RevisionService{ return &RevisionService{
revisionRepo: revisionRepo, revisionRepo: revisionRepo,
userCommon: userCommon, userCommon: userCommon,
questionCommon: questionCommon, questionCommon: questionCommon,
answerService: answerService, answerService: answerService,
objectInfoService: objectInfoService,
} }
} }
// SearchUnreviewedList get unreviewed list
func (rs *RevisionService) GetUnreviewedRevisionList(ctx context.Context, req *schema.RevisionSearch) (resp []*schema.GetUnreviewedRevisionResp, count int64, err error) {
resp = []*schema.GetUnreviewedRevisionResp{}
search := &entity.RevisionSearch{}
_ = copier.Copy(search, req)
list, count, err := rs.revisionRepo.SearchUnreviewedList(ctx, search)
for _, revision := range list {
item := &schema.GetUnreviewedRevisionResp{}
_, ok := constant.ObjectTypeNumberMapping[revision.ObjectType]
if !ok {
continue
}
item.Type = constant.ObjectTypeNumberMapping[revision.ObjectType]
info, infoerr := rs.objectInfoService.GetUnreviewedRevisionInfo(ctx, revision.ObjectID)
if infoerr != nil {
return resp, 0, infoerr
}
item.Info = info
revisionitem := &schema.GetRevisionResp{}
_ = copier.Copy(revisionitem, revision)
rs.parseItem(ctx, revisionitem)
item.UnreviewedInfo = revisionitem
resp = append(resp, item)
}
return
}
// GetRevisionList get revision list all // GetRevisionList get revision list all
func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetRevisionListReq) (resp []schema.GetRevisionResp, err error) { func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetRevisionListReq) (resp []schema.GetRevisionResp, err error) {
var ( var (
@ -75,7 +107,7 @@ func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetR
func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisionResp) { func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisionResp) {
var ( var (
err error err error
question entity.Question question entity.QuestionWithTagsRevision
questionInfo *schema.QuestionInfo questionInfo *schema.QuestionInfo
answer entity.Answer answer entity.Answer
answerInfo *schema.AnswerInfo answerInfo *schema.AnswerInfo
@ -89,7 +121,7 @@ func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisi
if err != nil { if err != nil {
break break
} }
questionInfo = rs.questionCommon.ShowFormat(ctx, &question) questionInfo = rs.questionCommon.ShowFormatWithTag(ctx, &question)
item.ContentParsed = questionInfo item.ContentParsed = questionInfo
case constant.ObjectTypeStrMapping["answer"]: case constant.ObjectTypeStrMapping["answer"]:
err = json.Unmarshal([]byte(item.Content), &answer) err = json.Unmarshal([]byte(item.Content), &answer)

View File

@ -70,7 +70,7 @@ func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.Searc
if err != nil { if err != nil {
return return
} }
ts.tagsFormatRecommendAndReserved(ctx, tags) ts.TagsFormatRecommendAndReserved(ctx, tags)
for _, tag := range tags { for _, tag := range tags {
item := schema.SearchTagLikeResp{} item := schema.SearchTagLikeResp{}
item.SlugName = tag.SlugName item.SlugName = tag.SlugName
@ -168,7 +168,7 @@ func (ts *TagCommonService) GetTagListByNames(ctx context.Context, tagNames []st
if err != nil { if err != nil {
return nil, err return nil, err
} }
ts.tagsFormatRecommendAndReserved(ctx, tagList) ts.TagsFormatRecommendAndReserved(ctx, tagList)
return tagList, nil return tagList, nil
} }
@ -233,7 +233,7 @@ func (ts *TagCommonService) GetTagListByIDs(ctx context.Context, ids []string) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
ts.tagsFormatRecommendAndReserved(ctx, tagList) ts.TagsFormatRecommendAndReserved(ctx, tagList)
return return
} }
@ -244,7 +244,7 @@ func (ts *TagCommonService) GetTagPage(ctx context.Context, page, pageSize int,
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
ts.tagsFormatRecommendAndReserved(ctx, tagList) ts.TagsFormatRecommendAndReserved(ctx, tagList)
return return
} }
@ -278,7 +278,7 @@ func (ts *TagCommonService) TagFormat(ctx context.Context, tags []*entity.Tag) (
return objTags, nil return objTags, nil
} }
func (ts *TagCommonService) tagsFormatRecommendAndReserved(ctx context.Context, tagList []*entity.Tag) { func (ts *TagCommonService) TagsFormatRecommendAndReserved(ctx context.Context, tagList []*entity.Tag) {
if len(tagList) == 0 { if len(tagList) == 0 {
return return
} }