diff --git a/internal/entity/question_entity.go b/internal/entity/question_entity.go index 83de9520..64c982ed 100644 --- a/internal/entity/question_entity.go +++ b/internal/entity/question_entity.go @@ -46,10 +46,27 @@ type Question struct { 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:"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 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"` +} diff --git a/internal/entity/revision_entity.go b/internal/entity/revision_entity.go index 48740ef2..e439dcb2 100644 --- a/internal/entity/revision_entity.go +++ b/internal/entity/revision_entity.go @@ -2,19 +2,28 @@ 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"` - CreatedAt time.Time `xorm:"created TIMESTAMP created_at"` - UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"` - UserID string `xorm:"not null default 0 BIGINT(20) user_id"` - ObjectType int `xorm:"not null default 0 ) INT(11) object_type"` - ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"` - 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"` + ID string `xorm:"not null pk autoincr BIGINT(20) id"` + CreatedAt time.Time `xorm:"created TIMESTAMP created_at"` + UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"` + UserID string `xorm:"not null default 0 BIGINT(20) user_id"` + ObjectType int `xorm:"not null default 0 ) INT(11) object_type"` + ObjectID string `xorm:"not null default 0 BIGINT(20) INDEX object_id"` + Title string `xorm:"not null default '' VARCHAR(255) title"` + Content string `xorm:"not null TEXT content"` + Log string `xorm:"VARCHAR(255) log"` + 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 diff --git a/internal/service/question_service.go b/internal/service/question_service.go index 6f36fbe7..4d7764b9 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -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 +}