feat(question): If user edit question, update last edit user id

This commit is contained in:
LinkinStar 2022-12-30 18:07:23 +08:00
parent 96e292462e
commit 6b9fa98e48
3 changed files with 40 additions and 19 deletions

View File

@ -4,10 +4,35 @@ import (
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/handler"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/i18n"
)
var (
langMapping = map[i18n.Language]bool{
i18n.LanguageChinese: true,
i18n.LanguageChineseTraditional: true,
i18n.LanguageEnglish: true,
i18n.LanguageGerman: true,
i18n.LanguageSpanish: true,
i18n.LanguageFrench: true,
i18n.LanguageItalian: true,
i18n.LanguageJapanese: true,
i18n.LanguageKorean: true,
i18n.LanguagePortuguese: true,
i18n.LanguageRussian: true,
i18n.LanguageVietnamese: true,
}
)
// ExtractAndSetAcceptLanguage extract accept language from header and set to context
func ExtractAndSetAcceptLanguage(ctx *gin.Context) {
// The language of our front-end configuration, like en_US
lang := handler.GetLang(ctx)
ctx.Set(constant.AcceptLanguageFlag, lang)
if langMapping[lang] {
ctx.Set(constant.AcceptLanguageFlag, lang)
return
}
// default language
ctx.Set(constant.AcceptLanguageFlag, i18n.LanguageEnglish)
}

View File

@ -297,20 +297,20 @@ func (qs *QuestionCommon) FormatQuestionsPage(
t.OperationType = askedOp
t.OperatedAt = questionInfo.CreatedAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.UserID}
}
} else {
// if no one
if haveEdited {
t.OperationType = modifiedOp
t.OperatedAt = questionInfo.UpdatedAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
}
// if no one
if haveEdited {
t.OperationType = modifiedOp
t.OperatedAt = questionInfo.UpdatedAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: questionInfo.LastEditUserID}
}
if haveAnswered {
if t.LastAnsweredAt.Unix() > t.OperatedAt {
t.OperationType = answeredOp
t.OperatedAt = t.LastAnsweredAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: t.LastAnsweredUserID}
if haveAnswered {
if t.LastAnsweredAt.Unix() > t.OperatedAt {
t.OperationType = answeredOp
t.OperatedAt = t.LastAnsweredAt.Unix()
t.Operator = &schema.QuestionPageRespOperator{ID: t.LastAnsweredUserID}
}
}
}
formattedQuestions = append(formattedQuestions, t)

View File

@ -476,11 +476,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
question.UpdatedAt = now
question.PostUpdateTime = now
question.UserID = dbinfo.UserID
question.LastEditUserID = "0"
if dbinfo.UserID != req.UserID {
question.LastEditUserID = req.UserID
}
question.LastEditUserID = req.UserID
oldTags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, question.ID)
if tagerr != nil {