mirror of https://gitee.com/answerdev/answer.git
fix(notification): add rank activity type translation
This commit is contained in:
parent
d0bc403c88
commit
40690a2a36
4
go.sum
4
go.sum
|
@ -625,16 +625,12 @@ github.com/scottleedavis/go-exif-remove v0.0.0-20230314195146-7e059d593405 h1:2i
|
|||
github.com/scottleedavis/go-exif-remove v0.0.0-20230314195146-7e059d593405/go.mod h1:rIxVzVLKlBwLxO+lC+k/I4HJfRQcemg/f/76Xmmzsec=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
|
||||
github.com/segmentfault/pacman v1.0.3 h1:/K8LJHQMiCaCIvC/e8GQITpYTEG6RH4KTLTZjPTghl4=
|
||||
github.com/segmentfault/pacman v1.0.3/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=
|
||||
github.com/segmentfault/pacman v1.0.4 h1:6UIXuMHUeYMWe5toflV9SXZQizRny1RczjZJLj9kul0=
|
||||
github.com/segmentfault/pacman v1.0.4/go.mod h1:5lNp5REd8QMThmBUvR3Fi9Y3AsOB4GRq7soCB4QLqOs=
|
||||
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20221219081300-f734f4a16aa0 h1:4x0qG7H2M3qH7Yo2BhGrVlji1iTmRAWgINY/JyENeHs=
|
||||
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20221219081300-f734f4a16aa0/go.mod h1:rmf1TCwz67dyM+AmTwSd1BxTo2AOYHj262lP93bOZbs=
|
||||
github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20221018072427-a15dd1434e05 h1:BlqTgc3/MYKG6vMI2MI+6o+7P4Gy5PXlawu185wPXAk=
|
||||
github.com/segmentfault/pacman/contrib/conf/viper v0.0.0-20221018072427-a15dd1434e05/go.mod h1:prPjFam7MyZ5b3S9dcDOt2tMPz6kf7C9c243s9zSwPY=
|
||||
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093245-f9384b820548 h1:R+FH23Qrdp5ECuHXmZy4BvoO/x7m2wZgNeiC46+jqCQ=
|
||||
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093245-f9384b820548/go.mod h1:7QcRmnV7OYq4hNOOCWXT5HXnN/u756JUsqIW0Bw8n9E=
|
||||
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150 h1:OEuW1D7RGDE0CZDr0oGMw9Eiq7fAbD9C4WMrvSixamk=
|
||||
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150/go.mod h1:7QcRmnV7OYq4hNOOCWXT5HXnN/u756JUsqIW0Bw8n9E=
|
||||
github.com/segmentfault/pacman/contrib/log/zap v0.0.0-20221018072427-a15dd1434e05 h1:jcGZU2juv0L3eFEkuZYV14ESLUlWfGMWnP0mjOfrSZc=
|
||||
|
|
|
@ -359,6 +359,8 @@ backend:
|
|||
other: answered
|
||||
modified:
|
||||
other: modified
|
||||
deleted_title:
|
||||
other: Deleted question
|
||||
notification:
|
||||
action:
|
||||
update_question:
|
||||
|
@ -433,6 +435,19 @@ backend:
|
|||
other: "[{{.SiteName}}] Test Email"
|
||||
body:
|
||||
other: "This is a test email."
|
||||
action_activity_type:
|
||||
upvote:
|
||||
other: upvote
|
||||
upvoted:
|
||||
other: upvoted
|
||||
downvote:
|
||||
other: downvote
|
||||
downvoted:
|
||||
other: downvoted
|
||||
accept:
|
||||
other: accept
|
||||
accepted:
|
||||
other: accepted
|
||||
|
||||
# The following fields are used for interface presentation(Front-end)
|
||||
ui:
|
||||
|
|
|
@ -344,6 +344,8 @@ backend:
|
|||
other: 回答于
|
||||
modified:
|
||||
other: 修改于
|
||||
deleted_title:
|
||||
other: 问题已被删除
|
||||
notification:
|
||||
action:
|
||||
update_question:
|
||||
|
@ -418,6 +420,19 @@ backend:
|
|||
other: "[{{.SiteName}}] 测试邮件"
|
||||
body:
|
||||
other: "这是一封测试邮件。"
|
||||
action_activity_type:
|
||||
upvote:
|
||||
other: 点赞
|
||||
upvoted:
|
||||
other: 被赞
|
||||
downvote:
|
||||
other: 点踩
|
||||
downvoted:
|
||||
other: 被踩
|
||||
accept:
|
||||
other: 采纳
|
||||
accepted:
|
||||
other: 被采纳
|
||||
#The following fields are used for interface presentation(Front-end)
|
||||
ui:
|
||||
how_to_format:
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package constant
|
||||
|
||||
const (
|
||||
DeletedQuestionTitleTrKey = "question.deleted_title"
|
||||
)
|
|
@ -27,7 +27,7 @@ func NewRankController(
|
|||
// @Param page query int false "page"
|
||||
// @Param page_size query int false "page size"
|
||||
// @Param username query string false "username"
|
||||
// @Success 200 {object} handler.RespBody{data=pager.PageModel{list=[]schema.GetRankPersonalWithPageResp}}
|
||||
// @Success 200 {object} handler.RespBody{data=pager.PageModel{list=[]schema.GetRankPersonalPageResp}}
|
||||
// @Router /answer/api/v1/personal/rank/page [get]
|
||||
func (cc *RankController) GetRankPersonalWithPage(ctx *gin.Context) {
|
||||
req := &schema.GetRankPersonalWithPageReq{}
|
||||
|
@ -37,6 +37,6 @@ func (cc *RankController) GetRankPersonalWithPage(ctx *gin.Context) {
|
|||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
resp, err := cc.rankService.GetRankPersonalWithPage(ctx, req)
|
||||
resp, err := cc.rankService.GetRankPersonalPage(ctx, req)
|
||||
handler.HandleResponse(ctx, err, resp)
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ type GetRankPersonalWithPageReq struct {
|
|||
UserID string `json:"-"`
|
||||
}
|
||||
|
||||
// GetRankPersonalWithPageResp rank response
|
||||
type GetRankPersonalWithPageResp struct {
|
||||
// GetRankPersonalPageResp rank response
|
||||
type GetRankPersonalPageResp struct {
|
||||
// create time
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
// object id
|
||||
|
|
|
@ -39,27 +39,17 @@ var (
|
|||
AnswerVotedDown,
|
||||
CommentVoteUp,
|
||||
}
|
||||
activityTypeFlagMapping = map[string]string{
|
||||
QuestionVoteUp: "upvote",
|
||||
QuestionVoteDown: "downvote",
|
||||
QuestionVotedUp: "upvoted",
|
||||
QuestionVotedDown: "downvoted",
|
||||
AnswerVoteUp: "upvote",
|
||||
AnswerVoteDown: "downvote",
|
||||
AnswerVotedUp: "upvoted",
|
||||
AnswerVotedDown: "downvoted",
|
||||
AnswerAccepted: "accepted",
|
||||
AnswerAccept: "accept",
|
||||
CommentVoteUp: "upvote",
|
||||
ActivityTypeFlagMapping = map[string]string{
|
||||
QuestionVoteUp: "action_activity_type.upvote",
|
||||
QuestionVoteDown: "action_activity_type.downvote",
|
||||
QuestionVotedUp: "action_activity_type.upvoted",
|
||||
QuestionVotedDown: "action_activity_type.downvoted",
|
||||
AnswerVoteUp: "action_activity_type.upvote",
|
||||
AnswerVoteDown: "action_activity_type.downvote",
|
||||
AnswerVotedUp: "action_activity_type.upvoted",
|
||||
AnswerVotedDown: "action_activity_type.downvoted",
|
||||
AnswerAccepted: "action_activity_type.accepted",
|
||||
AnswerAccept: "action_activity_type.accept",
|
||||
CommentVoteUp: "action_activity_type.upvote",
|
||||
}
|
||||
)
|
||||
|
||||
func Format(activityTypeID int) string {
|
||||
return ""
|
||||
//activityTypeStr := config_common.ID2KeyMapping[activityTypeID]
|
||||
//activityTypeFlag := activityTypeFlagMapping[activityTypeStr]
|
||||
//if len(activityTypeFlag) == 0 {
|
||||
// return "edit" // to edit
|
||||
//}
|
||||
//return activityTypeFlag // todo i18n support
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/base/pager"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service/activity_type"
|
||||
|
@ -234,8 +236,8 @@ func (rs *RankService) checkUserRank(ctx context.Context, userID string, userRan
|
|||
return true, requireRank
|
||||
}
|
||||
|
||||
// GetRankPersonalWithPage get personal comment list page
|
||||
func (rs *RankService) GetRankPersonalWithPage(ctx context.Context, req *schema.GetRankPersonalWithPageReq) (
|
||||
// GetRankPersonalPage get personal comment list page
|
||||
func (rs *RankService) GetRankPersonalPage(ctx context.Context, req *schema.GetRankPersonalWithPageReq) (
|
||||
pageModel *pager.PageModel, err error) {
|
||||
if plugin.RankAgentEnabled() {
|
||||
return pager.NewPageModel(0, []string{}), nil
|
||||
|
@ -258,32 +260,47 @@ func (rs *RankService) GetRankPersonalWithPage(ctx context.Context, req *schema.
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := make([]*schema.GetRankPersonalWithPageResp, 0)
|
||||
|
||||
resp := rs.decorateRankPersonalPageResp(ctx, userRankPage)
|
||||
return pager.NewPageModel(total, resp), nil
|
||||
}
|
||||
|
||||
func (rs *RankService) decorateRankPersonalPageResp(
|
||||
ctx context.Context, userRankPage []*entity.Activity) []*schema.GetRankPersonalPageResp {
|
||||
resp := make([]*schema.GetRankPersonalPageResp, 0)
|
||||
lang := handler.GetLangByCtx(ctx)
|
||||
|
||||
for _, userRankInfo := range userRankPage {
|
||||
if len(userRankInfo.ObjectID) == 0 || userRankInfo.ObjectID == "0" {
|
||||
continue
|
||||
}
|
||||
commentResp := &schema.GetRankPersonalWithPageResp{
|
||||
objInfo, err := rs.objectInfoService.GetInfo(ctx, userRankInfo.ObjectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
commentResp := &schema.GetRankPersonalPageResp{
|
||||
CreatedAt: userRankInfo.CreatedAt.Unix(),
|
||||
ObjectID: userRankInfo.ObjectID,
|
||||
Reputation: userRankInfo.Rank,
|
||||
}
|
||||
objInfo, err := rs.objectInfoService.GetInfo(ctx, userRankInfo.ObjectID)
|
||||
cfg, err := rs.configService.GetConfigByID(ctx, userRankInfo.ActivityType)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
} else {
|
||||
commentResp.RankType = activity_type.Format(userRankInfo.ActivityType)
|
||||
continue
|
||||
}
|
||||
commentResp.RankType = translator.Tr(lang, activity_type.ActivityTypeFlagMapping[cfg.Key])
|
||||
commentResp.ObjectType = objInfo.ObjectType
|
||||
commentResp.Title = objInfo.Title
|
||||
commentResp.UrlTitle = htmltext.UrlTitle(objInfo.Title)
|
||||
commentResp.Content = objInfo.Content
|
||||
if objInfo.QuestionStatus == entity.QuestionStatusDeleted {
|
||||
commentResp.Title = "Deleted question"
|
||||
commentResp.Title = translator.Tr(lang, constant.DeletedQuestionTitleTrKey)
|
||||
}
|
||||
commentResp.QuestionID = objInfo.QuestionID
|
||||
commentResp.AnswerID = objInfo.AnswerID
|
||||
}
|
||||
resp = append(resp, commentResp)
|
||||
}
|
||||
return pager.NewPageModel(total, resp), nil
|
||||
return resp
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ package service
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/constant"
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/base/pager"
|
||||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/service/activity_type"
|
||||
"github.com/answerdev/answer/internal/service/comment_common"
|
||||
|
@ -151,23 +154,22 @@ func (vs *VoteService) GetObjectUserID(ctx context.Context, objectID string) (us
|
|||
|
||||
// ListUserVotes list user's votes
|
||||
func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWithPageReq) (model *pager.PageModel, err error) {
|
||||
var (
|
||||
resp []schema.GetVoteWithPageResp
|
||||
typeKeys = []string{
|
||||
"question.vote_up",
|
||||
"question.vote_down",
|
||||
"answer.vote_up",
|
||||
"answer.vote_down",
|
||||
typeKeys := []string{
|
||||
activity_type.QuestionVoteUp,
|
||||
activity_type.QuestionVoteDown,
|
||||
activity_type.AnswerVoteUp,
|
||||
activity_type.AnswerVoteDown,
|
||||
}
|
||||
activityTypes []int
|
||||
)
|
||||
activityTypes := make([]int, 0)
|
||||
activityTypeMapping := make(map[int]string, 0)
|
||||
|
||||
for _, typeKey := range typeKeys {
|
||||
cfg, err := vs.configService.GetConfigByKey(ctx, typeKey)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
activityTypes = append(activityTypes, cfg.GetIntValue())
|
||||
activityTypes = append(activityTypes, cfg.ID)
|
||||
activityTypeMapping[cfg.ID] = typeKey
|
||||
}
|
||||
|
||||
voteList, total, err := vs.voteRepo.ListUserVotes(ctx, req.UserID, req, activityTypes)
|
||||
|
@ -175,15 +177,17 @@ func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWith
|
|||
return
|
||||
}
|
||||
|
||||
lang := handler.GetLangByCtx(ctx)
|
||||
|
||||
resp := make([]*schema.GetVoteWithPageResp, 0)
|
||||
for _, voteInfo := range voteList {
|
||||
var objInfo *schema.SimpleObjectInfo
|
||||
objInfo, err = vs.objectService.GetInfo(ctx, voteInfo.ObjectID)
|
||||
objInfo, err := vs.objectService.GetInfo(ctx, voteInfo.ObjectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
item := schema.GetVoteWithPageResp{
|
||||
item := &schema.GetVoteWithPageResp{
|
||||
CreatedAt: voteInfo.CreatedAt.Unix(),
|
||||
ObjectID: objInfo.ObjectID,
|
||||
QuestionID: objInfo.QuestionID,
|
||||
|
@ -192,13 +196,13 @@ func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWith
|
|||
Title: objInfo.Title,
|
||||
UrlTitle: htmltext.UrlTitle(objInfo.Title),
|
||||
Content: objInfo.Content,
|
||||
VoteType: activity_type.Format(voteInfo.ActivityType),
|
||||
}
|
||||
item.VoteType = translator.Tr(lang,
|
||||
activity_type.ActivityTypeFlagMapping[activityTypeMapping[voteInfo.ActivityType]])
|
||||
if objInfo.QuestionStatus == entity.QuestionStatusDeleted {
|
||||
item.Title = "Deleted question"
|
||||
item.Title = translator.Tr(lang, constant.DeletedQuestionTitleTrKey)
|
||||
}
|
||||
resp = append(resp, item)
|
||||
}
|
||||
|
||||
return pager.NewPageModel(total, resp), err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue