From d12818620b13fdb493e3f24c2286b3cd7957a30e Mon Sep 17 00:00:00 2001 From: Diger Date: Sun, 11 Feb 2024 17:52:47 +0900 Subject: [PATCH] refactor : Total User Count --- .../domain/admin/service/AdminBusinessService.java | 14 +++++++++++--- .../service/UserIsolationCRUDService.java | 7 ++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/usw/suwiki/domain/admin/service/AdminBusinessService.java b/src/main/java/usw/suwiki/domain/admin/service/AdminBusinessService.java index 21fd53b7..eabe46c5 100644 --- a/src/main/java/usw/suwiki/domain/admin/service/AdminBusinessService.java +++ b/src/main/java/usw/suwiki/domain/admin/service/AdminBusinessService.java @@ -15,9 +15,11 @@ import usw.suwiki.domain.postreport.ExamPostReport; import usw.suwiki.domain.postreport.service.ReportPostService; import usw.suwiki.domain.restrictinguser.service.RestrictingUserService; +import usw.suwiki.domain.user.user.Role; import usw.suwiki.domain.user.user.User; import usw.suwiki.domain.user.user.controller.dto.UserRequestDto.LoginForm; import usw.suwiki.domain.user.user.service.UserCRUDService; +import usw.suwiki.domain.user.userIsolation.service.UserIsolationCRUDService; import usw.suwiki.global.exception.errortype.AccountException; import usw.suwiki.global.jwt.JwtAgent; @@ -36,6 +38,7 @@ public class AdminBusinessService { private final BlacklistDomainCRUDService blacklistDomainCRUDService; private final UserCRUDService userCRUDService; + private final UserIsolationCRUDService userIsolationCRUDService; private final ReportPostService reportPostService; private final EvaluatePostCRUDService evaluatePostCRUDService; private final ExamPostCRUDService examPostCRUDService; @@ -49,10 +52,15 @@ public class AdminBusinessService { public Map executeAdminLogin(LoginForm loginForm) { User user = userCRUDService.loadUserFromLoginId(loginForm.loginId()); if (user.validatePassword(bCryptPasswordEncoder, loginForm.password())) { - if (user.getRole().getKey().equals("ADMIN")) { + if (user.getRole().getKey().equals(Role.ADMIN.getKey())) { + + final int userCount = userCRUDService.findAllUsersSize(); + final int userIsolationCount = userIsolationCRUDService.findAllIsolationUsersSize(); + final int totalUserCount = userCount + userIsolationCount; + return new HashMap<>() {{ put("AccessToken", jwtAgent.createAccessToken(user)); - put("UserCount", String.valueOf(userCRUDService.findAllUsersSize())); + put("UserCount", String.valueOf(totalUserCount)); }}; } throw new AccountException(USER_RESTRICTED); @@ -194,4 +202,4 @@ private void plusReportingUserPoint(Long reportingUserIdx) { User user = userCRUDService.loadUserFromUserIdx(reportingUserIdx); user.increasePointByReporting(); } -} \ No newline at end of file +} diff --git a/src/main/java/usw/suwiki/domain/user/userIsolation/service/UserIsolationCRUDService.java b/src/main/java/usw/suwiki/domain/user/userIsolation/service/UserIsolationCRUDService.java index 45f7ae05..4067e620 100644 --- a/src/main/java/usw/suwiki/domain/user/userIsolation/service/UserIsolationCRUDService.java +++ b/src/main/java/usw/suwiki/domain/user/userIsolation/service/UserIsolationCRUDService.java @@ -61,6 +61,11 @@ public UserIsolation loadUserFromEmail(String email) { return convertOptionalUserToDomainUser(userIsolationRepository.findByEmail(email)); } + @Transactional(readOnly = true) + public int findAllIsolationUsersSize() { + return userIsolationRepository.findAll().size(); + } + public void deleteByUserIdx(Long userIdx) { userIsolationRepository.deleteByUserIdx(userIdx); } @@ -75,4 +80,4 @@ private UserIsolation convertOptionalUserToDomainUser(Optional op } throw new AccountException(USER_NOT_EXISTS); } -} \ No newline at end of file +}