mirror of https://gitee.com/answerdev/answer.git
feat: question revision add tags
This commit is contained in:
parent
661d8a7f8f
commit
20f0a1b664
|
@ -46,10 +46,27 @@ type Question struct {
|
||||||
AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`
|
AcceptedAnswerID string `xorm:"not null default 0 BIGINT(20) accepted_answer_id"`
|
||||||
LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`
|
LastAnswerID string `xorm:"not null default 0 BIGINT(20) last_answer_id"`
|
||||||
PostUpdateTime time.Time `xorm:"default CURRENT_TIMESTAMP TIMESTAMP post_update_time"`
|
PostUpdateTime time.Time `xorm:"default CURRENT_TIMESTAMP TIMESTAMP post_update_time"`
|
||||||
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName question table name
|
// TableName question table name
|
||||||
func (Question) TableName() string {
|
func (Question) TableName() string {
|
||||||
return "question"
|
return "question"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QuestionWithTagsRevision question
|
||||||
|
type QuestionWithTagsRevision struct {
|
||||||
|
Question
|
||||||
|
Tags []*TagSimpleInfoForRevision `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TagSimpleInfoForRevision tag simple info for revision
|
||||||
|
type TagSimpleInfoForRevision struct {
|
||||||
|
ID string `xorm:"not null pk comment('tag_id') BIGINT(20) id"`
|
||||||
|
MainTagID int64 `xorm:"not null default 0 BIGINT(20) main_tag_id"`
|
||||||
|
SlugName string `xorm:"not null default '' unique VARCHAR(35) slug_name"`
|
||||||
|
DisplayName string `xorm:"not null default '' VARCHAR(35) display_name"`
|
||||||
|
Recommend bool `xorm:"not null default false BOOL recommend"`
|
||||||
|
Reserved bool `xorm:"not null default false BOOL reserved"`
|
||||||
|
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
|
||||||
|
}
|
||||||
|
|
|
@ -2,19 +2,28 @@ package entity
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
// RevisionUnreviewedStatus this revision is unreviewed
|
||||||
|
RevisionUnreviewedStatus = 1
|
||||||
|
// RevisionReviewPassStatus this revision is reviewed and approved by operator
|
||||||
|
RevisionReviewPassStatus = 2
|
||||||
|
// RevisionReviewRejectStatus this revision is reviewed and rejected by operator
|
||||||
|
RevisionReviewRejectStatus = 3
|
||||||
|
)
|
||||||
|
|
||||||
// Revision revision
|
// Revision revision
|
||||||
type Revision struct {
|
type Revision struct {
|
||||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||||
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`
|
||||||
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`
|
||||||
UserID string `xorm:"not null default 0 BIGINT(20) user_id"`
|
UserID string `xorm:"not null default 0 BIGINT(20) user_id"`
|
||||||
ObjectType int `xorm:"not null default 0 ) INT(11) object_type"`
|
ObjectType int `xorm:"not null default 0 ) INT(11) object_type"`
|
||||||
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"`
|
||||||
Title string `xorm:"not null default '' VARCHAR(255) title"`
|
Title string `xorm:"not null default '' VARCHAR(255) title"`
|
||||||
Content string `xorm:"not null TEXT content"`
|
Content string `xorm:"not null TEXT content"`
|
||||||
Log string `xorm:"VARCHAR(255) log"`
|
Log string `xorm:"VARCHAR(255) log"`
|
||||||
// Status todo: this field is not used, will be removed in the future
|
Status int `xorm:"not null default 1 INT(11) status"`
|
||||||
Status int `xorm:"not null default 1 INT(11) status"`
|
ReviewUserID string `xorm:"not null default 0 BIGINT(20) review_user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName revision table name
|
// TableName revision table name
|
||||||
|
|
|
@ -116,7 +116,6 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
questionInfo = &schema.QuestionInfo{}
|
|
||||||
question := &entity.Question{}
|
question := &entity.Question{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
question.UserID = req.UserID
|
question.UserID = req.UserID
|
||||||
|
@ -146,9 +145,13 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
|
||||||
revisionDTO := &schema.AddRevisionDTO{
|
revisionDTO := &schema.AddRevisionDTO{
|
||||||
UserID: question.UserID,
|
UserID: question.UserID,
|
||||||
ObjectID: question.ID,
|
ObjectID: question.ID,
|
||||||
Title: "",
|
Title: question.Title,
|
||||||
}
|
}
|
||||||
infoJSON, _ := json.Marshal(question)
|
questionWithTagsRevision, err := qs.changeQuestionToRevision(ctx, question)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
infoJSON, _ := json.Marshal(questionWithTagsRevision)
|
||||||
revisionDTO.Content = string(infoJSON)
|
revisionDTO.Content = string(infoJSON)
|
||||||
err = qs.revisionService.AddRevision(ctx, revisionDTO, true)
|
err = qs.revisionService.AddRevision(ctx, revisionDTO, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -264,7 +267,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
||||||
revisionDTO := &schema.AddRevisionDTO{
|
revisionDTO := &schema.AddRevisionDTO{
|
||||||
UserID: question.UserID,
|
UserID: question.UserID,
|
||||||
ObjectID: question.ID,
|
ObjectID: question.ID,
|
||||||
Title: "",
|
Title: question.Title,
|
||||||
Log: req.EditSummary,
|
Log: req.EditSummary,
|
||||||
}
|
}
|
||||||
infoJSON, _ := json.Marshal(question)
|
infoJSON, _ := json.Marshal(question)
|
||||||
|
@ -688,3 +691,20 @@ func (qs *QuestionService) CmsSearchAnswerList(ctx context.Context, search *enti
|
||||||
}
|
}
|
||||||
return answerlist, count, nil
|
return answerlist, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questionInfo *entity.Question) (
|
||||||
|
questionRevision *entity.QuestionWithTagsRevision, err error) {
|
||||||
|
questionRevision = &entity.QuestionWithTagsRevision{}
|
||||||
|
questionRevision.Question = *questionInfo
|
||||||
|
|
||||||
|
tags, err := qs.tagCommon.GetObjectEntityTag(ctx, questionInfo.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, tag := range tags {
|
||||||
|
item := &entity.TagSimpleInfoForRevision{}
|
||||||
|
_ = copier.Copy(item, tag)
|
||||||
|
questionRevision.Tags = append(questionRevision.Tags, item)
|
||||||
|
}
|
||||||
|
return questionRevision, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue