Skip to content

Commit

Permalink
refactor : Total User Count
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Diger committed Feb 11, 2024
1 parent 401739e commit d128186
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -49,10 +52,15 @@ public class AdminBusinessService {
public Map<String, String> 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);
Expand Down Expand Up @@ -194,4 +202,4 @@ private void plusReportingUserPoint(Long reportingUserIdx) {
User user = userCRUDService.loadUserFromUserIdx(reportingUserIdx);
user.increasePointByReporting();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -75,4 +80,4 @@ private UserIsolation convertOptionalUserToDomainUser(Optional<UserIsolation> op
}
throw new AccountException(USER_NOT_EXISTS);
}
}
}

0 comments on commit d128186

Please sign in to comment.