update question

This commit is contained in:
aichy126 2023-03-16 15:22:47 +08:00
parent 7ce4e40e98
commit a2bc103d4f
2 changed files with 9 additions and 0 deletions

View File

@ -75,6 +75,7 @@ func (qc *QuestionController) CloseQuestion(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.ID = uid.DeShortID(req.ID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, permission.QuestionClose, "")
if err != nil {
@ -105,6 +106,7 @@ func (qc *QuestionController) ReopenQuestion(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.QuestionID = uid.DeShortID(req.QuestionID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, permission.QuestionReopen, "")
if err != nil {
@ -132,6 +134,7 @@ func (qc *QuestionController) ReopenQuestion(ctx *gin.Context) {
// @Router /answer/api/v1/question/info [get]
func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
id := ctx.Query("id")
id = uid.DeShortID(id)
userID := middleware.GetLoginUserIDFromContext(ctx)
req := schema.QuestionPermission{}
canList, err := qc.rankService.CheckOperationPermissions(ctx, userID, []string{
@ -170,6 +173,7 @@ func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
// @Router /answer/api/v1/question/similar/tag [get]
func (qc *QuestionController) SimilarQuestion(ctx *gin.Context) {
questionID := ctx.Query("question_id")
questionID = uid.DeShortID(questionID)
userID := middleware.GetLoginUserIDFromContext(ctx)
list, count, err := qc.questionService.SimilarQuestion(ctx, questionID, userID)
if err != nil {
@ -292,6 +296,7 @@ func (qc *QuestionController) UpdateQuestion(ctx *gin.Context) {
if ctx.IsAborted() {
return
}
req.ID = uid.DeShortID(req.ID)
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
canList, err := qc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
@ -509,6 +514,7 @@ func (qc *QuestionController) AdminSearchAnswerList(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.QuestionID = uid.DeShortID(req.QuestionID)
userID := middleware.GetLoginUserIDFromContext(ctx)
questionList, count, err := qc.questionService.AdminSearchAnswerList(ctx, req, userID)
handler.HandleResponse(ctx, err, gin.H{
@ -532,6 +538,7 @@ func (qc *QuestionController) AdminSetQuestionStatus(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}
req.QuestionID = uid.DeShortID(req.QuestionID)
err := qc.questionService.AdminSetQuestionStatus(ctx, req.QuestionID, req.StatusStr)
handler.HandleResponse(ctx, err, gin.H{})
}

View File

@ -13,6 +13,7 @@ import (
"github.com/answerdev/answer/internal/service/meta"
"github.com/answerdev/answer/pkg/checker"
"github.com/answerdev/answer/pkg/htmltext"
"github.com/answerdev/answer/pkg/uid"
"github.com/segmentfault/pacman/errors"
"github.com/answerdev/answer/internal/entity"
@ -147,6 +148,7 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser
if err != nil {
return showinfo, err
}
dbinfo.ID = uid.DeShortID(dbinfo.ID)
if !has {
return showinfo, errors.NotFound(reason.QuestionNotFound)
}