You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/03/28 09:01:07 UTC

(incubator-answer) branch feat/1.3.1/review updated: feat(review): set default review status

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.3.1/review
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/1.3.1/review by this push:
     new 84ec57d2 feat(review): set default review status
84ec57d2 is described below

commit 84ec57d2d63fc0ba4dab74b55dae68e029c1dfe7
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Mar 28 17:00:40 2024 +0800

    feat(review): set default review status
---
 internal/controller/answer_controller.go     |  6 +++---
 internal/controller/question_controller.go   | 14 +++++++-------
 internal/schema/answer_schema.go             |  2 ++
 internal/schema/question_schema.go           |  4 ++++
 internal/service/content/answer_service.go   |  4 ++--
 internal/service/content/question_service.go |  4 ++--
 internal/service/review/review_service.go    |  4 ++++
 7 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go
index 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)
 		return
diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go
index 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.AnswerContent
 		answerReq.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)
 			return
diff --git a/internal/schema/answer_schema.go b/internal/schema/answer_schema.go
index 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.go
index 48fd97c5..f915d5ea 100644
--- a/internal/schema/question_schema.go
+++ b/internal/schema/question_schema.go
@@ -86,6 +86,8 @@ type QuestionAdd struct {
 	QuestionPermission
 	CaptchaID   string `json:"captcha_id"` // captcha_id
 	CaptchaCode 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 {
 	QuestionPermission
 	CaptchaID   string `json:"captcha_id"` // captcha_id
 	CaptchaCode 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.go
index 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.RecoverA
 	return 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, i
 	if 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.go
index 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.Question
 	if 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.go
index 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.QuestionStatusPending
 	case plugin.ReviewStatusDeleteDirectly:
 		questionStatus = entity.QuestionStatusDeleted
+	default:
+		questionStatus = entity.QuestionStatusAvailable
 	}
 	return questionStatus
 }
@@ -141,6 +143,8 @@ func (cs *ReviewService) AddAnswerReview(ctx context.Context,
 		answerStatus = entity.AnswerStatusPending
 	case plugin.ReviewStatusDeleteDirectly:
 		answerStatus = entity.AnswerStatusDeleted
+	default:
+		answerStatus = entity.AnswerStatusAvailable
 	}
 	return answerStatus
 }