From 79cc30355a9fca8945c3127f8a06e81a59a50ac7 Mon Sep 17 00:00:00 2001 From: LinkinStar Date: Wed, 2 Nov 2022 14:43:45 +0800 Subject: [PATCH 1/3] update: gitlab ci only deploy on test --- .gitlab-ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9175a7e..c80bde9f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,9 +38,7 @@ stages: stage: push extends: .docker-build-push only: - - dev - - master - - main + - test variables: DockerNamespace: sf_app DockerImage: answer @@ -52,7 +50,7 @@ stages: stage: deploy-dev extends: .deploy-helm only: - - main + - test variables: LoadBalancerIP: 10.0.10.98 KubernetesCluster: dev From 8f38d2a0af43b3f23d5aeba1760f48f487eb7359 Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 4 Nov 2022 16:59:16 +0800 Subject: [PATCH 2/3] update delete answer or question --- internal/service/answer_service.go | 12 +++++++++--- internal/service/question_service.go | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go index 5d0ba33d..2839e94d 100644 --- a/internal/service/answer_service.go +++ b/internal/service/answer_service.go @@ -65,14 +65,20 @@ func NewAnswerService( } // RemoveAnswer delete answer -func (as *AnswerService) RemoveAnswer(ctx context.Context, id string) (err error) { - answerInfo, exist, err := as.answerRepo.GetByID(ctx, id) +func (as *AnswerService) RemoveAnswer(ctx context.Context, req *schema.RemoveAnswerReq) (err error) { + answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID) if err != nil { return err } if !exist { return nil } + if answerInfo.UserID != req.UserID { + return errors.BadRequest(reason.UnauthorizedError) + } + if answerInfo.Adopted == schema.AnswerAdoptedEnable { + return errors.BadRequest(reason.UnauthorizedError) + } // user add question count err = as.questionCommon.UpdateAnswerCount(ctx, answerInfo.QuestionID, -1) @@ -85,7 +91,7 @@ func (as *AnswerService) RemoveAnswer(ctx context.Context, id string) (err error log.Error("user IncreaseAnswerCount error", err.Error()) } - err = as.answerRepo.RemoveAnswer(ctx, id) + err = as.answerRepo.RemoveAnswer(ctx, req.ID) if err != nil { return err } diff --git a/internal/service/question_service.go b/internal/service/question_service.go index 97bceb24..72f885b1 100644 --- a/internal/service/question_service.go +++ b/internal/service/question_service.go @@ -163,6 +163,17 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov if !has { return nil } + if questionInfo.UserID != req.UserID { + return errors.BadRequest(reason.UnauthorizedError) + } + + if questionInfo.AcceptedAnswerID != "" { + return errors.BadRequest(reason.UnauthorizedError) + } + if questionInfo.AnswerCount > 0 { + return errors.BadRequest(reason.UnauthorizedError) + } + questionInfo.Status = entity.QuestionStatusDeleted err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) if err != nil { From e0c53bea1139474322809ea4b2065b4933d53291 Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 4 Nov 2022 17:10:20 +0800 Subject: [PATCH 3/3] update delete answer and question --- internal/controller/answer_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go index 43ea51a5..38ca3624 100644 --- a/internal/controller/answer_controller.go +++ b/internal/controller/answer_controller.go @@ -47,7 +47,7 @@ func (ac *AnswerController) RemoveAnswer(ctx *gin.Context) { return } - err := ac.answerService.RemoveAnswer(ctx, req.ID) + err := ac.answerService.RemoveAnswer(ctx, req) handler.HandleResponse(ctx, err, nil) }