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.
feat(review): set default review status
LinkinStars84ec57d2d63f
diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.goindex 4795e0b3..0142c58c 100644--- a/internal/controller/answer_controller.go+++ b/internal/controller/answer_controller.go@@ -260,10 +260,10 @@ func (ac *AnswerController) Add(ctx *gin.Context) {}}- ua := ctx.GetHeader("User-Agent")- ip := ctx.ClientIP()+ req.UserAgent = ctx.GetHeader("User-Agent")+ req.IP = ctx.ClientIP()- answerID, err := ac.answerService.Insert(ctx, req, ip, ua)+ answerID, err := ac.answerService.Insert(ctx, req)if err != nil {handler.HandleResponse(ctx, err, nil)returndiff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.goindex 7e67766b..1b0dee92 100644--- a/internal/controller/question_controller.go+++ b/internal/controller/question_controller.go@@ -434,10 +434,10 @@ func (qc *QuestionController) AddQuestion(ctx *gin.Context) {return}- ua := ctx.GetHeader("User-Agent")- ip := ctx.ClientIP()+ req.UserAgent = ctx.GetHeader("User-Agent")+ req.IP = ctx.ClientIP()- resp, err := qc.questionService.AddQuestion(ctx, req, ip, ua)+ resp, err := qc.questionService.AddQuestion(ctx, req)if err != nil {errlist, ok := resp.([]*validator.FormErrorField)if ok {@@ -529,9 +529,9 @@ func (qc *QuestionController) AddQuestionByAnswer(ctx *gin.Context) {return}- ua := ctx.GetHeader("User-Agent")- ip := ctx.ClientIP()- resp, err := qc.questionService.AddQuestion(ctx, questionReq, ip, ua)+ req.UserAgent = ctx.GetHeader("User-Agent")+ req.IP = ctx.ClientIP()+ resp, err := qc.questionService.AddQuestion(ctx, questionReq)if err != nil {errlist, ok := resp.([]*validator.FormErrorField)if ok {@@ -555,7 +555,7 @@ func (qc *QuestionController) AddQuestionByAnswer(ctx *gin.Context) {answerReq.UserID = middleware.GetLoginUserIDFromContext(ctx)answerReq.Content = req.AnswerContentanswerReq.HTML = req.AnswerHTML- answerID, err := qc.answerService.Insert(ctx, answerReq, ip, ua)+ answerID, err := qc.answerService.Insert(ctx, answerReq)if err != nil {handler.HandleResponse(ctx, err, nil)returndiff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.goindex d0c208e6..01bc64a2 100644--- a/internal/schema/answer_schema.go+++ b/internal/schema/answer_schema.go@@ -54,6 +54,8 @@ type AnswerAddReq struct {CanRecover bool `json:"-"`CaptchaID string `json:"captcha_id"`CaptchaCode string `json:"captcha_code"`+ IP string `json:"-"`+ UserAgent string `json:"-"`}func (req *AnswerAddReq) Check() (errFields []*validator.FormErrorField, err error) {diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex 48fd97c5..f915d5ea 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -86,6 +86,8 @@ type QuestionAdd struct {QuestionPermissionCaptchaID string `json:"captcha_id"` // captcha_idCaptchaCode string `json:"captcha_code"`+ IP string `json:"-"`+ UserAgent string `json:"-"`}func (req *QuestionAdd) Check() (errFields []*validator.FormErrorField, err error) {@@ -115,6 +117,8 @@ type QuestionAddByAnswer struct {QuestionPermissionCaptchaID string `json:"captcha_id"` // captcha_idCaptchaCode string `json:"captcha_code"`+ IP string `json:"-"`+ UserAgent string `json:"-"`}func (req *QuestionAddByAnswer) Check() (errFields []*validator.FormErrorField, err error) {diff --git a/internal/service/content/answer_service.go b/internal/service/content/answer_service.goindex eb4d61d3..667ea8c0 100644--- a/internal/service/content/answer_service.go+++ b/internal/service/content/answer_service.go@@ -216,7 +216,7 @@ func (as *AnswerService) RecoverAnswer(ctx context.Context, req *schema.RecoverAreturn nil}-func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq, ip, ua string) (string, error) {+func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (string, error) {questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, req.QuestionID)if err != nil {return "", err@@ -241,7 +241,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq, iif err = as.answerRepo.AddAnswer(ctx, insertData); err != nil {return "", err}- insertData.Status = as.reviewService.AddAnswerReview(ctx, insertData, ip, ua)+ insertData.Status = as.reviewService.AddAnswerReview(ctx, insertData, req.IP, req.UserAgent)if err := as.answerRepo.UpdateAnswerStatus(ctx, insertData.ID, insertData.Status); err != nil {return "", err}diff --git a/internal/service/content/question_service.go b/internal/service/content/question_service.goindex 81f674d8..171f67bd 100644--- a/internal/service/content/question_service.go+++ b/internal/service/content/question_service.go@@ -258,7 +258,7 @@ func (qs *QuestionService) HasNewTag(ctx context.Context, tags []*schema.TagItem}// AddQuestion add question-func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.QuestionAdd, ip, ua string) (questionInfo any, err error) {+func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.QuestionAdd) (questionInfo any, err error) {if len(req.Tags) == 0 {errorlist := make([]*validator.FormErrorField, 0)errorlist = append(errorlist, &validator.FormErrorField{@@ -327,7 +327,7 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Questionif err != nil {return}- question.Status = qs.reviewService.AddQuestionReview(ctx, question, req.Tags, ip, ua)+ question.Status = qs.reviewService.AddQuestionReview(ctx, question, req.Tags, req.IP, req.UserAgent)if err := qs.questionRepo.UpdateQuestionStatus(ctx, question.ID, question.Status); err != nil {return nil, err}diff --git a/internal/service/review/review_service.go b/internal/service/review/review_service.goindex 8db95725..ab4079ee 100644--- a/internal/service/review/review_service.go+++ b/internal/service/review/review_service.go@@ -119,6 +119,8 @@ func (cs *ReviewService) AddQuestionReview(ctx context.Context,questionStatus = entity.QuestionStatusPendingcase plugin.ReviewStatusDeleteDirectly:questionStatus = entity.QuestionStatusDeleted+ default:+ questionStatus = entity.QuestionStatusAvailable}return questionStatus}@@ -141,6 +143,8 @@ func (cs *ReviewService) AddAnswerReview(ctx context.Context,answerStatus = entity.AnswerStatusPendingcase plugin.ReviewStatusDeleteDirectly:answerStatus = entity.AnswerStatusDeleted+ default:+ answerStatus = entity.AnswerStatusAvailable}return answerStatus}