Skip to content

Commit

Permalink
[chore] #112 - EnterpriseRepository에서 Enterprise 타입 Optional로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
2oo1s committed Nov 20, 2024
1 parent ab9bc18 commit ac4505b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface EnterpriseRepository extends JpaRepository<Enterprise, String> {
Expand All @@ -30,7 +31,7 @@ List<Enterprise> findEnterprises(@Param("entName") String entName,
@Param("addrCity") String addrCity);

// 기업회원 상세 정보 조회
Enterprise findByEntId(String entId);
Optional<Enterprise> findByEntId(String entId);

// 가입 승인 대기 중인 기업회원 목록 조회
@Query("SELECT e FROM Enterprise e " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Enterprise> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RequiredArgsConstructor
Expand Down Expand Up @@ -39,8 +40,13 @@ public List<AdminEnterpriseDTO> getEnterprises(AdminEnterpriseReqDTO adminEnterp

@Override
public AdminEnterpriseDetailDTO getEnterpriseInfo(String entId) {
try {
Enterprise enterprise = enterpriseRepository.findByEntId(entId);
Optional<Enterprise> optionalEnterprise = enterpriseRepository.findByEntId(entId);

if (optionalEnterprise.isEmpty()) {
throw new NoEnterpriseException("해당 기업 ID를 찾을 수 없습니다: " + entId);
}

Enterprise enterprise = optionalEnterprise.get();

return AdminEnterpriseDetailDTO.builder()
.entId(enterprise.getEntId())
Expand All @@ -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
Expand Down

0 comments on commit ac4505b

Please sign in to comment.