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
|
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
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue