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 edit userid
aichy126b093358e0cf4
diff --git a/docs/docs.go b/docs/docs.goindex eb99dfca..9de9e8fc 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -3074,7 +3074,7 @@ const docTemplate = `{"ApiKeyAuth": []}],- "description": "check can update question",+ "description": "check can update revision","consumes": ["application/json"],@@ -3084,7 +3084,7 @@ const docTemplate = `{"tags": ["Revision"],- "summary": "check can update question",+ "summary": "check can update revision","parameters": [{"type": "string",@@ -3141,10 +3141,22 @@ const docTemplate = `{"type": "object","properties": {"data": {- "type": "array",- "items": {- "$ref": "#/definitions/schema.GetRevisionResp"- }+ "allOf": [+ {+ "$ref": "#/definitions/pager.PageModel"+ },+ {+ "type": "object",+ "properties": {+ "list": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.GetUnreviewedRevisionResp"+ }+ }+ }+ }+ ]}}}@@ -3470,10 +3482,7 @@ const docTemplate = `{"type": "object","properties": {"data": {- "type": "array",- "items": {- "$ref": "#/definitions/schema.GetTagSynonymsResp"- }+ "$ref": "#/definitions/schema.GetTagSynonymsResp"}}}@@ -4701,6 +4710,9 @@ const docTemplate = `{"answer_id": {"type": "string"},+ "display_name": {+ "type": "string"+ },"object_type": {"type": "string"},@@ -5547,21 +5559,33 @@ const docTemplate = `{"schema.GetTagSynonymsResp": {"type": "object","properties": {- "display_name": {- "description": "display name",- "type": "string"+ "member_actions": {+ "description": "MemberActions",+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.PermissionMemberAction"+ }},- "main_tag_slug_name": {- "description": "if main tag slug name is not empty, this tag is synonymous with the main tag",- "type": "string"+ "synonyms": {+ "description": "synonyms",+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.TagSynonym"+ }+ }+ }+ },+ "schema.GetUnreviewedRevisionResp": {+ "type": "object",+ "properties": {+ "info": {+ "$ref": "#/definitions/schema.UnreviewedRevisionInfoInfo"},- "slug_name": {- "description": "slug name",+ "type": {"type": "string"},- "tag_id": {- "description": "tag id",- "type": "string"+ "unreviewed_info": {+ "$ref": "#/definitions/schema.GetRevisionResp"}}},@@ -6203,9 +6227,7 @@ const docTemplate = `{"type": "object","required": ["contact_email",- "description","name",- "short_description","site_url"],"properties": {@@ -6235,9 +6257,7 @@ const docTemplate = `{"type": "object","required": ["contact_email",- "description","name",- "short_description","site_url"],"properties": {@@ -6425,6 +6445,50 @@ const docTemplate = `{}}},+ "schema.TagSynonym": {+ "type": "object",+ "properties": {+ "display_name": {+ "description": "display name",+ "type": "string"+ },+ "main_tag_slug_name": {+ "description": "if main tag slug name is not empty, this tag is synonymous with the main tag",+ "type": "string"+ },+ "slug_name": {+ "description": "slug name",+ "type": "string"+ },+ "tag_id": {+ "description": "tag id",+ "type": "string"+ }+ }+ },+ "schema.UnreviewedRevisionInfoInfo": {+ "type": "object",+ "properties": {+ "content": {+ "type": "string"+ },+ "html": {+ "type": "string"+ },+ "object_id": {+ "type": "string"+ },+ "tags": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.TagResp"+ }+ },+ "title": {+ "type": "string"+ }+ }+ },"schema.UpdateCommentReq": {"type": "object","required": [diff --git a/docs/swagger.json b/docs/swagger.jsonindex 6af9f310..b1eaec18 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -3062,7 +3062,7 @@"ApiKeyAuth": []}],- "description": "check can update question",+ "description": "check can update revision","consumes": ["application/json"],@@ -3072,7 +3072,7 @@"tags": ["Revision"],- "summary": "check can update question",+ "summary": "check can update revision","parameters": [{"type": "string",@@ -3129,10 +3129,22 @@"type": "object","properties": {"data": {- "type": "array",- "items": {- "$ref": "#/definitions/schema.GetRevisionResp"- }+ "allOf": [+ {+ "$ref": "#/definitions/pager.PageModel"+ },+ {+ "type": "object",+ "properties": {+ "list": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.GetUnreviewedRevisionResp"+ }+ }+ }+ }+ ]}}}@@ -3458,10 +3470,7 @@"type": "object","properties": {"data": {- "type": "array",- "items": {- "$ref": "#/definitions/schema.GetTagSynonymsResp"- }+ "$ref": "#/definitions/schema.GetTagSynonymsResp"}}}@@ -4689,6 +4698,9 @@"answer_id": {"type": "string"},+ "display_name": {+ "type": "string"+ },"object_type": {"type": "string"},@@ -5535,21 +5547,33 @@"schema.GetTagSynonymsResp": {"type": "object","properties": {- "display_name": {- "description": "display name",- "type": "string"+ "member_actions": {+ "description": "MemberActions",+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.PermissionMemberAction"+ }},- "main_tag_slug_name": {- "description": "if main tag slug name is not empty, this tag is synonymous with the main tag",- "type": "string"+ "synonyms": {+ "description": "synonyms",+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.TagSynonym"+ }+ }+ }+ },+ "schema.GetUnreviewedRevisionResp": {+ "type": "object",+ "properties": {+ "info": {+ "$ref": "#/definitions/schema.UnreviewedRevisionInfoInfo"},- "slug_name": {- "description": "slug name",+ "type": {"type": "string"},- "tag_id": {- "description": "tag id",- "type": "string"+ "unreviewed_info": {+ "$ref": "#/definitions/schema.GetRevisionResp"}}},@@ -6191,9 +6215,7 @@"type": "object","required": ["contact_email",- "description","name",- "short_description","site_url"],"properties": {@@ -6223,9 +6245,7 @@"type": "object","required": ["contact_email",- "description","name",- "short_description","site_url"],"properties": {@@ -6413,6 +6433,50 @@}}},+ "schema.TagSynonym": {+ "type": "object",+ "properties": {+ "display_name": {+ "description": "display name",+ "type": "string"+ },+ "main_tag_slug_name": {+ "description": "if main tag slug name is not empty, this tag is synonymous with the main tag",+ "type": "string"+ },+ "slug_name": {+ "description": "slug name",+ "type": "string"+ },+ "tag_id": {+ "description": "tag id",+ "type": "string"+ }+ }+ },+ "schema.UnreviewedRevisionInfoInfo": {+ "type": "object",+ "properties": {+ "content": {+ "type": "string"+ },+ "html": {+ "type": "string"+ },+ "object_id": {+ "type": "string"+ },+ "tags": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/schema.TagResp"+ }+ },+ "title": {+ "type": "string"+ }+ }+ },"schema.UpdateCommentReq": {"type": "object","required": [diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex abd78c89..d32dd3d7 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -93,6 +93,8 @@ definitions:properties:answer_id:type: string+ display_name:+ type: stringobject_type:type: stringquestion_id:@@ -697,19 +699,25 @@ definitions:type: objectschema.GetTagSynonymsResp:properties:- display_name:- description: display name- type: string- main_tag_slug_name:- description: if main tag slug name is not empty, this tag is synonymous with- the main tag- type: string- slug_name:- description: slug name- type: string- tag_id:- description: tag id+ member_actions:+ description: MemberActions+ items:+ $ref: '#/definitions/schema.PermissionMemberAction'+ type: array+ synonyms:+ description: synonyms+ items:+ $ref: '#/definitions/schema.TagSynonym'+ type: array+ type: object+ schema.GetUnreviewedRevisionResp:+ properties:+ info:+ $ref: '#/definitions/schema.UnreviewedRevisionInfoInfo'+ type:type: string+ unreviewed_info:+ $ref: '#/definitions/schema.GetRevisionResp'type: objectschema.GetUserPageResp:properties:@@ -1189,9 +1197,7 @@ definitions:type: stringrequired:- contact_email- - description- name- - short_description- site_urltype: objectschema.SiteGeneralResp:@@ -1213,9 +1219,7 @@ definitions:type: stringrequired:- contact_email- - description- name- - short_description- site_urltype: objectschema.SiteInterfaceReq:@@ -1330,6 +1334,37 @@ definitions:slug_name:type: stringtype: object+ schema.TagSynonym:+ properties:+ display_name:+ description: display name+ type: string+ main_tag_slug_name:+ description: if main tag slug name is not empty, this tag is synonymous with+ the main tag+ type: string+ slug_name:+ description: slug name+ type: string+ tag_id:+ description: tag id+ type: string+ type: object+ schema.UnreviewedRevisionInfoInfo:+ properties:+ content:+ type: string+ html:+ type: string+ object_id:+ type: string+ tags:+ items:+ $ref: '#/definitions/schema.TagResp'+ type: array+ title:+ type: string+ type: objectschema.UpdateCommentReq:properties:comment_id:@@ -3510,7 +3545,7 @@ paths:get:consumes:- application/json- description: check can update question+ description: check can update revisionparameters:- default: stringdescription: id@@ -3527,7 +3562,7 @@ paths:$ref: '#/definitions/handler.RespBody'security:- ApiKeyAuth: []- summary: check can update question+ summary: check can update revisiontags:- Revision/answer/api/v1/revisions/unreviewed:@@ -3549,9 +3584,14 @@ paths:- $ref: '#/definitions/handler.RespBody'- properties:data:- items:- $ref: '#/definitions/schema.GetRevisionResp'- type: array+ allOf:+ - $ref: '#/definitions/pager.PageModel'+ - properties:+ list:+ items:+ $ref: '#/definitions/schema.GetUnreviewedRevisionResp'+ type: array+ type: objecttype: objectsecurity:- ApiKeyAuth: []@@ -3753,9 +3793,7 @@ paths:- $ref: '#/definitions/handler.RespBody'- properties:data:- items:- $ref: '#/definitions/schema.GetTagSynonymsResp'- type: array+ $ref: '#/definitions/schema.GetTagSynonymsResp'type: objectsummary: get tag synonymstags:diff --git a/internal/entity/answer_entity.go b/internal/entity/answer_entity.goindex 5dc1593a..8e4d89e6 100644--- a/internal/entity/answer_entity.go+++ b/internal/entity/answer_entity.go@@ -18,18 +18,19 @@ var CmsAnswerSearchStatus = map[string]int{// Answer answertype Answer struct {- ID string `xorm:"not null pk autoincr BIGINT(20) id"`- CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`- UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"`- QuestionID string `xorm:"not null default 0 BIGINT(20) question_id"`- UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"`- 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"`- Adopted int `xorm:"not null default 1 INT(11) adopted"`- CommentCount int `xorm:"not null default 0 INT(11) comment_count"`- VoteCount int `xorm:"not null default 0 INT(11) vote_count"`- RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`+ ID string `xorm:"not null pk autoincr BIGINT(20) id"`+ CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"`+ UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"`+ QuestionID string `xorm:"not null default 0 BIGINT(20) question_id"`+ 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"`+ 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"`+ Adopted int `xorm:"not null default 1 INT(11) adopted"`+ CommentCount int `xorm:"not null default 0 INT(11) comment_count"`+ VoteCount int `xorm:"not null default 0 INT(11) vote_count"`+ RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`}type AnswerSearch struct {diff --git a/internal/entity/question_entity.go b/internal/entity/question_entity.goindex 93d94cd6..804b345d 100644--- a/internal/entity/question_entity.go+++ b/internal/entity/question_entity.go@@ -33,6 +33,7 @@ type Question struct {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"`diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.goindex ef886b4d..4527357b 100644--- a/internal/schema/answer_schema.go+++ b/internal/schema/answer_schema.go@@ -57,6 +57,7 @@ type AnswerInfo struct {UpdateTime int64 `json:"update_time" xorm:"updated"` // update_timeAdopted int `json:"adopted"` // 1 Failed 2 AdoptedUserID string `json:"-" `+ UpdateUserID string `json:"-" `UserInfo *UserBasicInfo `json:"user_info,omitempty"`UpdateUserInfo *UserBasicInfo `json:"update_user_info,omitempty"`Collected bool `json:"collected"`@@ -76,6 +77,7 @@ type AdminAnswerInfo struct {UpdateTime int64 `json:"update_time"`Adopted int `json:"adopted"`UserID string `json:"-" `+ UpdateUserID string `json:"-" `UserInfo *UserBasicInfo `json:"user_info"`VoteCount int `json:"vote_count"`QuestionInfo struct {diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex 1c483a33..55ca661d 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -106,6 +106,8 @@ type QuestionInfo struct {Status int `json:"status"`Operation *Operation `json:"operation,omitempty"`UserID string `json:"-" `+ LastEditUserID string `json:"-" `+ LastAnsweredUserID string `json:"-" `UserInfo *UserBasicInfo `json:"user_info"`UpdateUserInfo *UserBasicInfo `json:"update_user_info,omitempty"`LastAnsweredUserInfo *UserBasicInfo `json:"last_answered_user_info,omitempty"`diff --git a/internal/service/answer_common/answer.go b/internal/service/answer_common/answer.goindex 56cfbb99..cce4e9eb 100644--- a/internal/service/answer_common/answer.go+++ b/internal/service/answer_common/answer.go@@ -72,6 +72,7 @@ func (as *AnswerCommon) ShowFormat(ctx context.Context, data *entity.Answer) *scinfo.UpdateTime = 0}info.UserID = data.UserID+ info.UpdateUserID = data.LastEditUserIDreturn &info}@@ -87,6 +88,7 @@ func (as *AnswerCommon) AdminShowFormat(ctx context.Context, data *entity.Answerinfo.UpdateTime = 0}info.UserID = data.UserID+ info.UpdateUserID = data.LastEditUserIDinfo.Description = htmltext.FetchExcerpt(data.ParsedText, "...", 240)return &info}diff --git a/internal/service/answer_service.go b/internal/service/answer_service.goindex d2bc0e00..78d727dc 100644--- a/internal/service/answer_service.go+++ b/internal/service/answer_service.go@@ -225,11 +225,15 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReqinsertData := new(entity.Answer)insertData.ID = req.IDinsertData.QuestionID = req.QuestionID- insertData.UserID = req.UserIDinsertData.OriginalText = req.ContentinsertData.ParsedText = req.HTMLinsertData.UpdatedAt = now+ insertData.LastEditUserID = "0"+ if answerInfo.UserID != req.UserID {+ insertData.LastEditUserID = req.UserID+ }+revisionDTO := &schema.AddRevisionDTO{UserID: req.UserID,ObjectID: req.ID,@@ -457,6 +461,7 @@ func (as *AnswerService) SearchFormatInfo(ctx context.Context, answers []*entitylist = append(list, item)objectIDs = append(objectIDs, info.ID)userIDs = append(userIDs, info.UserID)+ userIDs = append(userIDs, info.LastEditUserID)if req.UserID != "" {item.VoteStatus = as.voteRepo.GetVoteStatus(ctx, item.ID, req.UserID)}@@ -469,7 +474,10 @@ func (as *AnswerService) SearchFormatInfo(ctx context.Context, answers []*entity_, ok := userInfoMap[item.UserID]if ok {item.UserInfo = userInfoMap[item.UserID]- item.UpdateUserInfo = userInfoMap[item.UserID]+ }+ _, ok = userInfoMap[item.UpdateUserID]+ if ok {+ item.UpdateUserInfo = userInfoMap[item.UpdateUserID]}}diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.goindex 72cfba92..645d1148 100644--- a/internal/service/question_common/question.go+++ b/internal/service/question_common/question.go@@ -234,6 +234,9 @@ func (qs *QuestionCommon) ListFormat(ctx context.Context, questionList []*entitylist = append(list, item)objectIds = append(objectIds, item.ID)userIds = append(userIds, questionInfo.UserID)+ userIds = append(userIds, questionInfo.LastEditUserID)+ userIds = append(userIds, item.LastAnsweredUserID)+}tagsMap, err := qs.tagCommon.BatchGetObjectTag(ctx, objectIds)if err != nil {@@ -254,7 +257,14 @@ func (qs *QuestionCommon) ListFormat(ctx context.Context, questionList []*entityif ok {item.UserInfo = userInfoMap[item.UserID]item.UpdateUserInfo = userInfoMap[item.UserID]- item.LastAnsweredUserInfo = userInfoMap[item.UserID]+ }+ _, ok = userInfoMap[item.LastEditUserID]+ if ok {+ item.UpdateUserInfo = userInfoMap[item.UserID]+ }+ _, ok = userInfoMap[item.LastAnsweredUserID]+ if ok {+ item.LastAnsweredUserInfo = userInfoMap[item.LastAnsweredUserID]}}@@ -389,6 +399,18 @@ func (qs *QuestionCommon) ShowFormat(ctx context.Context, data *entity.Question)}info.Status = data.Statusinfo.UserID = data.UserID+ info.LastEditUserID = data.LastEditUserID+ if data.LastAnswerID != "0" {+ answerInfo, exist, err := qs.answerRepo.GetAnswer(ctx, data.LastAnswerID)+ if err == nil && exist {+ if answerInfo.LastEditUserID != "0" {+ info.LastAnsweredUserID = answerInfo.LastEditUserID+ } else {+ info.LastAnsweredUserID = answerInfo.UserID+ }+ }++ }info.Tags = make([]*schema.TagResp, 0)return &info}diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex 536f8c41..37178a5a 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -284,7 +284,6 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Questnow := time.Now()question := &entity.Question{}- question.UserID = req.UserIDquestion.Title = req.Titlequestion.OriginalText = req.Contentquestion.ParsedText = req.HTML@@ -298,6 +297,10 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Questif !has {return}+ question.LastEditUserID = "0"+ if dbinfo.UserID != req.UserID {+ question.LastEditUserID = req.UserID+ }oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)if tagerr != nil {@@ -377,7 +380,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest//Direct modificationrevisionDTO.Status = entity.RevisionReviewPassStatus//update question to db- saveerr := qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time"})+ saveerr := qs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time", "last_edit_user_id"})if saveerr != nil {return questionInfo, saveerr}diff --git a/internal/service/revision_service.go b/internal/service/revision_service.goindex 1d13599e..57688014 100644--- a/internal/service/revision_service.go+++ b/internal/service/revision_service.go@@ -128,7 +128,8 @@ func (rs *RevisionService) revisionAuditQuestion(ctx context.Context, revisionitquestion.ParsedText = questioninfo.HTMLquestion.UpdatedAt = nowquestion.PostUpdateTime = now- saveerr := rs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time"})+ question.LastEditUserID = revisionitem.UserID+ saveerr := rs.questionRepo.UpdateQuestion(ctx, question, []string{"title", "original_text", "parsed_text", "updated_at", "post_update_time", "last_edit_user_id"})if saveerr != nil {return saveerr}@@ -165,7 +166,8 @@ func (rs *RevisionService) revisionAuditAnswer(ctx context.Context, revisioniteminsertData.OriginalText = answerinfo.ContentinsertData.ParsedText = answerinfo.HTMLinsertData.UpdatedAt = now- saveerr := rs.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"})+ insertData.LastEditUserID = revisionitem.UserID+ saveerr := rs.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time", "last_edit_user_id"})if saveerr != nil {return saveerr}