update question pin and show

This commit is contained in:
aichy126 2023-04-13 15:46:36 +08:00
parent 13931e8da1
commit a038664fb4
8 changed files with 69 additions and 5 deletions

View File

@ -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"
},

View File

@ -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"
},

View File

@ -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:

View File

@ -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"`

View File

@ -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
}

View File

@ -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)

View File

@ -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"`

View File

@ -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)