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
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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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 {