From ac4505b7691d11581ae611f7a273474af11cbd3e Mon Sep 17 00:00:00 2001 From: 2oo1s Date: Wed, 20 Nov 2024 11:55:37 +0900 Subject: [PATCH] =?UTF-8?q?[chore]=20#112=20-=20EnterpriseRepository?= =?UTF-8?q?=EC=97=90=EC=84=9C=20Enterprise=20=ED=83=80=EC=9E=85=20Optional?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/enterprise/EnterpriseRepository.java | 3 ++- .../domain/enterprise/EnterpriseServiceImpl.java | 11 +++++++++-- .../service/AdminEnterpriseServiceImpl.java | 13 ++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/wooribound/domain/enterprise/EnterpriseRepository.java b/src/main/java/com/wooribound/domain/enterprise/EnterpriseRepository.java index 54a4780..c308836 100644 --- a/src/main/java/com/wooribound/domain/enterprise/EnterpriseRepository.java +++ b/src/main/java/com/wooribound/domain/enterprise/EnterpriseRepository.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface EnterpriseRepository extends JpaRepository { @@ -30,7 +31,7 @@ List findEnterprises(@Param("entName") String entName, @Param("addrCity") String addrCity); // 기업회원 상세 정보 조회 - Enterprise findByEntId(String entId); + Optional findByEntId(String entId); // 가입 승인 대기 중인 기업회원 목록 조회 @Query("SELECT e FROM Enterprise e " + diff --git a/src/main/java/com/wooribound/domain/enterprise/EnterpriseServiceImpl.java b/src/main/java/com/wooribound/domain/enterprise/EnterpriseServiceImpl.java index 44fcb14..3efdfed 100644 --- a/src/main/java/com/wooribound/domain/enterprise/EnterpriseServiceImpl.java +++ b/src/main/java/com/wooribound/domain/enterprise/EnterpriseServiceImpl.java @@ -5,6 +5,7 @@ import com.wooribound.domain.enterprise.dto.EnterpriseInfoDTO; import com.wooribound.global.constant.YNP; import com.wooribound.global.exception.DuplicatedIdException; +import com.wooribound.global.exception.NoEnterpriseException; import com.wooribound.global.exception.NotValidPasswordException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -117,8 +118,14 @@ public String duplicateIdCheck(String id) { @Override public void withdraw(String id, String pw) { System.out.println("들어온 비밀번호:" +pw); - Enterprise enterprise = enterpriseRepository.findByEntId(id); - if (!passwordEncoder.matches(pw, enterprise.getEntPwd())) { + + Optional optionalEnterprise = enterpriseRepository.findByEntId(id); + + if (optionalEnterprise.isEmpty()) { + throw new NoEnterpriseException("해당 기업 ID를 찾을 수 없습니다: " + id); + } + Enterprise enterprise = optionalEnterprise.get(); + if (!passwordEncoder.matches(pw, enterprise.getEntPwd())) { throw new NotValidPasswordException(); } enterprise.setIsDeleted(YNP.P); diff --git a/src/main/java/com/wooribound/domain/enterprise/service/AdminEnterpriseServiceImpl.java b/src/main/java/com/wooribound/domain/enterprise/service/AdminEnterpriseServiceImpl.java index 94770ab..c9852bd 100644 --- a/src/main/java/com/wooribound/domain/enterprise/service/AdminEnterpriseServiceImpl.java +++ b/src/main/java/com/wooribound/domain/enterprise/service/AdminEnterpriseServiceImpl.java @@ -12,6 +12,7 @@ import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -39,8 +40,13 @@ public List getEnterprises(AdminEnterpriseReqDTO adminEnterp @Override public AdminEnterpriseDetailDTO getEnterpriseInfo(String entId) { - try { - Enterprise enterprise = enterpriseRepository.findByEntId(entId); + Optional optionalEnterprise = enterpriseRepository.findByEntId(entId); + + if (optionalEnterprise.isEmpty()) { + throw new NoEnterpriseException("해당 기업 ID를 찾을 수 없습니다: " + entId); + } + + Enterprise enterprise = optionalEnterprise.get(); return AdminEnterpriseDetailDTO.builder() .entId(enterprise.getEntId()) @@ -53,9 +59,6 @@ public AdminEnterpriseDetailDTO getEnterpriseInfo(String entId) { .entField(enterprise.getEntField()) .revenue(enterprise.getRevenue()) .build(); - } catch (Exception e) { - throw new NoEnterpriseException("해당 기업 ID를 찾을 수 없습니다: " + entId, e); - } } @Override