From ac8d0278ad9fe3d39a733afd72c5fc52ae8e3c8d Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Thu, 2 Jan 2025 15:59:07 +0800 Subject: [PATCH] fix: rename DeleteUserBadge to DeleteUserBadgeAward --- cmd/wire_gen.go | 6 +++--- internal/repo/badge/badge_repo.go | 9 --------- internal/repo/badge_award/badge_award_repo.go | 9 +++++++++ internal/service/badge/badge_award_service.go | 2 ++ internal/service/badge/badge_service.go | 2 -- internal/service/user_admin/user_backyard.go | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go index 4363f08bb..c45d2f396 100644 --- a/cmd/wire_gen.go +++ b/cmd/wire_gen.go @@ -227,11 +227,11 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo, reviewService, reviewActivityRepo) revisionController := controller.NewRevisionController(contentRevisionService, rankService) rankController := controller.NewRankController(rankService) - badgeRepo := badge.NewBadgeRepo(dataData, uniqueIDRepo) + badgeAwardRepo := badge_award.NewBadgeAwardRepo(dataData, uniqueIDRepo) notificationRepo := notification2.NewNotificationRepo(dataData) pluginUserConfigRepo := plugin_config.NewPluginUserConfigRepo(dataData) userAdminRepo := user.NewUserAdminRepo(dataData, authRepo) - userAdminService := user_admin.NewUserAdminService(userAdminRepo, userRoleRelService, authService, userCommon, userActiveActivityRepo, siteInfoCommonService, emailService, questionRepo, answerRepo, commentCommonRepo, userExternalLoginRepo, notificationRepo, pluginUserConfigRepo, badgeRepo) + userAdminService := user_admin.NewUserAdminService(userAdminRepo, userRoleRelService, authService, userCommon, userActiveActivityRepo, siteInfoCommonService, emailService, questionRepo, answerRepo, commentCommonRepo, userExternalLoginRepo, notificationRepo, pluginUserConfigRepo, badgeAwardRepo) userAdminController := controller_admin.NewUserAdminController(userAdminService) reasonRepo := reason.NewReasonRepo(configService) reasonService := reason2.NewReasonService(reasonRepo) @@ -241,6 +241,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, siteInfoController := controller_admin.NewSiteInfoController(siteInfoService) controllerSiteInfoController := controller.NewSiteInfoController(siteInfoCommonService) notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService, notificationQueueService, userExternalLoginRepo, siteInfoCommonService) + badgeRepo := badge.NewBadgeRepo(dataData, uniqueIDRepo) notificationService := notification.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService, userRepo, reportRepo, reviewService, badgeRepo) notificationController := controller.NewNotificationController(notificationService, rankService) dashboardService := dashboard.NewDashboardService(questionRepo, answerRepo, commentCommonRepo, voteRepo, userRepo, reportRepo, configService, siteInfoCommonService, serviceConf, reviewService, revisionRepo, dataData) @@ -263,7 +264,6 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database, metaService := meta2.NewMetaService(metaCommonService, userCommon, answerRepo, questionRepo, eventQueueService) metaController := controller.NewMetaController(metaService) badgeGroupRepo := badge_group.NewBadgeGroupRepo(dataData, uniqueIDRepo) - badgeAwardRepo := badge_award.NewBadgeAwardRepo(dataData, uniqueIDRepo) eventRuleRepo := badge.NewEventRuleRepo(dataData) badgeAwardService := badge2.NewBadgeAwardService(badgeAwardRepo, badgeRepo, userCommon, objService, notificationQueueService) badgeEventService := badge2.NewBadgeEventService(dataData, eventQueueService, badgeRepo, eventRuleRepo, badgeAwardService) diff --git a/internal/repo/badge/badge_repo.go b/internal/repo/badge/badge_repo.go index 4c5e51ae1..d52fc1229 100644 --- a/internal/repo/badge/badge_repo.go +++ b/internal/repo/badge/badge_repo.go @@ -149,12 +149,3 @@ func (r *badgeRepo) UpdateAwardCount(ctx context.Context, badgeID string, awardC } return } - -// DeleteUserBadge delete user badge -func (r *badgeRepo) DeleteUserBadge(ctx context.Context, userID string) (err error) { - _, err = r.data.DB.Context(ctx).Where("user_id = ?", userID).Delete(&entity.BadgeAward{}) - if err != nil { - err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() - } - return -} diff --git a/internal/repo/badge_award/badge_award_repo.go b/internal/repo/badge_award/badge_award_repo.go index c1ce1e584..8c8dd9850 100644 --- a/internal/repo/badge_award/badge_award_repo.go +++ b/internal/repo/badge_award/badge_award_repo.go @@ -184,3 +184,12 @@ func (r *badgeAwardRepo) GetByUserIdAndBadgeIdAndAwardKey(ctx context.Context, u } return } + +// DeleteUserBadgeAward delete user badge award +func (r *badgeAwardRepo) DeleteUserBadgeAward(ctx context.Context, userID string) (err error) { + _, err = r.data.DB.Context(ctx).Where("user_id = ?", userID).Delete(&entity.BadgeAward{}) + if err != nil { + err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() + } + return +} diff --git a/internal/service/badge/badge_award_service.go b/internal/service/badge/badge_award_service.go index feb95a657..5b0df2897 100644 --- a/internal/service/badge/badge_award_service.go +++ b/internal/service/badge/badge_award_service.go @@ -52,6 +52,8 @@ type BadgeAwardRepo interface { GetByUserIdAndBadgeId(ctx context.Context, userID string, badgeID string) (badgeAward *entity.BadgeAward, exists bool, err error) GetByUserIdAndBadgeIdAndAwardKey(ctx context.Context, userID string, badgeID string, awardKey string) (badgeAward *entity.BadgeAward, exists bool, err error) + + DeleteUserBadgeAward(ctx context.Context, userID string) (err error) } type BadgeAwardService struct { diff --git a/internal/service/badge/badge_service.go b/internal/service/badge/badge_service.go index 5ed4c1573..0ab538a3b 100644 --- a/internal/service/badge/badge_service.go +++ b/internal/service/badge/badge_service.go @@ -45,8 +45,6 @@ type BadgeRepo interface { UpdateStatus(ctx context.Context, id string, status int8) (err error) UpdateAwardCount(ctx context.Context, badgeID string, awardCount int) (err error) - - DeleteUserBadge(ctx context.Context, userID string) (err error) } type BadgeService struct { diff --git a/internal/service/user_admin/user_backyard.go b/internal/service/user_admin/user_backyard.go index 6f436b0c7..6c1d50c13 100644 --- a/internal/service/user_admin/user_backyard.go +++ b/internal/service/user_admin/user_backyard.go @@ -84,7 +84,7 @@ type UserAdminService struct { userExternalLoginRepo user_external_login.UserExternalLoginRepo notificationRepo notificationcommon.NotificationRepo pluginUserConfigRepo plugin_common.PluginUserConfigRepo - badgeRepo badge.BadgeRepo + badgeAwardRepo badge.BadgeAwardRepo } // NewUserAdminService new user admin service @@ -102,7 +102,7 @@ func NewUserAdminService( userExternalLoginRepo user_external_login.UserExternalLoginRepo, notificationRepo notificationcommon.NotificationRepo, pluginUserConfigRepo plugin_common.PluginUserConfigRepo, - badgeRepo badge.BadgeRepo, + badgeAwardRepo badge.BadgeAwardRepo, ) *UserAdminService { return &UserAdminService{ userRepo: userRepo, @@ -118,7 +118,7 @@ func NewUserAdminService( userExternalLoginRepo: userExternalLoginRepo, notificationRepo: notificationRepo, pluginUserConfigRepo: pluginUserConfigRepo, - badgeRepo: badgeRepo, + badgeAwardRepo: badgeAwardRepo, } } @@ -194,9 +194,9 @@ func (us *UserAdminService) removeAllUserConfiguration(ctx context.Context, user if err != nil { log.Errorf("remove all user plugin config error: %v", err) } - err = us.badgeRepo.DeleteUserBadge(ctx, userID) + err = us.badgeAwardRepo.DeleteUserBadgeAward(ctx, userID) if err != nil { - log.Errorf("remove all user badge error: %v", err) + log.Errorf("remove all user badge award error: %v", err) } }