mirror of https://gitee.com/answerdev/answer.git
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:
commit
fed37f873d
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue