Skip to content

Commit

Permalink
refactor: 유저 카운트 쿼리 및 메서드 명 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wonslee committed Feb 11, 2024
1 parent 772e572 commit a52a19d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package usw.suwiki.domain.admin.service;

import static usw.suwiki.global.exception.ExceptionType.PASSWORD_ERROR;
import static usw.suwiki.global.exception.ExceptionType.USER_RESTRICTED;
import static usw.suwiki.global.util.apiresponse.ApiResponseFactory.successCapitalFlag;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.*;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.EvaluatePostBlacklistForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.EvaluatePostNoProblemForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.EvaluatePostRestrictForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.ExamPostBlacklistForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.ExamPostNoProblemForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminRequestDto.ExamPostRestrictForm;
import usw.suwiki.domain.admin.controller.dto.UserAdminResponseDto.LoadAllReportedPostForm;
import usw.suwiki.domain.blacklistdomain.service.BlacklistDomainCRUDService;
import usw.suwiki.domain.evaluatepost.domain.EvaluatePost;
Expand All @@ -23,14 +35,6 @@
import usw.suwiki.global.exception.errortype.AccountException;
import usw.suwiki.global.jwt.JwtAgent;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static usw.suwiki.global.exception.ExceptionType.PASSWORD_ERROR;
import static usw.suwiki.global.exception.ExceptionType.USER_RESTRICTED;
import static usw.suwiki.global.util.apiresponse.ApiResponseFactory.successCapitalFlag;

@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -54,9 +58,9 @@ public Map<String, String> executeAdminLogin(LoginForm loginForm) {
if (user.validatePassword(bCryptPasswordEncoder, loginForm.password())) {
if (user.getRole().getKey().equals(Role.ADMIN.getKey())) {

final int userCount = userCRUDService.findAllUsersSize();
final int userIsolationCount = userIsolationCRUDService.findAllIsolationUsersSize();
final int totalUserCount = userCount + userIsolationCount;
final long userCount = userCRUDService.countAllUsers();
final long userIsolationCount = userIsolationCRUDService.countAllIsolatedUsers();
final long totalUserCount = userCount + userIsolationCount;

return new HashMap<>() {{
put("AccessToken", jwtAgent.createAccessToken(user));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package usw.suwiki.domain.user.user.service;

import static usw.suwiki.global.exception.ExceptionType.USER_NOT_EXISTS;
import static usw.suwiki.global.exception.ExceptionType.USER_NOT_FOUND;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import usw.suwiki.domain.user.user.User;
import usw.suwiki.domain.user.user.repository.UserRepository;
import usw.suwiki.global.exception.errortype.AccountException;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import static usw.suwiki.global.exception.ExceptionType.USER_NOT_EXISTS;
import static usw.suwiki.global.exception.ExceptionType.USER_NOT_FOUND;

@Service
@RequiredArgsConstructor
@Transactional
Expand Down Expand Up @@ -73,8 +72,8 @@ private User convertOptionalUserToDomainUser(Optional<User> optionalUser) {
}

@Transactional(readOnly = true)
public int findAllUsersSize() {
return userRepository.findAll().size();
public long countAllUsers() {
return userRepository.count();
}

public void deleteFromUserIdx(Long userIdx) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package usw.suwiki.domain.user.userIsolation.service;

import static usw.suwiki.global.exception.ExceptionType.USER_NOT_EXISTS;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import usw.suwiki.domain.user.user.User;
import usw.suwiki.domain.user.userIsolation.UserIsolation;
import usw.suwiki.domain.user.userIsolation.repository.UserIsolationRepository;
import usw.suwiki.global.exception.errortype.AccountException;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static usw.suwiki.global.exception.ExceptionType.USER_NOT_EXISTS;

@Service
@RequiredArgsConstructor
@Transactional
Expand Down Expand Up @@ -62,8 +59,8 @@ public UserIsolation loadUserFromEmail(String email) {
}

@Transactional(readOnly = true)
public int findAllIsolationUsersSize() {
return userIsolationRepository.findAll().size();
public long countAllIsolatedUsers() {
return userIsolationRepository.count();
}

public void deleteByUserIdx(Long userIdx) {
Expand Down

0 comments on commit a52a19d

Please sign in to comment.