From f31f701b81b165b4e4fe195721b8a46b00e3d188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9D=80=EC=B1=84?= Date: Wed, 3 Jul 2024 01:04:06 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EC=97=85=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../companyUser/entity/CompanyUser.java | 6 ++--- .../repository/CompanyUserRepositoryImpl.java | 24 +++++++++++-------- .../companyUser/service/CpUserService.java | 10 -------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/main/java/team9502/sinchulgwinong/domain/companyUser/entity/CompanyUser.java b/src/main/java/team9502/sinchulgwinong/domain/companyUser/entity/CompanyUser.java index 0f244aa..976899d 100644 --- a/src/main/java/team9502/sinchulgwinong/domain/companyUser/entity/CompanyUser.java +++ b/src/main/java/team9502/sinchulgwinong/domain/companyUser/entity/CompanyUser.java @@ -64,11 +64,11 @@ public class CompanyUser extends BaseTimeEntity implements CommonPoint { private String cpPassword; @Setter - @Column(nullable = true) - private Float averageRating; + @Column + private Float averageRating = 0.0f; @Setter - private Integer reviewCount; + private Integer reviewCount = 0; @Column(nullable = false) private Integer viewCount = 0; diff --git a/src/main/java/team9502/sinchulgwinong/domain/companyUser/repository/CompanyUserRepositoryImpl.java b/src/main/java/team9502/sinchulgwinong/domain/companyUser/repository/CompanyUserRepositoryImpl.java index d1ae733..720b215 100644 --- a/src/main/java/team9502/sinchulgwinong/domain/companyUser/repository/CompanyUserRepositoryImpl.java +++ b/src/main/java/team9502/sinchulgwinong/domain/companyUser/repository/CompanyUserRepositoryImpl.java @@ -3,6 +3,8 @@ import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -13,12 +15,12 @@ import team9502.sinchulgwinong.domain.scrap.entity.QCpUserScrap; import java.util.List; -import java.util.Optional; @Repository public class CompanyUserRepositoryImpl implements CompanyUserRepositoryCustom { private final JPAQueryFactory queryFactory; + private static final Logger logger = LoggerFactory.getLogger(CompanyUserRepositoryImpl.class); public CompanyUserRepositoryImpl(EntityManager entityManager) { this.queryFactory = new JPAQueryFactory(entityManager); @@ -59,17 +61,18 @@ public Page findAllWithFilters(String sort, Float minRating, Float case "createdAtDesc": query.orderBy(companyUser.createdAt.desc()); break; + default: + query.orderBy(companyUser.cpUserId.asc()); // 기본 정렬 조건 } + } else { + query.orderBy(companyUser.cpUserId.asc()); // 기본 정렬 조건 } - // 총 개수 계산을 위한 쿼리 생성 및 실행, null 체크 - Long countResult = queryFactory - .select(companyUser.count()) - .from(companyUser) - .where(query.getMetadata().getWhere()) - .fetchOne(); + // 총 개수 계산을 위한 쿼리 생성 및 실행 + long total = query.fetchCount(); - long total = Optional.ofNullable(countResult).orElse(0L); + // 쿼리 디버깅을 위한 로그 + logger.info("쿼리 실행 조건 - sort: {}, minRating: {}, maxRating: {}, pageable: {}, total: {}", sort, minRating, maxRating, pageable, total); // 페이지 데이터 조회 List results = query @@ -77,10 +80,12 @@ public Page findAllWithFilters(String sort, Float minRating, Float .limit(pageable.getPageSize()) .fetch(); + // 결과 디버깅을 위한 로그 + logger.info("쿼리 결과 - results size: {}, pageable: {}", results.size(), pageable); + return new PageImpl<>(results, pageable, total); } - @Override public long countScrapsByCompanyUserId(Long cpUserId) { QCpUserScrap scrap = QCpUserScrap.cpUserScrap; @@ -93,5 +98,4 @@ public long countScrapsByCompanyUserId(Long cpUserId) { // fetchOne() 결과가 null일 경우 0으로 대체 return count != null ? count : 0L; } - } diff --git a/src/main/java/team9502/sinchulgwinong/domain/companyUser/service/CpUserService.java b/src/main/java/team9502/sinchulgwinong/domain/companyUser/service/CpUserService.java index cff1c1f..a8edfb8 100644 --- a/src/main/java/team9502/sinchulgwinong/domain/companyUser/service/CpUserService.java +++ b/src/main/java/team9502/sinchulgwinong/domain/companyUser/service/CpUserService.java @@ -1,8 +1,6 @@ package team9502.sinchulgwinong.domain.companyUser.service; import lombok.RequiredArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.crypto.password.PasswordEncoder; @@ -36,7 +34,6 @@ public class CpUserService { private final EmailVerificationService emailVerificationService; private final PointService pointService; private final JobBoardRepository jobBoardRepository; - private static final Logger logger = LoggerFactory.getLogger(CpUserService.class); @Transactional public CpUserProfileResponseDTO getCpUserProfile(Long cpUserId) { @@ -126,11 +123,8 @@ public void updateCpUserPassword(Long cpUserId, CpUserPasswordUpdateRequestDTO r @Transactional(readOnly = true) public CpUserPageResponseDTO getAllCompanyUsers(String sort, Float minRating, Float maxRating, Pageable pageable) { - - logger.info("기업회원 정렬 확인: {}, minRating: {}, maxRating: {}, pageable: {}", sort, minRating, maxRating, pageable); Page companyUsers = companyUserRepository.findAllWithFilters(sort, minRating, maxRating, pageable); - logger.info("기업 회원 총합: {}", companyUsers.getTotalElements()); List content = companyUsers.getContent().stream() .map(this::convertToDTO) .collect(Collectors.toList()); @@ -145,15 +139,12 @@ public CpUserPageResponseDTO getAllCompanyUsers(String sort, Float minRating, Fl @Transactional public void usePointsForBanner(Long cpUserId) { - CompanyUser companyUser = companyUserRepository.findById(cpUserId) .orElseThrow(() -> new ApiException(ErrorCode.COMPANY_USER_NOT_FOUND)); - pointService.deductPoints(companyUser, UpType.BANNER); } private CpUserResponseDTO convertToDTO(CompanyUser companyUser) { - return new CpUserResponseDTO( companyUser.getCpUserId(), companyUser.getCpName(), @@ -165,7 +156,6 @@ private CpUserResponseDTO convertToDTO(CompanyUser companyUser) { @Transactional public void deleteCpUser(Long cpUserId, CpUserDeleteRequestDTO requestDTO) { - CompanyUser companyUser = companyUserRepository.findById(cpUserId) .orElseThrow(() -> new ApiException(ErrorCode.COMPANY_USER_NOT_FOUND));