update answer

This commit is contained in:
aichy126 2023-03-15 17:34:16 +08:00
parent d7511a6697
commit cf2fc12e38
5 changed files with 11 additions and 0 deletions

View File

@ -48,6 +48,8 @@ backend:
other: No permission to delete.
cannot_update:
other: No permission to update.
question_closed_cannot_add:
other: Questions are closed and cannot be added.
comment:
edit_without_permission:
other: Comment are not allowed to edit.

View File

@ -44,6 +44,8 @@ backend:
other: 没有删除权限。
cannot_update:
other: 没有更新权限。
question_closed_cannot_add:
other: 问题已关闭不可以新增回答
comment:
edit_without_permission:
other: 不允许编辑评论。

View File

@ -25,6 +25,7 @@ const (
AnswerNotFound = "error.answer.not_found"
AnswerCannotDeleted = "error.answer.cannot_deleted"
AnswerCannotUpdate = "error.answer.cannot_update"
AnswerCannotAddByClosedQuestion = "error.answer.question_closed_cannot_add"
CommentEditWithoutPermission = "error.comment.edit_without_permission"
DisallowVote = "error.object.disallow_vote"
DisallowFollow = "error.object.disallow_follow"

View File

@ -6,6 +6,7 @@ import (
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/activity"
"github.com/answerdev/answer/internal/service/activity_common"
"github.com/answerdev/answer/pkg/uid"
"github.com/gin-gonic/gin"
)
@ -37,6 +38,7 @@ func (ac *ActivityController) GetObjectTimeline(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.ObjectID = uid.DeShortID(req.ObjectID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
if userInfo := middleware.GetUserInfoFromContext(ctx); userInfo != nil {

View File

@ -138,6 +138,10 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
if !exist {
return "", errors.BadRequest(reason.QuestionNotFound)
}
if questionInfo.Status == entity.QuestionStatusClosed || questionInfo.Status == entity.QuestionStatusDeleted {
err = errors.BadRequest(reason.AnswerCannotAddByClosedQuestion)
return "", err
}
insertData := new(entity.Answer)
insertData.UserID = req.UserID
insertData.OriginalText = req.Content