Merge branch 'ai_0.3_fix_del' into 'main'

Ai 0.3 fix del

See merge request opensource/answer!182
This commit is contained in:
linkinstar 2022-11-11 06:14:29 +00:00
commit fed37f873d
4 changed files with 23 additions and 8 deletions

View File

@ -38,9 +38,7 @@ stages:
stage: push stage: push
extends: .docker-build-push extends: .docker-build-push
only: only:
- dev - test
- master
- main
variables: variables:
DockerNamespace: sf_app DockerNamespace: sf_app
DockerImage: answer DockerImage: answer
@ -52,7 +50,7 @@ stages:
stage: deploy-dev stage: deploy-dev
extends: .deploy-helm extends: .deploy-helm
only: only:
- main - test
variables: variables:
LoadBalancerIP: 10.0.10.98 LoadBalancerIP: 10.0.10.98
KubernetesCluster: dev KubernetesCluster: dev

View File

@ -47,7 +47,7 @@ func (ac *AnswerController) RemoveAnswer(ctx *gin.Context) {
return return
} }
err := ac.answerService.RemoveAnswer(ctx, req.ID) err := ac.answerService.RemoveAnswer(ctx, req)
handler.HandleResponse(ctx, err, nil) handler.HandleResponse(ctx, err, nil)
} }

View File

@ -65,14 +65,20 @@ func NewAnswerService(
} }
// RemoveAnswer delete answer // RemoveAnswer delete answer
func (as *AnswerService) RemoveAnswer(ctx context.Context, id string) (err error) { func (as *AnswerService) RemoveAnswer(ctx context.Context, req *schema.RemoveAnswerReq) (err error) {
answerInfo, exist, err := as.answerRepo.GetByID(ctx, id) answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID)
if err != nil { if err != nil {
return err return err
} }
if !exist { if !exist {
return nil 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 // user add question count
err = as.questionCommon.UpdateAnswerCount(ctx, answerInfo.QuestionID, -1) 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()) log.Error("user IncreaseAnswerCount error", err.Error())
} }
err = as.answerRepo.RemoveAnswer(ctx, id) err = as.answerRepo.RemoveAnswer(ctx, req.ID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -163,6 +163,17 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
if !has { if !has {
return nil 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 questionInfo.Status = entity.QuestionStatusDeleted
err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo) err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo)
if err != nil { if err != nil {