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.

update question pin and show

aichy126a038664fb403
diff --git a/docs/docs.go b/docs/docs.go
index 73ff9ecd..f0954b62 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -6948,6 +6948,14 @@ const docTemplate = `{
"operator": {
"$ref": "#/definitions/schema.QuestionPageRespOperator"
},
+ "pin": {
+ "description": "1: unpin, 2: pin",
+ "type": "integer"
+ },
+ "show": {
+ "description": "0: show, 1: hide",
+ "type": "integer"
+ },
"status": {
"type": "integer"
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 75078211..124e77ba 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -6936,6 +6936,14 @@
"operator": {
"$ref": "#/definitions/schema.QuestionPageRespOperator"
},
+ "pin": {
+ "description": "1: unpin, 2: pin",
+ "type": "integer"
+ },
+ "show": {
+ "description": "0: show, 1: hide",
+ "type": "integer"
+ },
"status": {
"type": "integer"
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 200abf16..902d037f 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1105,6 +1105,12 @@ definitions:
type: string
operator:
$ref: '#/definitions/schema.QuestionPageRespOperator'
+ pin:
+ description: '1: unpin, 2: pin'
+ type: integer
+ show:
+ description: '0: show, 1: hide'
+ type: integer
status:
type: integer
tags:
diff --git a/internal/entity/question_entity.go b/internal/entity/question_entity.go
index 4b4f4923..41c9236b 100644
--- a/internal/entity/question_entity.go
+++ b/internal/entity/question_entity.go
@@ -8,6 +8,10 @@ const (
QuestionStatusAvailable = 1
QuestionStatusClosed = 2
QuestionStatusDeleted = 10
+ QuestionUnPin = 1
+ QuestionPin = 2
+ QuestionShow = 1
+ QuestionHide = 2
)
var AdminQuestionSearchStatus = map[string]int{
@@ -32,6 +36,8 @@ type Question struct {
Title string `xorm:"not null default '' VARCHAR(150) title"`
OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
+ Pin int `xorm:"not null default 1 INT(11) pin"`
+ Show int `xorm:"not null default 1 INT(11) show"`
Status int `xorm:"not null default 1 INT(11) status"`
ViewCount int `xorm:"not null default 0 INT(11) view_count"`
UniqueViewCount int `xorm:"not null default 0 INT(11) unique_view_count"`
diff --git a/internal/migrations/v8.go b/internal/migrations/v8.go
index 325738d0..dd46a558 100644
--- a/internal/migrations/v8.go
+++ b/internal/migrations/v8.go
@@ -1,6 +1,8 @@
package migrations
import (
+ "time"
+
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/service/permission"
"xorm.io/xorm"
@@ -51,6 +53,33 @@ func addRolePinAndHideFeatures(x *xorm.Engine) error {
return err
}
}
+ type Question struct {
+ ID string `xorm:"not null pk BIGINT(20) id"`
+ CreatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`
+ UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"`
+ UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`
+ LastEditUserID string `xorm:"not null default 0 BIGINT(20) last_edit_user_id"`
+ Title string `xorm:"not null default '' VARCHAR(150) title"`
+ OriginalText string `xorm:"not null MEDIUMTEXT original_text"`
+ ParsedText string `xorm:"not null MEDIUMTEXT parsed_text"`
+ Status int `xorm:"not null default 1 INT(11) status"`
+ Pin int `xorm:"not null default 1 INT(11) pin"`
+ Show int `xorm:"not null default 1 INT(11) show"`
+ ViewCount int `xorm:"not null default 0 INT(11) view_count"`
+ UniqueViewCount int `xorm:"not null default 0 INT(11) unique_view_count"`
+ VoteCount int `xorm:"not null default 0 INT(11) vote_count"`
+ AnswerCount int `xorm:"not null default 0 INT(11) answer_count"`
+ CollectionCount int `xorm:"not null default 0 INT(11) collection_count"`
+ FollowCount int `xorm:"not null default 0 INT(11) follow_count"`
+ AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`
+ LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`
+ PostUpdateTime time.Time `xorm:"post_update_time TIMESTAMP"`
+ RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
+ }
+ err := x.Sync(new(Question))
+ if err != nil {
+ return err
+ }
return nil
}
diff --git a/internal/repo/question/question_repo.go b/internal/repo/question/question_repo.go
index 5b1ab705..5c05dd19 100644
--- a/internal/repo/question/question_repo.go
+++ b/internal/repo/question/question_repo.go
@@ -258,19 +258,22 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
}
if len(userID) > 0 {
session.And("question.user_id = ?", userID)
+ } else {
+ session.And("question.show = ?", entity.QuestionShow)
}
+
switch orderCond {
case "newest":
- session.OrderBy("question.created_at DESC")
+ session.OrderBy("question.pin desc,question.created_at DESC")
case "active":
- session.OrderBy("question.post_update_time DESC, question.updated_at DESC")
+ session.OrderBy("question.pin desc,question.post_update_time DESC, question.updated_at DESC")
case "frequent":
- session.OrderBy("question.view_count DESC")
+ session.OrderBy("question.pin desc,question.view_count DESC")
case "score":
- session.OrderBy("question.vote_count DESC, question.view_count DESC")
+ session.OrderBy("question.pin desc,question.vote_count DESC, question.view_count DESC")
case "unanswered":
session.Where("question.last_answer_id = 0")
- session.OrderBy("question.created_at DESC")
+ session.OrderBy("question.pin desc,question.created_at DESC")
}
total, err = pager.Help(page, pageSize, &questionList, &entity.Question{}, session)
diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go
index a051ab83..b5b523e8 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -311,6 +311,8 @@ type QuestionPageResp struct {
Title string `json:"title"`
UrlTitle string `json:"url_title"`
Description string `json:"description"`
+ Pin int `json:"pin"` // 1: unpin, 2: pin
+ Show int `json:"show"` // 0: show, 1: hide
Status int `json:"status"`
Tags []*TagResp `json:"tags"`
diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go
index a0d039fc..4b4f259b 100644
--- a/internal/service/question_common/question.go
+++ b/internal/service/question_common/question.go
@@ -271,6 +271,8 @@ func (qs *QuestionCommon) FormatQuestionsPage(
FollowCount: questionInfo.FollowCount,
AcceptedAnswerID: questionInfo.AcceptedAnswerID,
LastAnswerID: questionInfo.LastAnswerID,
+ Pin: questionInfo.Pin,
+ Show: questionInfo.Show,
}
questionIDs = append(questionIDs, questionInfo.ID)