From ae522fb93326391b6fe185c5c982dc4db2331966 Mon Sep 17 00:00:00 2001 From: seungzzok <123801984+seungzzok@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:26:36 +0900 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20=EC=97=90=EB=9F=AC=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - participation category를 email로 변경 - 임시로 ETC_ERROR로 처리했던 에러들을 상황에 맞게 전부 구체화 --- .../writon/admin/global/error/ErrorCode.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/writon/admin/global/error/ErrorCode.java b/src/main/java/com/writon/admin/global/error/ErrorCode.java index 51718ad..f405f53 100644 --- a/src/main/java/com/writon/admin/global/error/ErrorCode.java +++ b/src/main/java/com/writon/admin/global/error/ErrorCode.java @@ -27,17 +27,26 @@ public enum ErrorCode { ACCESS_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND, "A05", "AccessToken이 존재하지 않습니다"), REFRESH_TOKEN_EXPIRATION(HttpStatus.UNAUTHORIZED, "A06", "RefreshToken이 만료되었습니다"), REFRESH_TOKEN_INCONSISTENCY(HttpStatus.NOT_FOUND, "A07", "RefreshToken이 일치하지 않습니다"), - DISABLED_USER(HttpStatus.NOT_FOUND, "A08", "비활성화된 계정입니다"), - LOCKED_USER(HttpStatus.NOT_FOUND, "A09", "계정이 잠겨 있습니다"), + DISABLED_USER(HttpStatus.FORBIDDEN, "A08", "비활성화된 계정입니다"), + LOCKED_USER(HttpStatus.FORBIDDEN, "A09", "계정이 잠겨 있습니다"), + USER_IDENTIFIER_DUPLICATE(HttpStatus.CONFLICT, "A10", "동일한 계정이 이미 존재합니다"), // organization ORGANIZATION_NOT_FOUND(HttpStatus.NOT_FOUND, "O01", "조직 정보를 찾을 수 없습니다"), + ORGANIZATION_DUPLICATE(HttpStatus.CONFLICT, "O02", "중복되는 조직이 존재합니다"), + POSITION_NOT_FOUND(HttpStatus.NOT_FOUND, "O03", "포지션 정보를 찾을 수 없습니다"), // challenge CHALLENGE_NOT_FOUND(HttpStatus.NOT_FOUND, "C01", "챌린지 정보를 찾을 수 없습니다"), - - // participation - EMAIL_DUPLICATION(HttpStatus.BAD_REQUEST, "P01", "중복되는 이메일이 존재합니다"); + CHALLENGE_DAY_NOT_FOUND(HttpStatus.NOT_FOUND, "C02", "챌린지 날짜 정보를 찾을 수 없습니다"), + CHALLENGE_USER_NOT_FOUND(HttpStatus.NOT_FOUND, "C03", "챌린지에 참여한 유저 정보를 찾을 수 없습니다"), + USER_TEMPLATE_NOT_FOUND(HttpStatus.NOT_FOUND, "C04", "해당 유저의 챌린지 참여 정보를 찾을 수 없습니다"), + QUESTION_NOT_FOUND(HttpStatus.NOT_FOUND, "C05", "질문 정보를 찾을 수 없습니다"), + + // email + EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "E01", "해당하는 이메일 정보를 찾을 수 없습니다"), + EMAIL_DUPLICATE(HttpStatus.CONFLICT, "E02", "중복되는 이메일이 존재합니다"), + EMAIL_SEND_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "E03", "이메일 전송에 실패하였습니다"); private final HttpStatus httpStatus; private final String code; From c85ca04db65c349a0ac608be2c84abc4629e0b26 Mon Sep 17 00:00:00 2001 From: seungzzok <123801984+seungzzok@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:30:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EC=83=88=EB=A1=AD=EA=B2=8C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC=ED=95=9C=20=EC=97=90=EB=9F=AC=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EA=B5=AC=EC=B2=B4=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/domain/controller/ParticipationController.java | 2 +- .../java/com/writon/admin/domain/service/AuthService.java | 4 ++-- .../com/writon/admin/domain/service/ChallengeService.java | 8 ++++---- .../com/writon/admin/domain/service/EmailService.java | 2 +- .../writon/admin/domain/service/OrganizationService.java | 6 ++++++ .../writon/admin/domain/service/ParticipationService.java | 6 +++--- .../global/config/auth/JwtAuthenticationEntryPoint.java | 1 + 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/writon/admin/domain/controller/ParticipationController.java b/src/main/java/com/writon/admin/domain/controller/ParticipationController.java index 38788af..68697ff 100644 --- a/src/main/java/com/writon/admin/domain/controller/ParticipationController.java +++ b/src/main/java/com/writon/admin/domain/controller/ParticipationController.java @@ -63,7 +63,7 @@ public SuccessDto> participate( return new SuccessDto<>(sendedEmailList); } else { - throw new CustomException(ErrorCode.EMAIL_DUPLICATION); + throw new CustomException(ErrorCode.EMAIL_DUPLICATE); } } diff --git a/src/main/java/com/writon/admin/domain/service/AuthService.java b/src/main/java/com/writon/admin/domain/service/AuthService.java index 28e2661..b4f6d99 100644 --- a/src/main/java/com/writon/admin/domain/service/AuthService.java +++ b/src/main/java/com/writon/admin/domain/service/AuthService.java @@ -48,7 +48,7 @@ public class AuthService { // ========== SignUp API ========== public SignUpResponseDto signup(SignUpRequestDto signUpRequestDto) { if (adminUserRepository.existsByIdentifier(signUpRequestDto.getIdentifier())) { - throw new CustomException(ErrorCode.ETC_ERROR); + throw new CustomException(ErrorCode.USER_IDENTIFIER_DUPLICATE); } AdminUser encodedAdminUser = signUpRequestDto.toAdminUser(passwordEncoder); @@ -89,7 +89,7 @@ public LoginResponseWrapper login(LoginRequestDto loginRequestDto) { // 5. 해당 Organization 정보 가져오기 AdminUser adminUser = adminUserRepository.findByIdentifier(identifier) - .orElseThrow(() -> new UsernameNotFoundException(" -> 데이터베이스에서 찾을 수 없습니다.")); + .orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)); Optional organization = organizationRepository.findByAdminUserId(adminUser.getId()); // 7. 챌린지 정보 가져오기 diff --git a/src/main/java/com/writon/admin/domain/service/ChallengeService.java b/src/main/java/com/writon/admin/domain/service/ChallengeService.java index ff85084..9f1316f 100644 --- a/src/main/java/com/writon/admin/domain/service/ChallengeService.java +++ b/src/main/java/com/writon/admin/domain/service/ChallengeService.java @@ -56,7 +56,7 @@ public class ChallengeService { private final UserTemplateRepository userTemplateRepository; private final EmailService emailService; - // ========== Create API ========== + // ========== CreateChallenge API ========== public CreateChallengeResponseDto createChallenge(CreateChallengeRequestDto requestDto) { // 1. 조직정보 추출 Organization organization = tokenUtil.getOrganization(); @@ -179,7 +179,7 @@ public QuestionsResponseDto getQuestions(Long challengeId) { public ChallengeInfoResponseDto getInfo(Long challengeId) { // 1. 챌린지 기본 정보 가져오기 Challenge challenge = challengeRepository.findById(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 챌린지 날짜 정보 가져오기 List challengeDays = challengeDayRepository.findByChallengeId(challengeId) @@ -197,7 +197,7 @@ public ChallengeInfoResponseDto getInfo(Long challengeId) { public QuestionsResponseDto putQuestions(Long challengeId, QuestionsRequestDto requestDto) { // 1. 챌린지 조회 Challenge challenge = challengeRepository.findById(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 질문 리스트 조회 List questionList = questionRepository.findByChallengeId(challengeId) @@ -310,7 +310,7 @@ public QuestionsResponseDto putQuestions(Long challengeId, QuestionsRequestDto r public ChallengeInfoResponseDto putInfo(Long challengeId, ChallengeInfoRequestDto requestDto) { // 1. 챌린지 기본 정보 조회 Challenge challenge = challengeRepository.findById(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 챌린지 기본 정보 수정 및 저장 challenge.setName(requestDto.getName()); diff --git a/src/main/java/com/writon/admin/domain/service/EmailService.java b/src/main/java/com/writon/admin/domain/service/EmailService.java index 71c6056..a8c4272 100644 --- a/src/main/java/com/writon/admin/domain/service/EmailService.java +++ b/src/main/java/com/writon/admin/domain/service/EmailService.java @@ -47,7 +47,7 @@ public void sendEmail(Challenge challenge, String email) { log.info("Succeeded to send Email"); } catch (Exception e) { log.info("Failed to send Email"); - throw new CustomException(ErrorCode.ETC_ERROR); + throw new CustomException(ErrorCode.EMAIL_SEND_FAILED); } } diff --git a/src/main/java/com/writon/admin/domain/service/OrganizationService.java b/src/main/java/com/writon/admin/domain/service/OrganizationService.java index 996132f..ca0d0a7 100644 --- a/src/main/java/com/writon/admin/domain/service/OrganizationService.java +++ b/src/main/java/com/writon/admin/domain/service/OrganizationService.java @@ -34,6 +34,12 @@ public CreateOrganizationResponseDto createOrganization( // 1. 사용자 정보 불러오기 AdminUser adminUser = tokenUtil.getAdminUser(); + // 1. 조직 생성 여부 확인하기 + organizationRepository.findByAdminUserId(adminUser.getId()) + .ifPresent(org -> { + throw new CustomException(ErrorCode.ORGANIZATION_DUPLICATE); + }); + // 2. Organization 객체 생성 Organization organization = new Organization( createOrganizationRequestDto.getName(), diff --git a/src/main/java/com/writon/admin/domain/service/ParticipationService.java b/src/main/java/com/writon/admin/domain/service/ParticipationService.java index 84e362e..b6ec313 100644 --- a/src/main/java/com/writon/admin/domain/service/ParticipationService.java +++ b/src/main/java/com/writon/admin/domain/service/ParticipationService.java @@ -49,7 +49,7 @@ public List getEmailList(Long challengeId) { public List getParticipationInfo(Long challengeId) { // 1. 챌린지 조회 Challenge challenge = challengeRepository.findById(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 유저 챌린지 조회 List userChallengeList = userChallengeRepository.findByChallengeId(challengeId) @@ -104,7 +104,7 @@ public List withdrawal(Long challengeId, List userChall for (Long userChallengeId : userChallengeIdList) { UserChallenge userChallenge = userChallengeRepository.findById(userChallengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_USER_NOT_FOUND)); userChallenge.setWithdrawn(true); userChallengeRepository.save(userChallenge); @@ -116,7 +116,7 @@ public List withdrawal(Long challengeId, List userChall // ========== Post Participate API ========== public List participate(Long challengeId, List emailList) { Challenge challenge = challengeRepository.findById(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); for (String email : emailList) { emailService.sendEmail(challenge, email); diff --git a/src/main/java/com/writon/admin/global/config/auth/JwtAuthenticationEntryPoint.java b/src/main/java/com/writon/admin/global/config/auth/JwtAuthenticationEntryPoint.java index 642ad39..65afba4 100644 --- a/src/main/java/com/writon/admin/global/config/auth/JwtAuthenticationEntryPoint.java +++ b/src/main/java/com/writon/admin/global/config/auth/JwtAuthenticationEntryPoint.java @@ -43,6 +43,7 @@ public void commence( if (exception.equals(ErrorCode.UNAUTHORIZED_TOKEN.getCode())) { errorCode = ErrorCode.UNAUTHORIZED_TOKEN; } + } exceptionResponseHandler.setResponse(response, errorCode); From 29eefecadb7d9b553d762d97d1e110c0967718fc Mon Sep 17 00:00:00 2001 From: seungzzok <123801984+seungzzok@users.noreply.github.com> Date: Mon, 28 Apr 2025 18:32:49 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20List=EC=9D=98=20Optional=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Optional을 사용하면 데이터가 존재하지 않는 경우 빈 리스트를 return하기 때문에 orElseThrow를 사용한 Error Custom을 진행할 수 없어서 제거 - 리스트의 길이가 0인 경우에 대한 예외처리를 if문을 사용해 직접 처리 - 리스트의 길이가 0이어도 되는 데이터에 대한 예외처리는 삭제 --- .../activity/UserTemplateRepository.java | 2 +- .../challenge/ChallengeDayRepository.java | 2 +- .../challenge/ChallengeRepository.java | 2 +- .../repository/challenge/EmailRepository.java | 2 +- .../organization/PositionRepository.java | 2 +- .../question/QuestionRepository.java | 2 +- .../user/UserChallengeRepository.java | 4 +- .../admin/domain/service/AuthService.java | 3 +- .../domain/service/ChallengeService.java | 58 +++++++++++++------ .../domain/service/OrganizationService.java | 15 +++-- .../domain/service/ParticipationService.java | 16 ++--- 11 files changed, 65 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/writon/admin/domain/repository/activity/UserTemplateRepository.java b/src/main/java/com/writon/admin/domain/repository/activity/UserTemplateRepository.java index c883d0e..fa6deb4 100644 --- a/src/main/java/com/writon/admin/domain/repository/activity/UserTemplateRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/activity/UserTemplateRepository.java @@ -7,7 +7,7 @@ public interface UserTemplateRepository extends JpaRepository { - Optional> findByUserChallengeId(Long userChallengeId); + List findByUserChallengeId(Long userChallengeId); int countByUserChallengeId(Long userChallengeId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeDayRepository.java b/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeDayRepository.java index 97e3263..34c7c4f 100644 --- a/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeDayRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeDayRepository.java @@ -7,6 +7,6 @@ public interface ChallengeDayRepository extends JpaRepository { - Optional> findByChallengeId(Long challengeId); + List findByChallengeId(Long challengeId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeRepository.java b/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeRepository.java index af45554..c04d8b3 100644 --- a/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/challenge/ChallengeRepository.java @@ -7,6 +7,6 @@ public interface ChallengeRepository extends JpaRepository { - Optional> findByOrganizationId(Long organizationId); + List findByOrganizationId(Long organizationId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/repository/challenge/EmailRepository.java b/src/main/java/com/writon/admin/domain/repository/challenge/EmailRepository.java index b471d88..e91df65 100644 --- a/src/main/java/com/writon/admin/domain/repository/challenge/EmailRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/challenge/EmailRepository.java @@ -7,6 +7,6 @@ public interface EmailRepository extends JpaRepository { - Optional> findByChallengeId(Long challengeId); + List findByChallengeId(Long challengeId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/repository/organization/PositionRepository.java b/src/main/java/com/writon/admin/domain/repository/organization/PositionRepository.java index 1e414c6..1da6879 100644 --- a/src/main/java/com/writon/admin/domain/repository/organization/PositionRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/organization/PositionRepository.java @@ -7,6 +7,6 @@ public interface PositionRepository extends JpaRepository { - Optional> findByOrganizationId(Long organizationId); + List findByOrganizationId(Long organizationId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/repository/question/QuestionRepository.java b/src/main/java/com/writon/admin/domain/repository/question/QuestionRepository.java index 26a6f7e..f74354e 100644 --- a/src/main/java/com/writon/admin/domain/repository/question/QuestionRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/question/QuestionRepository.java @@ -8,7 +8,7 @@ public interface QuestionRepository extends JpaRepository { - Optional> findByChallengeId(Long challengeId); + List findByChallengeId(Long challengeId); int countByKeyword(Keyword keyword); diff --git a/src/main/java/com/writon/admin/domain/repository/user/UserChallengeRepository.java b/src/main/java/com/writon/admin/domain/repository/user/UserChallengeRepository.java index 4cf605a..051fe10 100644 --- a/src/main/java/com/writon/admin/domain/repository/user/UserChallengeRepository.java +++ b/src/main/java/com/writon/admin/domain/repository/user/UserChallengeRepository.java @@ -7,7 +7,7 @@ public interface UserChallengeRepository extends JpaRepository { - Optional> findByChallengeId(Long challengeId); - Optional> findByAffiliationId(Long affiliationId); + List findByChallengeId(Long challengeId); + List findByAffiliationId(Long affiliationId); } \ No newline at end of file diff --git a/src/main/java/com/writon/admin/domain/service/AuthService.java b/src/main/java/com/writon/admin/domain/service/AuthService.java index b4f6d99..0082937 100644 --- a/src/main/java/com/writon/admin/domain/service/AuthService.java +++ b/src/main/java/com/writon/admin/domain/service/AuthService.java @@ -95,8 +95,7 @@ public LoginResponseWrapper login(LoginRequestDto loginRequestDto) { // 7. 챌린지 정보 가져오기 List challenges = Collections.emptyList(); if (organization.isPresent()) { - challenges = challengeRepository.findByOrganizationId(organization.get().getId()) - .orElse(Collections.emptyList()); // 데이터가 없을 때 빈 리스트 반환 + challenges = challengeRepository.findByOrganizationId(organization.get().getId()); // 데이터가 없을 때 빈 리스트 반환 } List challengeList = challenges.stream() .map(entity -> new ChallengeResponse(entity.getId(), entity.getName())) diff --git a/src/main/java/com/writon/admin/domain/service/ChallengeService.java b/src/main/java/com/writon/admin/domain/service/ChallengeService.java index 9f1316f..82cb998 100644 --- a/src/main/java/com/writon/admin/domain/service/ChallengeService.java +++ b/src/main/java/com/writon/admin/domain/service/ChallengeService.java @@ -98,8 +98,11 @@ public CreateChallengeResponseDto createChallenge(CreateChallengeRequestDto requ } // 6. Response 생성 - List challenges = challengeRepository.findByOrganizationId(organization.getId()) - .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); + List challenges = challengeRepository.findByOrganizationId(organization.getId()); + if (challenges.isEmpty()) { + throw new CustomException(ErrorCode.CHALLENGE_NOT_FOUND); + } + List challengeList = challenges.stream() .map(entity -> new ChallengeResponse(entity.getId(), entity.getName())) .collect(Collectors.toList()); @@ -110,16 +113,18 @@ public CreateChallengeResponseDto createChallenge(CreateChallengeRequestDto requ // ========== Get Dashboard API ========== public List getDashboard(Long challengeId) { // 1. 챌린지 날짜 리스트 추출 - List challengeDayList = challengeDayRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List challengeDayList = challengeDayRepository.findByChallengeId(challengeId); + + if (challengeDayList.isEmpty()) { + throw new CustomException(ErrorCode.CHALLENGE_DAY_NOT_FOUND); + } challengeDayList = challengeDayList.stream() .sorted(Comparator.comparing(ChallengeDay::getDay)) .toList(); // 2. 챌린지 참여 유저 리스트 추출 - List userChallengeList = userChallengeRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List userChallengeList = userChallengeRepository.findByChallengeId(challengeId); // 3. 유저별 참여여부 확인 List statusTable = new ArrayList<>(); @@ -127,8 +132,10 @@ public List getDashboard(Long challengeId) { for (UserChallenge userChallenge : userChallengeList) { List statusList = new ArrayList<>(); List userTemplateList = userTemplateRepository.findByUserChallengeId( - userChallenge.getId()) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + userChallenge.getId()); + if (userTemplateList.isEmpty()) { + throw new CustomException(ErrorCode.USER_TEMPLATE_NOT_FOUND); + } for (ChallengeDay challengeDay : challengeDayList) { // 참여여부 확인과정 @@ -149,8 +156,10 @@ public List getDashboard(Long challengeId) { // ========== Get Questions API ========== public QuestionsResponseDto getQuestions(Long challengeId) { - List questionList = questionRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException((ErrorCode.ETC_ERROR))); + List questionList = questionRepository.findByChallengeId(challengeId); + if (questionList.isEmpty()) { + throw new CustomException(ErrorCode.QUESTION_NOT_FOUND); + } List basicQuestions = questionList.stream() .filter(question -> question.getKeyword() == null) @@ -182,14 +191,17 @@ public ChallengeInfoResponseDto getInfo(Long challengeId) { .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 챌린지 날짜 정보 가져오기 - List challengeDays = challengeDayRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List challengeDayList = challengeDayRepository.findByChallengeId(challengeId); + + if (challengeDayList.isEmpty()) { + throw new CustomException(ErrorCode.CHALLENGE_DAY_NOT_FOUND); + } return new ChallengeInfoResponseDto( challenge.getName(), challenge.getStartAt(), challenge.getFinishAt(), - challengeDays.stream().map(ChallengeDay::getDay).collect(Collectors.toList()) + challengeDayList.stream().map(ChallengeDay::getDay).collect(Collectors.toList()) ); } @@ -200,8 +212,10 @@ public QuestionsResponseDto putQuestions(Long challengeId, QuestionsRequestDto r .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 질문 리스트 조회 - List questionList = questionRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException((ErrorCode.ETC_ERROR))); + List questionList = questionRepository.findByChallengeId(challengeId); + if (questionList.isEmpty()) { + throw new CustomException(ErrorCode.QUESTION_NOT_FOUND); + } // 3. 베이직 질문 처리 List requestBasicQuestions = requestDto.getBasicQuestions(); @@ -319,8 +333,11 @@ public ChallengeInfoResponseDto putInfo(Long challengeId, ChallengeInfoRequestDt Challenge editedChallenge = challengeRepository.save(challenge); // 3. 챌린지 날짜 정보 조회 - List challengeDays = challengeDayRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List challengeDays = challengeDayRepository.findByChallengeId(challengeId); + + if (challengeDays.isEmpty()) { + throw new CustomException(ErrorCode.CHALLENGE_DAY_NOT_FOUND); + } // 4. 챌린지 날짜 정보 수정 및 저장 // 1) 새로운 날짜가 기존 리스트에 없으면 추가 @@ -345,8 +362,11 @@ public ChallengeInfoResponseDto putInfo(Long challengeId, ChallengeInfoRequestDt } // 5. 변경된 날짜 정보 조회 - List editedChallengeDays = challengeDayRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List editedChallengeDays = challengeDayRepository.findByChallengeId(challengeId); + + if (editedChallengeDays.isEmpty()) { + throw new CustomException(ErrorCode.CHALLENGE_DAY_NOT_FOUND); + } return new ChallengeInfoResponseDto( editedChallenge.getName(), diff --git a/src/main/java/com/writon/admin/domain/service/OrganizationService.java b/src/main/java/com/writon/admin/domain/service/OrganizationService.java index ca0d0a7..008d005 100644 --- a/src/main/java/com/writon/admin/domain/service/OrganizationService.java +++ b/src/main/java/com/writon/admin/domain/service/OrganizationService.java @@ -22,7 +22,6 @@ public class OrganizationService { private final OrganizationRepository organizationRepository; - private final AdminUserRepository adminUserRepository; private final TokenUtil tokenUtil; private final PositionRepository positionRepository; @@ -69,10 +68,12 @@ public CreateOrganizationResponseDto createOrganization( public List getPositions() { Organization organization = tokenUtil.getOrganization(); - List responseDto = positionRepository.findByOrganizationId(organization.getId()) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List positionList = positionRepository.findByOrganizationId(organization.getId()); + if (positionList.isEmpty()) { + throw new CustomException(ErrorCode.POSITION_NOT_FOUND); + } - return responseDto.stream() + return positionList.stream() .map(Position::getName) .toList(); } @@ -103,8 +104,10 @@ public List editPositions(List positionList) { Organization organization = tokenUtil.getOrganization(); // 1. 현재 조직의 모든 Position을 조회 - List existingPositions = positionRepository.findByOrganizationId(organization.getId()) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List existingPositions = positionRepository.findByOrganizationId(organization.getId()); + if (positionList.isEmpty()) { + throw new CustomException(ErrorCode.POSITION_NOT_FOUND); + } // 2. 기존의 position names 리스트를 생성 List existingPositionNames = existingPositions.stream() diff --git a/src/main/java/com/writon/admin/domain/service/ParticipationService.java b/src/main/java/com/writon/admin/domain/service/ParticipationService.java index b6ec313..f6da23e 100644 --- a/src/main/java/com/writon/admin/domain/service/ParticipationService.java +++ b/src/main/java/com/writon/admin/domain/service/ParticipationService.java @@ -39,8 +39,7 @@ public class ParticipationService { // ========== Get Email API ========== public List getEmailList(Long challengeId) { - List emailList = emailRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List emailList = emailRepository.findByChallengeId(challengeId); return emailList.stream().map(Email::getEmail).toList(); } @@ -52,8 +51,7 @@ public List getParticipationInfo(Long challengeId) { .orElseThrow(() -> new CustomException(ErrorCode.CHALLENGE_NOT_FOUND)); // 2. 유저 챌린지 조회 - List userChallengeList = userChallengeRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List userChallengeList = userChallengeRepository.findByChallengeId(challengeId); // 3. 유저 정보 조회 List participationInfoList = new ArrayList<>(); @@ -62,8 +60,8 @@ public List getParticipationInfo(Long challengeId) { Affiliation affiliation = userChallenge.getAffiliation(); User user = affiliation.getUser(); - List userChallenges = userChallengeRepository.findByAffiliationId(affiliation.getId()) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List userChallenges = userChallengeRepository.findByAffiliationId(affiliation.getId()); + String challenges = userChallenges.stream() .map(entity -> entity.getChallenge().getName()) .collect(Collectors.joining(", ")); @@ -123,8 +121,10 @@ public List participate(Long challengeId, List emailList) { emailRepository.save(new Email(email, challenge)); } - List sendedEmailList = emailRepository.findByChallengeId(challengeId) - .orElseThrow(() -> new CustomException(ErrorCode.ETC_ERROR)); + List sendedEmailList = emailRepository.findByChallengeId(challengeId); + if (sendedEmailList.isEmpty()) { + throw new CustomException(ErrorCode.EMAIL_NOT_FOUND); + } return sendedEmailList.stream().map(Email::getEmail).toList(); }