mirror of https://gitee.com/answerdev/answer.git
feat: question revision add tags
This commit is contained in:
parent
661d8a7f8f
commit
20f0a1b664
|
@ -53,3 +53,20 @@ type Question struct {
|
|||
func (Question) TableName() string {
|
||||
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,6 +2,15 @@ package entity
|
|||
|
||||
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
|
||||
type Revision struct {
|
||||
ID string `xorm:"not null pk autoincr BIGINT(20) id"`
|
||||
|
@ -13,8 +22,8 @@ type Revision struct {
|
|||
Title string `xorm:"not null default '' VARCHAR(255) title"`
|
||||
Content string `xorm:"not null TEXT content"`
|
||||
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"`
|
||||
ReviewUserID string `xorm:"not null default 0 BIGINT(20) review_user_id"`
|
||||
}
|
||||
|
||||
// TableName revision table name
|
||||
|
|
|
@ -116,7 +116,6 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
|
|||
return
|
||||
}
|
||||
|
||||
questionInfo = &schema.QuestionInfo{}
|
||||
question := &entity.Question{}
|
||||
now := time.Now()
|
||||
question.UserID = req.UserID
|
||||
|
@ -146,9 +145,13 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
|
|||
revisionDTO := &schema.AddRevisionDTO{
|
||||
UserID: question.UserID,
|
||||
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)
|
||||
err = qs.revisionService.AddRevision(ctx, revisionDTO, true)
|
||||
if err != nil {
|
||||
|
@ -264,7 +267,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
|
|||
revisionDTO := &schema.AddRevisionDTO{
|
||||
UserID: question.UserID,
|
||||
ObjectID: question.ID,
|
||||
Title: "",
|
||||
Title: question.Title,
|
||||
Log: req.EditSummary,
|
||||
}
|
||||
infoJSON, _ := json.Marshal(question)
|
||||
|
@ -688,3 +691,20 @@ func (qs *QuestionService) CmsSearchAnswerList(ctx context.Context, search *enti
|
|||
}
|
||||
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