From 3c8aa03fd96801f92940475b0e05b14a0f9445df Mon Sep 17 00:00:00 2001 From: kumfo Date: Wed, 4 Sep 2024 17:05:53 +0800 Subject: [PATCH] fix(badge): fixed badge description translation --- cmd/wire_gen.go | 2 +- i18n/en_US.yaml | 2 +- internal/schema/badge_schema.go | 18 ++---------- internal/service/badge/badge_service.go | 38 ++++++++++++++++++------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go index d18355e3a..537ece84f 100644 --- a/cmd/wire_gen.go +++ b/cmd/wire_gen.go @@ -265,7 +265,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, eventRuleRepo := badge.NewEventRuleRepo(dataData) badgeAwardService := badge2.NewBadgeAwardService(badgeAwardRepo, badgeRepo, userCommon, objService, notificationQueueService) badgeEventService := badge2.NewBadgeEventService(dataData, eventQueueService, badgeRepo, eventRuleRepo, badgeAwardService) - badgeService := badge2.NewBadgeService(badgeRepo, badgeGroupRepo, badgeAwardRepo, badgeEventService) + badgeService := badge2.NewBadgeService(badgeRepo, badgeGroupRepo, badgeAwardRepo, badgeEventService, siteInfoCommonService) badgeController := controller.NewBadgeController(badgeService, badgeAwardService) controller_adminBadgeController := controller_admin.NewBadgeController(badgeService) answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, userAdminController, reasonController, themeController, siteInfoController, controllerSiteInfoController, notificationController, dashboardController, uploadController, activityController, roleController, pluginController, permissionController, userPluginController, reviewController, metaController, badgeController, controller_adminBadgeController) diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 70318a386..020352101 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -539,7 +539,7 @@ backend: name: other: Autobiographer desc: - other: Filled out profile information. + other: Filled out profile information. certified: name: other: Certified diff --git a/internal/schema/badge_schema.go b/internal/schema/badge_schema.go index a33fb480d..8c934ee2d 100644 --- a/internal/schema/badge_schema.go +++ b/internal/schema/badge_schema.go @@ -172,20 +172,6 @@ type GetUserBadgeAwardListResp struct { Level entity.BadgeLevel `json:"level" ` } -// GetBadgeByIDResp get badge by id response -type GetBadgeByIDResp struct { - // badge id - ID string `json:"id" ` - // badge name - Name string `json:"name" ` - // badge description - Description string `json:"description" ` - // badge icon - Icon string `json:"icon" ` - // badge award count - AwardCount int `json:"award_count" ` - // badge is single or multiple - IsSingle bool `json:"is_single" ` - // badge level - Level entity.BadgeLevel `json:"level" ` +type BadgeTplData struct { + ProfileURL string } diff --git a/internal/service/badge/badge_service.go b/internal/service/badge/badge_service.go index faf9b628f..029130adc 100644 --- a/internal/service/badge/badge_service.go +++ b/internal/service/badge/badge_service.go @@ -26,6 +26,7 @@ import ( "github.com/apache/incubator-answer/internal/base/translator" "github.com/apache/incubator-answer/internal/entity" "github.com/apache/incubator-answer/internal/schema" + "github.com/apache/incubator-answer/internal/service/siteinfo_common" "github.com/apache/incubator-answer/pkg/converter" "github.com/apache/incubator-answer/pkg/uid" "github.com/gin-gonic/gin" @@ -47,10 +48,11 @@ type BadgeRepo interface { } type BadgeService struct { - badgeRepo BadgeRepo - badgeGroupRepo BadgeGroupRepo - badgeAwardRepo BadgeAwardRepo - badgeEventService *BadgeEventService + badgeRepo BadgeRepo + badgeGroupRepo BadgeGroupRepo + badgeAwardRepo BadgeAwardRepo + badgeEventService *BadgeEventService + siteInfoCommonService siteinfo_common.SiteInfoCommonService } func NewBadgeService( @@ -58,12 +60,14 @@ func NewBadgeService( badgeGroupRepo BadgeGroupRepo, badgeAwardRepo BadgeAwardRepo, badgeEventService *BadgeEventService, + siteInfoCommonService siteinfo_common.SiteInfoCommonService, ) *BadgeService { return &BadgeService{ - badgeRepo: badgeRepo, - badgeGroupRepo: badgeGroupRepo, - badgeAwardRepo: badgeAwardRepo, - badgeEventService: badgeEventService, + badgeRepo: badgeRepo, + badgeGroupRepo: badgeGroupRepo, + badgeAwardRepo: badgeAwardRepo, + badgeEventService: badgeEventService, + siteInfoCommonService: siteInfoCommonService, } } @@ -200,11 +204,18 @@ func (b *BadgeService) ListPaged(ctx context.Context, req *schema.GetBadgeListPa resp = make([]*schema.GetBadgeListPagedResp, len(badges)) + general, siteErr := b.siteInfoCommonService.GetSiteGeneral(ctx) + var baseURL = "" + if siteErr != nil { + baseURL = "" + } + baseURL = general.SiteUrl + for i, badge := range badges { resp[i] = &schema.GetBadgeListPagedResp{ ID: uid.EnShortID(badge.ID), Name: translator.Tr(handler.GetLangByCtx(ctx), badge.Name), - Description: translator.Tr(handler.GetLangByCtx(ctx), badge.Description), + Description: translator.TrWithData(handler.GetLangByCtx(ctx), badge.Description, &schema.BadgeTplData{ProfileURL: baseURL + "/users/settings/profile"}), Icon: badge.Icon, AwardCount: badge.AwardCount, Level: badge.Level, @@ -253,10 +264,17 @@ func (b *BadgeService) GetBadgeInfo(ctx *gin.Context, id string, userID string) earnedTotal = b.badgeAwardRepo.CountByUserIdAndBadgeId(ctx, userID, badge.ID) } + general, siteErr := b.siteInfoCommonService.GetSiteGeneral(ctx) + var baseURL = "" + if siteErr != nil { + baseURL = "" + } + baseURL = general.SiteUrl + info = &schema.GetBadgeInfoResp{ ID: uid.EnShortID(badge.ID), Name: translator.Tr(handler.GetLangByCtx(ctx), badge.Name), - Description: translator.Tr(handler.GetLangByCtx(ctx), badge.Description), + Description: translator.TrWithData(handler.GetLangByCtx(ctx), badge.Description, &schema.BadgeTplData{ProfileURL: baseURL + "/users/settings/profile"}), Icon: badge.Icon, AwardCount: badge.AwardCount, EarnedCount: earnedTotal,