mirror of https://gitee.com/answerdev/answer.git
update unreviewed revision
This commit is contained in:
parent
a923e6f0b4
commit
3cd52758f3
|
@ -120,7 +120,11 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
answerRepo := answer.NewAnswerRepo(dataData, uniqueIDRepo, userRankRepo, activityRepo)
|
||||
questionRepo := question.NewQuestionRepo(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)
|
||||
commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)
|
||||
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)
|
||||
voteController := controller.NewVoteController(voteService)
|
||||
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)
|
||||
tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService)
|
||||
tagController := controller.NewTagController(tagService, tagCommonService, rankService)
|
||||
|
|
|
@ -31,7 +31,9 @@ type RevisionSearch struct {
|
|||
}
|
||||
|
||||
type GetUnreviewedRevisionResp struct {
|
||||
Type string `json:"type"`
|
||||
Type string `json:"type"`
|
||||
Info *UnreviewedRevisionInfoInfo `json:"info"`
|
||||
UnreviewedInfo *GetRevisionResp `json:"unreviewed_info"`
|
||||
}
|
||||
|
||||
// GetRevisionResp get revision response
|
||||
|
|
|
@ -12,3 +12,11 @@ type SimpleObjectInfo struct {
|
|||
Title string `json:"title"`
|
||||
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"`
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ type ObjService struct {
|
|||
questionRepo questioncommon.QuestionRepo
|
||||
commentRepo comment_common.CommentCommonRepo
|
||||
tagRepo tagcommon.TagCommonRepo
|
||||
tagCommon *tagcommon.TagCommonService
|
||||
}
|
||||
|
||||
// NewObjService new object service
|
||||
|
@ -27,14 +28,92 @@ func NewObjService(
|
|||
answerRepo answercommon.AnswerRepo,
|
||||
questionRepo questioncommon.QuestionRepo,
|
||||
commentRepo comment_common.CommentCommonRepo,
|
||||
tagRepo tagcommon.TagCommonRepo) *ObjService {
|
||||
tagRepo tagcommon.TagCommonRepo,
|
||||
tagCommon *tagcommon.TagCommonService,
|
||||
) *ObjService {
|
||||
return &ObjService{
|
||||
answerRepo: answerRepo,
|
||||
questionRepo: questionRepo,
|
||||
commentRepo: commentRepo,
|
||||
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
|
||||
func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *schema.SimpleObjectInfo, err error) {
|
||||
|
|
|
@ -386,3 +386,17 @@ func (qs *QuestionCommon) ShowFormat(ctx context.Context, data *entity.Question)
|
|||
info.Tags = make([]*schema.TagResp, 0)
|
||||
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
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
||||
"github.com/answerdev/answer/internal/service/revision"
|
||||
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
|
@ -47,18 +46,23 @@ func (rs *RevisionService) GetUnreviewedRevisionList(ctx context.Context, req *s
|
|||
_ = copier.Copy(search, req)
|
||||
list, count, err := rs.revisionRepo.SearchUnreviewedList(ctx, search)
|
||||
for _, revision := range list {
|
||||
spew.Dump(revision)
|
||||
item := &schema.GetUnreviewedRevisionResp{}
|
||||
_, ok := constant.ObjectTypeNumberMapping[revision.ObjectType]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
item.Type = constant.ObjectTypeNumberMapping[revision.ObjectType]
|
||||
info, err := rs.objectInfoService.GetInfo(ctx, revision.ObjectID)
|
||||
spew.Dump(info, err)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -103,7 +107,7 @@ func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetR
|
|||
func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisionResp) {
|
||||
var (
|
||||
err error
|
||||
question entity.Question
|
||||
question entity.QuestionWithTagsRevision
|
||||
questionInfo *schema.QuestionInfo
|
||||
answer entity.Answer
|
||||
answerInfo *schema.AnswerInfo
|
||||
|
@ -117,7 +121,7 @@ func (rs *RevisionService) parseItem(ctx context.Context, item *schema.GetRevisi
|
|||
if err != nil {
|
||||
break
|
||||
}
|
||||
questionInfo = rs.questionCommon.ShowFormat(ctx, &question)
|
||||
questionInfo = rs.questionCommon.ShowFormatWithTag(ctx, &question)
|
||||
item.ContentParsed = questionInfo
|
||||
case constant.ObjectTypeStrMapping["answer"]:
|
||||
err = json.Unmarshal([]byte(item.Content), &answer)
|
||||
|
|
|
@ -70,7 +70,7 @@ func (ts *TagCommonService) SearchTagLike(ctx context.Context, req *schema.Searc
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
ts.tagsFormatRecommendAndReserved(ctx, tags)
|
||||
ts.TagsFormatRecommendAndReserved(ctx, tags)
|
||||
for _, tag := range tags {
|
||||
item := schema.SearchTagLikeResp{}
|
||||
item.SlugName = tag.SlugName
|
||||
|
@ -168,7 +168,7 @@ func (ts *TagCommonService) GetTagListByNames(ctx context.Context, tagNames []st
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ts.tagsFormatRecommendAndReserved(ctx, tagList)
|
||||
ts.TagsFormatRecommendAndReserved(ctx, tagList)
|
||||
return tagList, nil
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ func (ts *TagCommonService) GetTagListByIDs(ctx context.Context, ids []string) (
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ts.tagsFormatRecommendAndReserved(ctx, tagList)
|
||||
ts.TagsFormatRecommendAndReserved(ctx, tagList)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ func (ts *TagCommonService) GetTagPage(ctx context.Context, page, pageSize int,
|
|||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
ts.tagsFormatRecommendAndReserved(ctx, tagList)
|
||||
ts.TagsFormatRecommendAndReserved(ctx, tagList)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ func (ts *TagCommonService) TagFormat(ctx context.Context, tags []*entity.Tag) (
|
|||
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 {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue