mirror of https://gitee.com/answerdev/answer.git
update vote
This commit is contained in:
parent
d3d049a9b3
commit
45f2f06698
|
@ -100,6 +100,8 @@ backend:
|
|||
rank:
|
||||
fail_to_meet_the_condition:
|
||||
other: Rank fail to meet the condition.
|
||||
vote_fail_to_meet_the_condition:
|
||||
other: Thanks for the feedback. You need at least {{ rank }} reputation to cast a vote.
|
||||
report:
|
||||
handle_failed:
|
||||
other: Report handle failed.
|
||||
|
|
|
@ -99,6 +99,8 @@ backend:
|
|||
rank:
|
||||
fail_to_meet_the_condition:
|
||||
other: 级别不符合条件
|
||||
vote_fail_to_meet_the_condition:
|
||||
other: 感谢您的投票。您至少需要{{ rank }}声望才能投票。
|
||||
report:
|
||||
handle_failed:
|
||||
other: 报告处理失败
|
||||
|
|
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
|
@ -73,3 +74,10 @@ func BindAndCheckReturnErr(ctx *gin.Context, data interface{}) (errFields []*val
|
|||
errFields, _ = validator.GetValidatorByLang(lang).Check(data)
|
||||
return errFields
|
||||
}
|
||||
|
||||
func MsgWithParameter(msg string, list map[string]string) string {
|
||||
for k, v := range list {
|
||||
msg = strings.Replace(msg, "{{ "+k+" }}", v, -1)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ const (
|
|||
TagIsUsedCannotDelete = "error.tag.is_used_cannot_delete"
|
||||
TagAlreadyExist = "error.tag.already_exist"
|
||||
RankFailToMeetTheCondition = "error.rank.fail_to_meet_the_condition"
|
||||
VoteRankFailToMeetTheCondition = "error.rank.vote_fail_to_meet_the_condition"
|
||||
ThemeNotFound = "error.theme.not_found"
|
||||
LangNotFound = "error.lang.not_found"
|
||||
ReportHandleFailed = "error.report.handle_failed"
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/base/middleware"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service"
|
||||
"github.com/answerdev/answer/internal/service/rank"
|
||||
|
@ -41,13 +44,16 @@ func (vc *VoteController) VoteUp(ctx *gin.Context) {
|
|||
}
|
||||
req.ObjectID = uid.DeShortID(req.ObjectID)
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
can, _, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, true)
|
||||
can, rank, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, true)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
lang := handler.GetLang(ctx)
|
||||
msg := translator.Tr(lang, reason.VoteRankFailToMeetTheCondition)
|
||||
msg = handler.MsgWithParameter(msg, map[string]string{"rank": fmt.Sprintf("%d", rank)})
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.VoteRankFailToMeetTheCondition).WithMsg(msg), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,13 +84,16 @@ func (vc *VoteController) VoteDown(ctx *gin.Context) {
|
|||
}
|
||||
req.ObjectID = uid.DeShortID(req.ObjectID)
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
can, _, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, false)
|
||||
can, rank, err := vc.rankService.CheckVotePermission(ctx, req.UserID, req.ObjectID, false)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, err, nil)
|
||||
return
|
||||
}
|
||||
if !can {
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
||||
lang := handler.GetLang(ctx)
|
||||
msg := translator.Tr(lang, reason.VoteRankFailToMeetTheCondition)
|
||||
msg = handler.MsgWithParameter(msg, map[string]string{"rank": fmt.Sprintf("%d", rank)})
|
||||
handler.HandleResponse(ctx, errors.Forbidden(reason.VoteRankFailToMeetTheCondition).WithMsg(msg), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue