Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

add question and tags Description

aichy126d8682e726428
diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go
index 65c66d51..25d20557 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -97,6 +97,7 @@ type QuestionInfo struct {
Title string `json:"title" xorm:"title"` // title
Content string `json:"content" xorm:"content"` // content
HTML string `json:"html" xorm:"html"` // html
+ Description string `json:"description"` //description
Tags []*TagResp `json:"tags" ` // tags
ViewCount int `json:"view_count" xorm:"view_count"` // view_count
UniqueViewCount int `json:"unique_view_count" xorm:"unique_view_count"` // unique_view_count
diff --git a/internal/schema/tag_schema.go b/internal/schema/tag_schema.go
index 796b6bb8..278b309d 100644
--- a/internal/schema/tag_schema.go
+++ b/internal/schema/tag_schema.go
@@ -66,6 +66,8 @@ type GetTagResp struct {
OriginalText string `json:"original_text"`
// parsed text
ParsedText string `json:"parsed_text"`
+ // description text
+ Description string `json:"description"`
// follower amount
FollowCount int `json:"follow_count"`
// question amount
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index cca6b9f2..ea46c533 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -23,6 +23,7 @@ import (
"github.com/answerdev/answer/internal/service/revision_common"
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
usercommon "github.com/answerdev/answer/internal/service/user_common"
+ "github.com/answerdev/answer/pkg/htmltext"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/i18n"
@@ -454,6 +455,7 @@ func (qs *QuestionService) GetQuestion(ctx context.Context, questionID, userID s
if question.Status == entity.QuestionStatusClosed {
per.CanClose = false
}
+ question.Description = htmltext.FetchExcerpt(question.HTML, "...", 240)
question.MemberActions = permission.GetQuestionPermission(ctx, userID, question.UserID,
per.CanEdit, per.CanDelete, per.CanClose, per.CanReopen)
return question, nil
diff --git a/internal/service/tag/tag_service.go b/internal/service/tag/tag_service.go
index 1504f4fe..8ebe610c 100644
--- a/internal/service/tag/tag_service.go
+++ b/internal/service/tag/tag_service.go
@@ -105,6 +105,7 @@ func (ts *TagService) GetTagInfo(ctx context.Context, req *schema.GetTagInfoReq)
resp.DisplayName = tagInfo.DisplayName
resp.OriginalText = tagInfo.OriginalText
resp.ParsedText = tagInfo.ParsedText
+ resp.Description = htmltext.FetchExcerpt(tagInfo.ParsedText, "...", 240)
resp.FollowCount = tagInfo.FollowCount
resp.QuestionCount = tagInfo.QuestionCount
resp.Recommend = tagInfo.Recommend