diff --git a/.github/workflows/aws.yml b/.github/workflows/aws.yml index 947a034..f60f712 100644 --- a/.github/workflows/aws.yml +++ b/.github/workflows/aws.yml @@ -123,7 +123,7 @@ jobs: set -e cd /home/ubuntu/stack/docker/app - sudo docker compose down || true + sudo docker compose -f docker-compose-dev.yml down || true # 기존 kindergarten 이미지 전부 삭제 sudo docker images "juhoonlee/kindergarten" -q | xargs -r sudo docker rmi -f diff --git a/src/main/java/com/onebyone/kindergarten/domain/communityComments/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/communityComments/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/communityComments/service/CommunityCommentService.java b/src/main/java/com/onebyone/kindergarten/domain/communityComments/service/CommunityCommentService.java index 7189551..7dcd5dd 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/communityComments/service/CommunityCommentService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/communityComments/service/CommunityCommentService.java @@ -2,6 +2,8 @@ import com.onebyone.kindergarten.domain.communityComments.dto.response.PageCommunityCommentsResponseDTO; import com.onebyone.kindergarten.domain.userBlock.repository.UserBlockRepository; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -42,28 +44,28 @@ public CommentResponseDTO createComment(Long postId, CreateCommentRequestDTO dto // 게시글 조회 (작성자 정보를 포함) CommunityPost post = postRepository.findByIdWithUser(postId) - .orElseThrow(() -> new IllegalArgumentException("게시글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_POST)); CommunityComment parent = null; // 대댓글인 경우 부모 댓글 조회 if (dto.getParentId() != null) { parent = commentRepository.findByIdWithUser(dto.getParentId()) - .orElseThrow(() -> new IllegalArgumentException("원댓글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_PARENT_COMMENT)); // 부모 댓글의 게시글과 요청된 게시글이 일치하는지 확인 if (!parent.getPost().getId().equals(postId)) { - throw new IllegalArgumentException("원댓글의 게시글이 일치하지 않습니다."); + throw new BusinessException(ErrorCodes.PARENT_POST_MISMATCH); } // 이미 대댓글인 경우 대댓글에 대댓글 작성 방지 if (parent.isReply()) { - throw new IllegalArgumentException("대댓글에는 답글을 작성할 수 없습니다."); + throw new BusinessException(ErrorCodes.REPLY_TO_REPLY_NOT_ALLOWED); } // 삭제된 댓글에는 대댓글 작성 불가 if (parent.getDeletedAt() != null) { - throw new IllegalArgumentException("삭제된 댓글에는 답글을 작성할 수 없습니다."); + throw new BusinessException(ErrorCodes.REPLY_TO_DELETED_COMMENT_NOT_ALLOWED); } } @@ -143,11 +145,11 @@ public PageCommunityCommentsResponseDTO getWroteMyCommunityComments(Long userId, public void deleteComment(Long commentId, String email) { // 댓글 조회 (작성자 정보 포함) CommunityComment comment = commentRepository.findByIdWithUser(commentId) - .orElseThrow(() -> new IllegalArgumentException("댓글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_COMMENT)); // 작성자 확인 if (!comment.getUser().getEmail().equals(email)) { - throw new com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.UnauthorizedDeleteException(); + throw new BusinessException(ErrorCodes.UNAUTHORIZED_DELETE); } Long postId = comment.getPost().getId(); diff --git a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/exception/PostNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/communityPosts/exception/PostNotFoundException.java deleted file mode 100644 index 3696f34..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/exception/PostNotFoundException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.onebyone.kindergarten.domain.communityPosts.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.NOT_FOUND) // 404 상태 코드 반환 -public class PostNotFoundException extends RuntimeException { - public PostNotFoundException(String message) { - super(message); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityLikeService.java b/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityLikeService.java index 9b1d39a..88ec487 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityLikeService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityLikeService.java @@ -3,12 +3,13 @@ import com.onebyone.kindergarten.domain.communityPosts.dto.response.CommunityLikeResponseDTO; import com.onebyone.kindergarten.domain.communityPosts.entity.CommunityLike; import com.onebyone.kindergarten.domain.communityPosts.entity.CommunityPost; -import com.onebyone.kindergarten.domain.communityPosts.exception.PostNotFoundException; import com.onebyone.kindergarten.domain.communityPosts.repository.CommunityLikeRepository; import com.onebyone.kindergarten.domain.communityPosts.repository.CommunityRepository; import com.onebyone.kindergarten.domain.pushNotification.service.NotificationTemplateService; import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.service.UserService; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -51,7 +52,7 @@ public CommunityLikeResponseDTO toggleLike(Long postId, String email) { .orElseGet(() -> { // 게시글 존재 여부 확인 및 좋아요 추가 CommunityPost post = communityRepository.findById(postId) - .orElseThrow(() -> new PostNotFoundException("게시글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_POST)); CommunityLike newLike = CommunityLike.builder() .user(user) diff --git a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityService.java b/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityService.java index f6c144d..54b8ac6 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/communityPosts/service/CommunityService.java @@ -5,7 +5,6 @@ import com.onebyone.kindergarten.domain.communityPosts.dto.response.CommunityPostResponseDTO; import com.onebyone.kindergarten.domain.communityPosts.entity.CommunityCategory; import com.onebyone.kindergarten.domain.communityPosts.entity.CommunityPost; -import com.onebyone.kindergarten.domain.communityPosts.exception.PostNotFoundException; import com.onebyone.kindergarten.domain.communityPosts.mapper.CommunityPostMapper; import com.onebyone.kindergarten.domain.communityPosts.repository.CommunityCategoryRepository; import com.onebyone.kindergarten.domain.communityPosts.repository.CommunityRepository; @@ -13,6 +12,8 @@ import com.onebyone.kindergarten.domain.user.service.UserService; import com.onebyone.kindergarten.domain.userBlock.repository.UserBlockRepository; import com.onebyone.kindergarten.global.config.CacheConfig; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -84,7 +85,7 @@ public CommunityPostResponseDTO getPost(Long id) { // 게시글 조회 (User 정보 포함) CommunityPost post = communityRepository.findByIdWithUser(id) - .orElseThrow(() -> new PostNotFoundException("게시글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_POST)); // 게시글이 존재할 때만 조회수 증가 communityRepository.increaseViewCount(id); @@ -111,11 +112,11 @@ public void deletePost(Long postId, String email) { // 게시글 조회 (작성자 정보 포함) CommunityPost post = communityRepository.findByIdWithUser(postId) - .orElseThrow(() -> new PostNotFoundException("게시글을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_POST)); // 작성자 확인 if (!post.getUser().getEmail().equals(email)) { - throw new com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.UnauthorizedDeleteException(); + throw new BusinessException(ErrorCodes.UNAUTHORIZED_DELETE); } // 게시글 소프트 삭제 (deletedAt 설정) diff --git a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminReadException.java b/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminReadException.java deleted file mode 100644 index ead8753..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminReadException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.onebyone.kindergarten.domain.inquires.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.FORBIDDEN) -public class InquiryNotAdminReadException extends RuntimeException { - public InquiryNotAdminReadException(String message) { - super(message); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminWriteException.java b/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminWriteException.java deleted file mode 100644 index e735f33..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotAdminWriteException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.onebyone.kindergarten.domain.inquires.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.FORBIDDEN) -public class InquiryNotAdminWriteException extends RuntimeException { - public InquiryNotAdminWriteException(String message) { - super(message); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotFoundException.java deleted file mode 100644 index 4b1c494..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/inquires/exception/InquiryNotFoundException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.onebyone.kindergarten.domain.inquires.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.NOT_FOUND) -public class InquiryNotFoundException extends RuntimeException { - public InquiryNotFoundException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/inquires/service/InquiryService.java b/src/main/java/com/onebyone/kindergarten/domain/inquires/service/InquiryService.java index 91c4279..24ede36 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/inquires/service/InquiryService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/inquires/service/InquiryService.java @@ -5,14 +5,13 @@ import com.onebyone.kindergarten.domain.inquires.dto.response.InquiryResponseDTO; import com.onebyone.kindergarten.domain.inquires.entity.Inquiry; import com.onebyone.kindergarten.domain.inquires.enums.InquiryStatus; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotAdminReadException; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotAdminWriteException; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotFoundException; import com.onebyone.kindergarten.domain.inquires.repository.InquiryRepository; import com.onebyone.kindergarten.domain.pushNotification.service.NotificationTemplateService; import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.enums.UserRole; import com.onebyone.kindergarten.domain.user.service.UserService; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -54,11 +53,11 @@ public InquiryResponseDTO getInquiry(Long id, String email) { // 문의 조회 Inquiry inquiry = inquiryRepository.findByIdWithUser(id) - .orElseThrow(() -> new InquiryNotFoundException("문의를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INQUIRY)); // 본인 및 관리자 권한 체크 if (!inquiry.getUser().getId().equals(user.getId()) && !user.getRole().equals(UserRole.ADMIN)) { - throw new InquiryNotAdminReadException("본인 문의만 조회할 수 있습니다."); + throw new BusinessException(ErrorCodes.INQUIRY_NOT_ADMIN_CANNOT_READ); } return InquiryResponseDTO.fromEntity(inquiry); @@ -82,7 +81,7 @@ public Page getAllInquiries(String email, Pageable pageable) // 관리자 권한 체크 if (!user.getRole().equals(UserRole.ADMIN)) { - throw new InquiryNotAdminReadException("관리자만 모든 문의를 조회할 수 있습니다."); + throw new BusinessException(ErrorCodes.INQUIRY_NOT_ADMIN_CANNOT_READ); } return inquiryRepository.findAllDtosOrderByStatusAndCreatedAt(pageable); @@ -96,7 +95,7 @@ public Page getInquiriesByStatus(InquiryStatus status, Strin // 관리자 권한 체크 if (!user.getRole().equals(UserRole.ADMIN)) { - throw new InquiryNotAdminReadException("관리자만 상태별 문의를 조회할 수 있습니다."); + throw new BusinessException(ErrorCodes.INQUIRY_NOT_ADMIN_CANNOT_READ); } return inquiryRepository.findDtosByStatus(status, pageable); @@ -111,12 +110,12 @@ public InquiryResponseDTO answerInquiry(Long id, AnswerInquiryRequestDTO dto, St // 관리자 권한 체크 if (!user.getRole().equals(UserRole.ADMIN)) { - throw new InquiryNotAdminWriteException("관리자만 문의에 답변할 수 있습니다."); + throw new BusinessException(ErrorCodes.INQUIRY_NOT_ADMIN_CANNOT_WRITE); } // 문의 조회 Inquiry inquiry = inquiryRepository.findByIdWithUser(id) - .orElseThrow(() -> new InquiryNotFoundException("문의를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INQUIRY)); // 답변 등록 inquiry.answerInquiry(dto.getAnswer()); @@ -140,12 +139,12 @@ public InquiryResponseDTO closeInquiry(Long id, String email) { // 관리자 권한 체크 if (!user.getRole().equals(UserRole.ADMIN)) { - throw new InquiryNotAdminWriteException("관리자만 문의를 마감할 수 있습니다."); + throw new BusinessException(ErrorCodes.INQUIRY_NOT_ADMIN_CANNOT_READ); } // 문의 조회 Inquiry inquiry = inquiryRepository.findById(id) - .orElseThrow(() -> new InquiryNotFoundException("문의를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INQUIRY)); // 문의 마감 inquiry.closeInquiry(); diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/AlreadyExistInternshipReviewException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/AlreadyExistInternshipReviewException.java deleted file mode 100644 index 9e625b9..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/AlreadyExistInternshipReviewException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception; - -import lombok.Getter; - -@Getter -public class AlreadyExistInternshipReviewException extends RuntimeException { - private String value; - - public AlreadyExistInternshipReviewException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/NotFoundInternshipReviewException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/NotFoundInternshipReviewException.java deleted file mode 100644 index f1e6fe1..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/exception/NotFoundInternshipReviewException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception; - -import lombok.Getter; - -@Getter -public class NotFoundInternshipReviewException extends RuntimeException { - private String value; - - public NotFoundInternshipReviewException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/service/KindergartenInternshipReviewService.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/service/KindergartenInternshipReviewService.java index 91049ad..8d178db 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/service/KindergartenInternshipReviewService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/kindergartenInternshipReview/service/KindergartenInternshipReviewService.java @@ -7,8 +7,6 @@ import com.onebyone.kindergarten.domain.kindergartenInternshipReview.entity.KindergartenInternshipReview; import com.onebyone.kindergarten.domain.kindergartenInternshipReview.entity.KindergartenInternshipReviewLikeHistory; import com.onebyone.kindergarten.domain.kindergartenInternshipReview.enums.InternshipReviewStarRatingType; -import com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception.AlreadyExistInternshipReviewException; -import com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception.NotFoundInternshipReviewException; import com.onebyone.kindergarten.domain.kindergartenInternshipReview.repository.KindergartenInternshipReviewLikeHistoryRepository; import com.onebyone.kindergarten.domain.kindergartenInternshipReview.repository.KindergartenInternshipReviewRepository; import com.onebyone.kindergarten.domain.kindergatens.entity.Kindergarten; @@ -16,8 +14,8 @@ import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.service.UserService; import com.onebyone.kindergarten.global.enums.ReviewStatus; -import com.onebyone.kindergarten.global.exception.IllegalArgumentStarRatingException; -import com.onebyone.kindergarten.global.exception.IncorrectUserException; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.data.domain.Page; @@ -45,7 +43,7 @@ public Kindergarten createInternshipReview(CreateInternshipReviewRequestDTO requ boolean exists = kindergartenInternshipReviewRepository.existsByUserAndKindergarten(user, kindergarten); if (exists) { - throw new AlreadyExistInternshipReviewException("이미 등록된 실습 리뷰가 존재합니다."); + throw new BusinessException(ErrorCodes.ALREADY_EXIST_INTERNSHIP_REVIEW); } KindergartenInternshipReview review = KindergartenInternshipReview.builder() @@ -76,10 +74,10 @@ public Kindergarten modifyInternshipReview(ModifyInternshipReviewRequestDTO requ KindergartenInternshipReview review = kindergartenInternshipReviewRepository .findById(request.getInternshipReviewId()) - .orElseThrow(() -> new NotFoundInternshipReviewException("존재하지 않는 실습 리뷰입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INTERNSHIP_REVIEW)); if (!review.getUser().equals(user)) { - throw new IncorrectUserException("작성자가 일치하지 않습니다."); + throw new BusinessException(ErrorCodes.INCORRECT_USER_EXCEPTION); } review.updateReview(request); @@ -92,7 +90,7 @@ public void likeInternshipReview(long reviewId, String email) { User user = userService.getUserByEmail(email); KindergartenInternshipReview review = kindergartenInternshipReviewRepository.findById(reviewId) - .orElseThrow(() -> new NotFoundInternshipReviewException("존재하지 않는 실습 리뷰입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_INTERNSHIP_REVIEW)); Optional existingLike = kindergartenInternshipReviewLikeHistoryRepository.findByUserAndInternshipReview(user, review); @@ -114,7 +112,7 @@ public void likeInternshipReview(long reviewId, String email) { public InternshipReviewPagedResponseDTO getReviews(Long kindergartenId, int page, int size, InternshipReviewPagedResponseDTO.SortType sortType, InternshipReviewStarRatingType internshipReviewStarRatingType, int starRating) { if (internshipReviewStarRatingType != InternshipReviewStarRatingType.ALL && starRating < 1 || starRating > 5) { - throw new IllegalArgumentStarRatingException("starRating은 1부터 5 사이의 값이어야 합니다."); + throw new BusinessException(ErrorCodes.ILLEGAL_ARGUMENT_STAR_RATING_EXCEPTION); } Pageable pageable; diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/KindergartenNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/KindergartenNotFoundException.java deleted file mode 100644 index 104e2a8..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/KindergartenNotFoundException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception; - -import lombok.Getter; - -@Getter -public class KindergartenNotFoundException extends RuntimeException { - public KindergartenNotFoundException() { - super("유치원을 찾을 수 없습니다."); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/UnauthorizedDeleteException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/UnauthorizedDeleteException.java deleted file mode 100644 index 206140d..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/UnauthorizedDeleteException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception; - -import lombok.Getter; - -@Getter -public class UnauthorizedDeleteException extends RuntimeException { - public UnauthorizedDeleteException() { - super("삭제 권한이 없습니다."); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/WorkHistoryNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/WorkHistoryNotFoundException.java deleted file mode 100644 index 6a7bfe6..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/exception/WorkHistoryNotFoundException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception; - -import lombok.Getter; - -@Getter -public class WorkHistoryNotFoundException extends RuntimeException { - public WorkHistoryNotFoundException() { - super("이력을 찾을 수 없습니다."); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/service/KindergartenWorkHistoryService.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/service/KindergartenWorkHistoryService.java index 31c246a..388c4bb 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/service/KindergartenWorkHistoryService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkHistories/service/KindergartenWorkHistoryService.java @@ -8,6 +8,8 @@ import com.onebyone.kindergarten.domain.kindergatens.repository.KindergartenRepository; import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.service.UserService; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,11 +17,6 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.List; -import java.util.stream.Collectors; - -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.KindergartenNotFoundException; -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.WorkHistoryNotFoundException; -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.UnauthorizedDeleteException; @Service @RequiredArgsConstructor @@ -45,7 +42,7 @@ public KindergartenWorkHistoryResponse addCertification(String email, Kindergart // 유치원 이름으로 유치원 조회 Kindergarten kindergarten = kindergartenRepository.findByName(request.getKindergartenName()) - .orElseThrow(KindergartenNotFoundException::new); + .orElseThrow(() -> new BusinessException(ErrorCodes.KINDERGARTEN_NOT_FOUND)); // 사용자 조회 User user = userService.getUserByEmail(email); @@ -82,14 +79,14 @@ public void deleteCertification(String email, Long historyId) { // 유치원 근무 이력 조회 KindergartenWorkHistory workHistory = workHistoryRepository.findByIdWithKindergarten(historyId) - .orElseThrow(WorkHistoryNotFoundException::new); + .orElseThrow(() -> new BusinessException(ErrorCodes.WORK_HISTORY_NOT_FOUND)); // 사용자 조회 User user = userService.getUserByEmail(email); // 유치원 근무 이력 소유자 확인 if (!workHistory.getUser().equals(user)) { - throw new UnauthorizedDeleteException(); + throw new BusinessException(ErrorCodes.UNAUTHORIZED_DELETE); } // 유치원 경력 개월 수 업데이트 diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/AlreadyExistWorkReviewException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/AlreadyExistWorkReviewException.java deleted file mode 100644 index c3de2f7..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/AlreadyExistWorkReviewException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenWorkReview.exception; - -public class AlreadyExistWorkReviewException extends RuntimeException { - private String value; - - public AlreadyExistWorkReviewException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/NotFoundWorkReviewException.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/NotFoundWorkReviewException.java deleted file mode 100644 index 62f4c81..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/exception/NotFoundWorkReviewException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.domain.kindergartenWorkReview.exception; - -public class NotFoundWorkReviewException extends RuntimeException { - private String value; - - public NotFoundWorkReviewException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/service/KindergartenWorkReviewService.java b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/service/KindergartenWorkReviewService.java index daab769..1cb33b0 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/service/KindergartenWorkReviewService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/kindergartenWorkReview/service/KindergartenWorkReviewService.java @@ -7,8 +7,6 @@ import com.onebyone.kindergarten.domain.kindergartenWorkReview.entity.KindergartenWorkReview; import com.onebyone.kindergarten.domain.kindergartenWorkReview.entity.KindergartenWorkReviewLikeHistory; import com.onebyone.kindergarten.domain.kindergartenWorkReview.enums.WorkReviewStarRatingType; -import com.onebyone.kindergarten.domain.kindergartenWorkReview.exception.AlreadyExistWorkReviewException; -import com.onebyone.kindergarten.domain.kindergartenWorkReview.exception.NotFoundWorkReviewException; import com.onebyone.kindergarten.domain.kindergartenWorkReview.repository.KindergartenWorkReviewLikeHistoryRepository; import com.onebyone.kindergarten.domain.kindergartenWorkReview.repository.KindergartenWorkReviewRepository; import com.onebyone.kindergarten.domain.kindergatens.entity.Kindergarten; @@ -17,7 +15,8 @@ import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.service.UserService; import com.onebyone.kindergarten.global.enums.ReviewStatus; -import com.onebyone.kindergarten.global.exception.IllegalArgumentStarRatingException; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -45,7 +44,7 @@ public Kindergarten createWorkReview(CreateWorkReviewRequestDTO request, String boolean exists = workReviewRepository.existsByUserAndKindergarten(user, kindergarten); if (exists) { - throw new AlreadyExistWorkReviewException("이미 등록된 근무 리뷰가 존재합니다."); + throw new BusinessException(ErrorCodes.ALREADY_EXIST_WORK_REVIEW); } KindergartenWorkReview review = KindergartenWorkReview.builder() @@ -79,10 +78,10 @@ public Kindergarten modifyWorkReview(ModifyWorkReviewRequestDTO request, String Kindergarten kindergarten = kindergartenService.getKindergartenById(request.getKindergartenId()); KindergartenWorkReview review = workReviewRepository.findById(request.getWorkReviewId()) - .orElseThrow(() -> new NotFoundWorkReviewException("존재하지 않는 근무 리뷰입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_WORK_REVIEW)); if (!review.getUser().equals(user)) { - throw new SecurityException("본인의 리뷰만 수정할 수 있습니다."); + throw new BusinessException(ErrorCodes.REVIEW_EDIT_NOT_OWNER); } review.updateReview(request); @@ -94,7 +93,7 @@ public void likeWorkReview(long reviewId, String email) { User user = userService.getUserByEmail(email); KindergartenWorkReview review = workReviewRepository.findById(reviewId) - .orElseThrow(() -> new NotFoundWorkReviewException("존재하지 않는 근무 리뷰입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_WORK_REVIEW)); Optional existingLike = workReviewLikeHistoryRepository.findByUserAndWorkReview(user, review); @@ -128,7 +127,7 @@ public void likeWorkReview(long reviewId, String email) { public WorkReviewPagedResponseDTO getReviews(Long kindergartenId, int page, int size, WorkReviewPagedResponseDTO.SortType sortType, WorkReviewStarRatingType workReviewStarRatingType, int starRating) { if (workReviewStarRatingType != WorkReviewStarRatingType.ALL && starRating < 1 || starRating > 5) { - throw new IllegalArgumentStarRatingException("starRating은 1부터 5 사이의 값이어야 합니다."); + throw new BusinessException(ErrorCodes.ILLEGAL_ARGUMENT_STAR_RATING_EXCEPTION); } Pageable pageable; diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergatens/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/kindergatens/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/kindergatens/service/KindergartenService.java b/src/main/java/com/onebyone/kindergarten/domain/kindergatens/service/KindergartenService.java index 69b0b5c..9f0dc52 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/kindergatens/service/KindergartenService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/kindergatens/service/KindergartenService.java @@ -8,7 +8,8 @@ import com.onebyone.kindergarten.domain.kindergatens.repository.KindergartenInternshipReviewAggregateRepository; import com.onebyone.kindergarten.domain.kindergatens.repository.KindergartenRepository; import com.onebyone.kindergarten.domain.kindergatens.repository.KindergartenWorkReviewAggregateRepository; -import com.onebyone.kindergarten.global.exception.EntityNotFoundException; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -83,7 +84,7 @@ public Page searchKindergartens(KindergartenSearchDTO s /// 유치원 상세 조회 public KindergartenResponseDTO findById(Long id) { Kindergarten kindergarten = kindergartenRepository.findWithReviewsById(id) - .orElseThrow(() -> new EntityNotFoundException("유치원을 찾을 수 없습니다. ID: " + id)); + .orElseThrow(() -> new BusinessException(ErrorCodes.ENTITY_NOT_FOUND_EXCEPTION)); return KindergartenResponseDTO.from(kindergarten); } @@ -102,7 +103,7 @@ public List getNearbyKindergarten( public Kindergarten getKindergartenById(Long id) { return kindergartenRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("유치원을 찾을 수 없습니다. ID: " + id)); + .orElseThrow(() -> new BusinessException(ErrorCodes.ENTITY_NOT_FOUND_EXCEPTION)); } /// DTO -> Entity 변환 @@ -130,6 +131,5 @@ private Kindergarten convertToEntity(KindergartenDTO dto) { public KindergartenSimpleDTO getSimpleKindergarten(Long id) { return kindergartenRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("유치원을 찾을 수 없습니다. ID: " + id)).toSimpleDTO(); - } + .orElseThrow(() -> new BusinessException(ErrorCodes.ENTITY_NOT_FOUND_EXCEPTION)).toSimpleDTO();} } diff --git a/src/main/java/com/onebyone/kindergarten/domain/notice/exception/NoticeNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/notice/exception/NoticeNotFoundException.java deleted file mode 100644 index 60ed38f..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/notice/exception/NoticeNotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.notice.exception; - -public class NoticeNotFoundException extends RuntimeException { - public NoticeNotFoundException() { - super("존재하지 않는 공지사항입니다."); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/notice/service/NoticeService.java b/src/main/java/com/onebyone/kindergarten/domain/notice/service/NoticeService.java index 653865c..831a552 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/notice/service/NoticeService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/notice/service/NoticeService.java @@ -3,8 +3,9 @@ import com.onebyone.kindergarten.domain.notice.dto.request.NoticeCreateRequestDTO; import com.onebyone.kindergarten.domain.notice.dto.response.NoticeResponseDTO; import com.onebyone.kindergarten.domain.notice.entity.Notice; -import com.onebyone.kindergarten.domain.notice.exception.NoticeNotFoundException; import com.onebyone.kindergarten.domain.notice.repository.NoticeRepository; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,7 +54,7 @@ public NoticeResponseDTO togglePublicStatus(Long noticeId) { // 공지사항 조회 Notice notice = noticeRepository.findById(noticeId) - .orElseThrow(NoticeNotFoundException::new); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_NOTICE)); // 공개 여부 토글 notice.togglePublicStatus(); diff --git a/src/main/java/com/onebyone/kindergarten/domain/pushNotification/exception/NotificationException.java b/src/main/java/com/onebyone/kindergarten/domain/pushNotification/exception/NotificationException.java deleted file mode 100644 index fc6b4bf..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/pushNotification/exception/NotificationException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.onebyone.kindergarten.domain.pushNotification.exception; - -import lombok.Getter; - -@Getter -public class NotificationException extends RuntimeException { - private String message; - - public NotificationException(String message) { - super(message); - this.message = message; - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/pushNotification/service/PushNotificationService.java b/src/main/java/com/onebyone/kindergarten/domain/pushNotification/service/PushNotificationService.java index 443bd18..0950da3 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/pushNotification/service/PushNotificationService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/pushNotification/service/PushNotificationService.java @@ -5,10 +5,11 @@ import com.onebyone.kindergarten.domain.pushNotification.dto.PushNotificationRequestDTO; import com.onebyone.kindergarten.domain.pushNotification.dto.PushNotificationResponseDTO; import com.onebyone.kindergarten.domain.pushNotification.entity.PushNotification; -import com.onebyone.kindergarten.domain.pushNotification.exception.NotificationException; import com.onebyone.kindergarten.domain.pushNotification.repository.PushNotificationRepository; import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.repository.UserRepository; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.userdetails.UserDetails; @@ -58,7 +59,7 @@ private boolean shouldSendNotification(User user, NotificationType type) { public void savePushNotification(PushNotificationRequestDTO requestDTO) { // 사용자 조회 User user = userRepository.findById(requestDTO.getUserId()) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 알림 설정 확인 if (!shouldSendNotification(user, requestDTO.getType())) { @@ -250,7 +251,7 @@ public List getUserNotifications(Long userId) { // 사용자 조회 User user = userRepository.findById(userId) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 모든 알림 조회 return pushNotificationRepository.findByUserOrderByCreatedAtDesc(user) @@ -265,7 +266,7 @@ public List getUserNotificationByUserDetails(UserDe // 사용자 조회 User user = userRepository.findByEmailAndDeletedAtIsNull(userDetails.getUsername()) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 모든 알림 조회 return pushNotificationRepository.findByUserOrderByCreatedAtDesc(user) @@ -281,7 +282,7 @@ public List getUnreadNotificationsByUserDetails(Use // 사용자 조회 User user = userRepository.findByEmailAndDeletedAtIsNull(userDetails.getUsername()) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 읽지 않은 알림 조회 return pushNotificationRepository.findByUserAndIsReadFalseOrderByCreatedAtDesc(user) @@ -296,7 +297,7 @@ public void markAsRead(Long notificationId) { // 알림 조회 PushNotification notification = pushNotificationRepository.findById(notificationId) - .orElseThrow(() -> new NotificationException("알림을 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 읽음 처리 notification.markAsRead(); @@ -309,7 +310,7 @@ public void markAllAsRead(UserDetails userDetails) { // 사용자 조회 User user = userRepository.findByEmailAndDeletedAtIsNull(userDetails.getUsername()) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 모든 알림 읽음 처리 pushNotificationRepository.markAllAsRead(user); @@ -321,7 +322,7 @@ public Long countUnreadNotifications(UserDetails userDetails) { // 사용자 조회 User user = userRepository.findByEmailAndDeletedAtIsNull(userDetails.getUsername()) - .orElseThrow(() -> new NotificationException("사용자를 찾을 수 없습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_USER)); // 읽지 않은 알림 개수 조회 return pushNotificationRepository.countByUserAndIsReadFalse(user); diff --git a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportStatusException.java b/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportStatusException.java deleted file mode 100644 index bd01399..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportStatusException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.reports.exception; - -public class InvalidReportStatusException extends RuntimeException { - public InvalidReportStatusException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportTargetException.java b/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportTargetException.java deleted file mode 100644 index b65ea51..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/InvalidReportTargetException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.reports.exception; - -public class InvalidReportTargetException extends RuntimeException { - public InvalidReportTargetException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/ReportNotFoundException.java b/src/main/java/com/onebyone/kindergarten/domain/reports/exception/ReportNotFoundException.java deleted file mode 100644 index d9549e0..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/reports/exception/ReportNotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.reports.exception; - -public class ReportNotFoundException extends RuntimeException { - public ReportNotFoundException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/reports/service/ReportService.java b/src/main/java/com/onebyone/kindergarten/domain/reports/service/ReportService.java index 4a319dd..3cb1d6c 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/reports/service/ReportService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/reports/service/ReportService.java @@ -13,13 +13,13 @@ import com.onebyone.kindergarten.domain.user.service.UserService; import com.onebyone.kindergarten.global.enums.ReportStatus; import com.onebyone.kindergarten.domain.reports.dto.request.ReportSearchDTO; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.onebyone.kindergarten.domain.reports.exception.ReportNotFoundException; -import com.onebyone.kindergarten.domain.reports.exception.InvalidReportTargetException; import java.util.concurrent.CompletableFuture; @@ -71,7 +71,7 @@ public ReportResponseDTO processReport(Long reportId, ReportStatus status) { // 신고 존재 여부 확인 Report report = reportRepository.findByIdWithReporter(reportId) - .orElseThrow(() -> new ReportNotFoundException("존재하지 않는 신고입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_REPORT)); // 신고 상태 업데이트 report.updateStatus(status); @@ -101,7 +101,7 @@ public ReportResponseDTO getReportDetail(Long reportId) { // 신고 상세 조회 return reportRepository.findByIdWithReporter(reportId) .map(ReportResponseDTO::fromEntity) - .orElseThrow(() -> new ReportNotFoundException("존재하지 않는 신고입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_REPORT)); } /// 신고 대상 상태 업데이트 @@ -109,18 +109,18 @@ private void _updateTargetStatus(ReportTargetType targetType, Long targetId, Rep switch (targetType) { case POST -> { CommunityPost post = communityRepository.findById(targetId) - .orElseThrow(() -> new InvalidReportTargetException("존재하지 않는 게시글입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.INVALID_REPORT_POST_TARGET)); post.updateStatus(status); } case COMMENT -> { CommunityComment comment = commentRepository.findById(targetId) - .orElseThrow(() -> new InvalidReportTargetException("존재하지 않는 댓글입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.INVALID_REPORT_COMMENT_TARGET)); comment.updateStatus(status); } case REVIEW -> { - throw new InvalidReportTargetException("리뷰 처리는 아직 구현되지 않았습니다."); + throw new BusinessException(ErrorCodes.REVIEW_REPORT_NOT_IMPLEMENTED); } - default -> throw new InvalidReportTargetException("지원하지 않는 신고 대상 타입입니다."); + default -> throw new BusinessException(ErrorCodes.INVALID_REPORT_TARGET_TYPE); } } @@ -128,10 +128,10 @@ private void _updateTargetStatus(ReportTargetType targetType, Long targetId, Rep private void validateReportTarget(ReportTargetType targetType, Long targetId) { switch (targetType) { case POST -> communityRepository.findById(targetId) - .orElseThrow(() -> new InvalidReportTargetException("존재하지 않는 게시글입니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.INVALID_REPORT_POST_TARGET)); case COMMENT -> commentRepository.findById(targetId) - .orElseThrow(() -> new InvalidReportTargetException("존재하지 않는 댓글입니다.")); - case REVIEW -> throw new InvalidReportTargetException("리뷰 처리는 아직 구현되지 않았습니다."); + .orElseThrow(() -> new BusinessException(ErrorCodes.INVALID_REPORT_COMMENT_TARGET)); + case REVIEW -> throw new BusinessException(ErrorCodes.REVIEW_REPORT_NOT_IMPLEMENTED); } } } diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/controller/SampleController.java b/src/main/java/com/onebyone/kindergarten/domain/sample/controller/SampleController.java deleted file mode 100644 index 026ac19..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/sample/controller/SampleController.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.onebyone.kindergarten.domain.sample.controller; - -import com.onebyone.kindergarten.domain.sample.service.SampleService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Tag(name = "Sample API", description = "샘플 API") -@RestController -@RequestMapping("/sample/v2") -@RequiredArgsConstructor -public class SampleController{ - private final SampleService sampleService; - - @Operation(summary = "예시-01", description = "예시입니다.") - @GetMapping("/sample") - public void sample() { - sampleService.getSample(); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/dto/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/sample/dto/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/entity/Sample.java b/src/main/java/com/onebyone/kindergarten/domain/sample/entity/Sample.java deleted file mode 100644 index db95832..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/sample/entity/Sample.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.onebyone.kindergarten.domain.sample.entity; - -import com.onebyone.kindergarten.global.common.BaseEntity; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Table(name = "sample") -@Entity -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Sample extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "participant_id") - private Long participantId; - - @Column(name = "phone_number") - private String reason; -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/sample/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/exception/SampleException.java b/src/main/java/com/onebyone/kindergarten/domain/sample/exception/SampleException.java deleted file mode 100644 index 5df8f72..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/sample/exception/SampleException.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.onebyone.kindergarten.domain.sample.exception; - -import lombok.Getter; - -@Getter -public class SampleException extends RuntimeException { - private String value; - - public SampleException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/repository/SampleRepository.java b/src/main/java/com/onebyone/kindergarten/domain/sample/repository/SampleRepository.java deleted file mode 100644 index b0cc788..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/sample/repository/SampleRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.onebyone.kindergarten.domain.sample.repository; - -import com.onebyone.kindergarten.domain.sample.entity.Sample; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface SampleRepository extends JpaRepository {} diff --git a/src/main/java/com/onebyone/kindergarten/domain/sample/service/SampleService.java b/src/main/java/com/onebyone/kindergarten/domain/sample/service/SampleService.java deleted file mode 100644 index e291736..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/sample/service/SampleService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.onebyone.kindergarten.domain.sample.service; - -import com.onebyone.kindergarten.domain.sample.exception.SampleException; -import com.onebyone.kindergarten.domain.sample.repository.SampleRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class SampleService { - private final SampleRepository sampleRepository; - - public void getSample() { - throw new SampleException("sample"); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/termAgreementHistory/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/termAgreementHistory/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/controller/AdminUserController.java b/src/main/java/com/onebyone/kindergarten/domain/user/controller/AdminUserController.java new file mode 100644 index 0000000..e84d285 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/domain/user/controller/AdminUserController.java @@ -0,0 +1,52 @@ +package com.onebyone.kindergarten.domain.user.controller; + +import com.onebyone.kindergarten.domain.user.dto.request.UserSearchDTO; +import com.onebyone.kindergarten.domain.user.dto.response.AdminUserResponseDTO; +import com.onebyone.kindergarten.domain.user.service.UserService; +import com.onebyone.kindergarten.global.common.PageResponseDTO; +import com.onebyone.kindergarten.global.common.ResponseDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/admin/users") +@Tag(name = "유저 관리", description = "유저 관리 API (관리자용)") +@RequiredArgsConstructor +public class AdminUserController { + + private final UserService userService; + + @GetMapping + @Operation(summary = "전체 유저 목록 조회", description = "모든 유저 목록 리스트 조회") + public PageResponseDTO getAllUsers( + @PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable + ) { + Page users = userService.getAllUsers(pageable); + return new PageResponseDTO<>(users); + } + + @GetMapping("/search") + @Operation(summary = "유저 검색", description = "조건부 유저 검색") + public PageResponseDTO searchUsers( + UserSearchDTO searchDTO, + @PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable + ) { + Page users = userService.searchUsers(searchDTO, pageable); + return new PageResponseDTO<>(users); + } + + @GetMapping("/{userId}") + @Operation(summary = "유저 상세 조회", description = "특정 유저 상세 정보 조회") + public ResponseDto getUserDetail( + @PathVariable Long userId + ) { + AdminUserResponseDTO user = userService.getUserById(userId); + return ResponseDto.success(user); + } +} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/controller/UserApiController.java b/src/main/java/com/onebyone/kindergarten/domain/user/controller/UserApiController.java index 8d20858..d4fa663 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/user/controller/UserApiController.java +++ b/src/main/java/com/onebyone/kindergarten/domain/user/controller/UserApiController.java @@ -14,8 +14,9 @@ import com.onebyone.kindergarten.domain.user.dto.response.UpdateHomeShortcutsResponseDTO; import com.onebyone.kindergarten.domain.user.service.UserService; import com.onebyone.kindergarten.global.common.ResponseDto; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import com.onebyone.kindergarten.global.jwt.JwtProvider; -import com.onebyone.kindergarten.global.jwt.exception.InvalidTokenException; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; @@ -92,7 +93,7 @@ public ReIssueResponseDTO reissue( String authHeader = request.getHeader("Authorization"); if (authHeader == null || !authHeader.startsWith("Bearer ")) { - throw new InvalidTokenException("RefreshToken이 존재하지 않거나 형식이 잘못되었습니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_ILLEGAL); } String refreshToken = authHeader.substring(7); diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/dto/request/UserSearchDTO.java b/src/main/java/com/onebyone/kindergarten/domain/user/dto/request/UserSearchDTO.java new file mode 100644 index 0000000..7063288 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/domain/user/dto/request/UserSearchDTO.java @@ -0,0 +1,22 @@ +package com.onebyone.kindergarten.domain.user.dto.request; + +import com.onebyone.kindergarten.domain.user.entity.UserProvider; +import com.onebyone.kindergarten.domain.user.enums.UserRole; +import com.onebyone.kindergarten.domain.user.enums.UserStatus; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UserSearchDTO { + private String email; + private String nickname; + private UserRole role; + private UserProvider provider; + private UserStatus status; + private String kindergartenName; + private Boolean hasWrittenReview; + private Boolean isRestoredUser; +} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/dto/response/AdminUserResponseDTO.java b/src/main/java/com/onebyone/kindergarten/domain/user/dto/response/AdminUserResponseDTO.java new file mode 100644 index 0000000..7813611 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/domain/user/dto/response/AdminUserResponseDTO.java @@ -0,0 +1,59 @@ +package com.onebyone.kindergarten.domain.user.dto.response; + +import com.onebyone.kindergarten.domain.user.entity.User; +import com.onebyone.kindergarten.domain.user.entity.UserProvider; +import com.onebyone.kindergarten.domain.user.enums.UserRole; +import com.onebyone.kindergarten.domain.user.enums.UserStatus; +import com.onebyone.kindergarten.domain.user.enums.NotificationSetting; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AdminUserResponseDTO { + private Long id; + private String email; + private String nickname; + private UserRole role; + private UserProvider provider; + private UserStatus status; + private String profileImageUrl; + private String career; + private String kindergartenName; + private LocalDateTime createdAt; + private LocalDateTime deletedAt; + private LocalDateTime previousDeletedAt; + private boolean isRestoredUser; + private boolean hasWrittenReview; + private boolean allNotificationsEnabled; + private boolean communityNotificationsEnabled; + private boolean eventNotificationsEnabled; + + public static AdminUserResponseDTO from(User user) { + return AdminUserResponseDTO.builder() + .id(user.getId()) + .email(user.getEmail()) + .nickname(user.getNickname()) + .role(user.getRole()) + .provider(user.getProvider()) + .status(user.getStatus()) + .profileImageUrl(user.getProfileImageUrl()) + .career(user.getCareer()) + .kindergartenName(user.getKindergarten() != null ? user.getKindergarten().getName() : null) + .createdAt(user.getCreatedAt()) + .deletedAt(user.getDeletedAt()) + .previousDeletedAt(user.getPreviousDeletedAt()) + .isRestoredUser(user.isRestoredUser()) + .hasWrittenReview(user.hasWrittenReview()) + .allNotificationsEnabled(user.hasNotificationEnabled(NotificationSetting.ALL_NOTIFICATIONS)) + .communityNotificationsEnabled(user.hasNotificationEnabled(NotificationSetting.COMMUNITY_NOTIFICATIONS)) + .eventNotificationsEnabled(user.hasNotificationEnabled(NotificationSetting.EVENT_NOTIFICATIONS)) + .build(); + } +} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/user/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/EmailDuplicationException.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/EmailDuplicationException.java deleted file mode 100644 index 47d8eff..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/EmailDuplicationException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -public class EmailDuplicationException extends RuntimeException{ - private String message; - - public EmailDuplicationException(String message) {} -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/InvalidPasswordException.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/InvalidPasswordException.java deleted file mode 100644 index 92fa468..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/InvalidPasswordException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -public class InvalidPasswordException extends RuntimeException { - private String message; - - public InvalidPasswordException(String message) { - this.message = message; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailException.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailException.java deleted file mode 100644 index decb3e0..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -public class NotFoundEmailException extends RuntimeException{ - private String message; - - public NotFoundEmailException(String message) {} -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailExceptionByTemporaryPassword.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailExceptionByTemporaryPassword.java deleted file mode 100644 index d5c73f2..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/NotFoundEmailExceptionByTemporaryPassword.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -public class NotFoundEmailExceptionByTemporaryPassword extends RuntimeException{ - private String message; - - public NotFoundEmailExceptionByTemporaryPassword(String message) {} -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/PasswordMismatchException.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/PasswordMismatchException.java deleted file mode 100644 index 8e72b7b..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/PasswordMismatchException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -public class PasswordMismatchException extends RuntimeException { - private String message; - - public PasswordMismatchException(String message) { - this.message = message; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/exception/UnauthorizedException.java b/src/main/java/com/onebyone/kindergarten/domain/user/exception/UnauthorizedException.java deleted file mode 100644 index 93fbaa5..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/user/exception/UnauthorizedException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.onebyone.kindergarten.domain.user.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(HttpStatus.FORBIDDEN) -public class UnauthorizedException extends RuntimeException { - public UnauthorizedException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/repository/UserRepository.java b/src/main/java/com/onebyone/kindergarten/domain/user/repository/UserRepository.java index efc3f8a..f5fe856 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/user/repository/UserRepository.java +++ b/src/main/java/com/onebyone/kindergarten/domain/user/repository/UserRepository.java @@ -4,6 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -18,4 +20,52 @@ public interface UserRepository extends JpaRepository { Optional findUserWithKindergarten(@Param("email") String email); Optional findByEmailAndDeletedAtIsNotNull(String email); + + @Query("SELECT u FROM user u LEFT JOIN FETCH u.Kindergarten WHERE u.id = :id") + Optional findByIdWithKindergarten(@Param("id") Long id); + + @Query("SELECT u FROM user u LEFT JOIN FETCH u.Kindergarten k") + Page findAllUsersWithKindergarten(Pageable pageable); + + @Query(value = "SELECT u FROM user u LEFT JOIN FETCH u.Kindergarten k WHERE " + + "(:email IS NULL OR " + + " (LENGTH(:email) <= 3 AND u.email LIKE %:email%) OR " + + " (LENGTH(:email) > 3 AND u.email LIKE :email%)) AND " + + "(:nickname IS NULL OR " + + " (LENGTH(:nickname) <= 2 AND u.nickname LIKE %:nickname%) OR " + + " (LENGTH(:nickname) > 2 AND u.nickname LIKE :nickname%)) AND " + + "(:role IS NULL OR u.role = :role) AND " + + "(:provider IS NULL OR u.provider = :provider) AND " + + "(:status IS NULL OR u.status = :status) AND " + + "(:kindergartenName IS NULL OR k.name LIKE %:kindergartenName%) AND " + + "(:hasWrittenReview IS NULL OR u.hasWrittenReview = :hasWrittenReview) AND " + + "(:isRestoredUser IS NULL OR " + + " (:isRestoredUser = true AND u.previousDeletedAt IS NOT NULL) OR " + + " (:isRestoredUser = false AND u.previousDeletedAt IS NULL))", + countQuery = "SELECT COUNT(u) FROM user u LEFT JOIN u.Kindergarten k WHERE " + + "(:email IS NULL OR " + + " (LENGTH(:email) <= 3 AND u.email LIKE %:email%) OR " + + " (LENGTH(:email) > 3 AND u.email LIKE :email%)) AND " + + "(:nickname IS NULL OR " + + " (LENGTH(:nickname) <= 2 AND u.nickname LIKE %:nickname%) OR " + + " (LENGTH(:nickname) > 2 AND u.nickname LIKE :nickname%)) AND " + + "(:role IS NULL OR u.role = :role) AND " + + "(:provider IS NULL OR u.provider = :provider) AND " + + "(:status IS NULL OR u.status = :status) AND " + + "(:kindergartenName IS NULL OR k.name LIKE %:kindergartenName%) AND " + + "(:hasWrittenReview IS NULL OR u.hasWrittenReview = :hasWrittenReview) AND " + + "(:isRestoredUser IS NULL OR " + + " (:isRestoredUser = true AND u.previousDeletedAt IS NOT NULL) OR " + + " (:isRestoredUser = false AND u.previousDeletedAt IS NULL))") + Page findUsersWithFilters( + @Param("email") String email, + @Param("nickname") String nickname, + @Param("role") com.onebyone.kindergarten.domain.user.enums.UserRole role, + @Param("provider") com.onebyone.kindergarten.domain.user.entity.UserProvider provider, + @Param("status") com.onebyone.kindergarten.domain.user.enums.UserStatus status, + @Param("kindergartenName") String kindergartenName, + @Param("hasWrittenReview") Boolean hasWrittenReview, + @Param("isRestoredUser") Boolean isRestoredUser, + Pageable pageable + ); } diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/service/CustomUserDetailService.java b/src/main/java/com/onebyone/kindergarten/domain/user/service/CustomUserDetailService.java index de76a79..4c99973 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/user/service/CustomUserDetailService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/user/service/CustomUserDetailService.java @@ -2,8 +2,9 @@ import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.enums.UserRole; -import com.onebyone.kindergarten.domain.user.exception.NotFoundEmailException; import com.onebyone.kindergarten.domain.user.repository.UserRepository; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -18,7 +19,7 @@ public class CustomUserDetailService implements UserDetailsService{ @Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); return org.springframework.security.core.userdetails.User.builder() .username(email) diff --git a/src/main/java/com/onebyone/kindergarten/domain/user/service/UserService.java b/src/main/java/com/onebyone/kindergarten/domain/user/service/UserService.java index 7134d16..a75f4cb 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/user/service/UserService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/user/service/UserService.java @@ -14,22 +14,22 @@ import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.enums.NotificationSetting; import com.onebyone.kindergarten.domain.user.enums.UserRole; -import com.onebyone.kindergarten.domain.user.exception.EmailDuplicationException; -import com.onebyone.kindergarten.domain.user.exception.InvalidPasswordException; -import com.onebyone.kindergarten.domain.user.exception.NotFoundEmailException; -import com.onebyone.kindergarten.domain.user.exception.NotFoundEmailExceptionByTemporaryPassword; -import com.onebyone.kindergarten.domain.user.exception.PasswordMismatchException; import com.onebyone.kindergarten.domain.user.repository.EmailCertificationRepository; import com.onebyone.kindergarten.domain.user.repository.UserRepository; +import com.onebyone.kindergarten.global.exception.ErrorCodes; +import com.onebyone.kindergarten.global.exception.BusinessException; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.security.auth.login.AccountNotFoundException; import java.util.Optional; import java.util.HashSet; import java.util.Set; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import com.onebyone.kindergarten.domain.user.dto.request.UserSearchDTO; +import com.onebyone.kindergarten.domain.user.dto.response.AdminUserResponseDTO; @Service @RequiredArgsConstructor @@ -42,7 +42,7 @@ public class UserService { @Transactional public String signUp(SignUpRequestDTO request) { if (isExistedEmail(request.getEmail())) { - throw new EmailDuplicationException(request.getEmail()); + throw new BusinessException(ErrorCodes.ALREADY_EXIST_EMAIL); } String encodedPassword = encodePassword(request.getPassword()); @@ -51,14 +51,6 @@ public String signUp(SignUpRequestDTO request) { return user.getEmail(); } - @Transactional(readOnly = true) - public String findById(Long id) throws AccountNotFoundException { - User user = userRepository.findById(id) - .orElseThrow(() -> new AccountNotFoundException("id가 존재하지 않습니다.")); - - return user.getEmail(); - } - @Transactional(readOnly = true) public boolean isExistedEmail(String email) { return userRepository.findByEmailAndDeletedAtIsNull(email).isPresent(); @@ -75,7 +67,7 @@ public String signIn(SignInRequestDTO request) { if (activeUser.isPresent()) { User user = activeUser.get(); if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) { - throw new InvalidPasswordException("비밀번호가 일치하지 않습니다."); + throw new BusinessException(ErrorCodes.INVALID_PASSWORD_ERROR); } if (request.getFcmToken() != null) { @@ -90,7 +82,7 @@ public String signIn(SignInRequestDTO request) { if (deletedUser.isPresent()) { User user = deletedUser.get(); if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) { - throw new InvalidPasswordException("비밀번호가 일치하지 않습니다."); + throw new BusinessException(ErrorCodes.INVALID_PASSWORD_ERROR); } // 계정 복구 @@ -103,7 +95,7 @@ public String signIn(SignInRequestDTO request) { return user.getEmail(); } - throw new NotFoundEmailException("이메일이 존재하지 않습니다."); + throw new BusinessException(ErrorCodes.NOT_FOUND_EMAIL); } @Transactional @@ -123,7 +115,7 @@ public void changePassword(String email, ModifyUserPasswordRequestDTO request) { User user = findUser(email); if (!passwordEncoder.matches(request.getCurrentPassword(), user.getPassword())) { - throw new PasswordMismatchException("비밀번호가 일치하지 않습니다."); + throw new BusinessException(ErrorCodes.INVALID_PASSWORD_ERROR); } user.changePassword(passwordEncoder.encode(request.getNewPassword())); @@ -131,7 +123,7 @@ public void changePassword(String email, ModifyUserPasswordRequestDTO request) { private User findUser(String email) { return userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); } @Transactional @@ -142,7 +134,7 @@ public void withdraw(String email) { public User getUserByEmail(String email) { return userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); } @Transactional @@ -152,7 +144,7 @@ public void updateCareer(User user, String career) { public UserDTO getUser(String email) { return UserDTO.from(userRepository.findUserWithKindergarten(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다"))); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL))); } @Transactional @@ -216,7 +208,7 @@ public String signUpByKakao(KakaoUserResponse userResponse, String fcmToken) { // FCM 토큰이 있으면 업데이트 if (fcmToken != null && !fcmToken.trim().isEmpty()) { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); user.updateFcmToken(fcmToken); } @@ -282,7 +274,7 @@ public String signUpByNaver(NaverUserResponse userResponse, String fcmToken) { // FCM 토큰이 있으면 업데이트 if (fcmToken != null && !fcmToken.trim().isEmpty()) { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); user.updateFcmToken(fcmToken); } @@ -349,7 +341,7 @@ public String signUpByApple(AppleUserResponse userResponse, String fcmToken) { // FCM 토큰이 있으면 업데이트 if (fcmToken != null && !fcmToken.trim().isEmpty()) { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); user.updateFcmToken(fcmToken); } @@ -365,7 +357,7 @@ public void updateHomeShortcut(String email, HomeShortcutsDto homeShortcutsDto) @Transactional public boolean saveCertification(String email, String certification) { if (userRepository.existsByEmail(email)) { - throw new EmailDuplicationException("이미 존재하는 이메일입니다."); + throw new BusinessException(ErrorCodes.ALREADY_EXIST_EMAIL); } EmailCertification emailCert = EmailCertification.builder() @@ -382,7 +374,7 @@ public boolean saveCertification(String email, String certification) { public boolean checkEmailCertification(CheckEmailCertificationRequestDTO request) { EmailCertification emailCertification = emailCertificationRepository .findById(request.getEmail()) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); if (emailCertification.getCertification().equals(request.getCertification())) { emailCertification.completeCertification(); @@ -408,17 +400,17 @@ public void updateTemporaryPassword(String email, String number) { public void checkEmailCertificationByTemporaryPassword(String email) { EmailCertification emailCertification = emailCertificationRepository .findById(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); if (!emailCertification.isCertificated()) { - throw new NotFoundEmailExceptionByTemporaryPassword("이메일이 검증되지 않았습니다."); + throw new BusinessException(ErrorCodes.NOT_FOUND_EXCEPTION_BY_TEMPORARY_PASSWORD_EXCEPTION); } } @Transactional(readOnly = true) public NotificationSettingsDTO getNotificationSettings(String email) { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); return NotificationSettingsDTO.builder() .allNotificationsEnabled(user.hasNotificationEnabled(NotificationSetting.ALL_NOTIFICATIONS)) @@ -430,7 +422,7 @@ public NotificationSettingsDTO getNotificationSettings(String email) { @Transactional public NotificationSettingsDTO updateNotificationSettings(String email, NotificationSettingsDTO request) { User user = userRepository.findByEmailAndDeletedAtIsNull(email) - .orElseThrow(() -> new NotFoundEmailException("이메일이 존재하지 않습니다.")); + .orElseThrow(() -> new BusinessException(ErrorCodes.NOT_FOUND_EMAIL)); Set enabledSettings = new HashSet<>(); if (request.isAllNotificationsEnabled()) { @@ -455,4 +447,35 @@ public void markUserAsReviewWriter(String email) { user.markAsReviewWriter(); } } + + /// 관리자용 - 전체 유저 조회 + @Transactional(readOnly = true) + public Page getAllUsers(Pageable pageable) { + Page users = userRepository.findAllUsersWithKindergarten(pageable); + return users.map(AdminUserResponseDTO::from); + } + + /// 관리자용 - 유저 검색 + @Transactional(readOnly = true) + public Page searchUsers(UserSearchDTO searchDTO, Pageable pageable) { + Page users = userRepository.findUsersWithFilters( + searchDTO.getEmail(), + searchDTO.getNickname(), + searchDTO.getRole(), + searchDTO.getProvider(), + searchDTO.getStatus(), + searchDTO.getKindergartenName(), + searchDTO.getHasWrittenReview(), + searchDTO.getIsRestoredUser(), + pageable + ); + return users.map(AdminUserResponseDTO::from); + } + + @Transactional(readOnly = true) + public AdminUserResponseDTO getUserById(Long userId) { + User user = userRepository.findByIdWithKindergarten(userId) + .orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다. ID: " + userId)); + return AdminUserResponseDTO.from(user); + } } diff --git a/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/AlreadyBlockException.java b/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/AlreadyBlockException.java deleted file mode 100644 index bbb308c..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/AlreadyBlockException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.userBlock.exception; - -public class AlreadyBlockException extends RuntimeException { - public AlreadyBlockException(String message) { - super(message); - } -} diff --git a/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/SelfBlockException.java b/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/SelfBlockException.java deleted file mode 100644 index 5e47aa9..0000000 --- a/src/main/java/com/onebyone/kindergarten/domain/userBlock/exception/SelfBlockException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.onebyone.kindergarten.domain.userBlock.exception; - -public class SelfBlockException extends RuntimeException { - public SelfBlockException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/domain/userBlock/service/UserBlockService.java b/src/main/java/com/onebyone/kindergarten/domain/userBlock/service/UserBlockService.java index 120a253..f63d64e 100644 --- a/src/main/java/com/onebyone/kindergarten/domain/userBlock/service/UserBlockService.java +++ b/src/main/java/com/onebyone/kindergarten/domain/userBlock/service/UserBlockService.java @@ -2,12 +2,12 @@ import com.onebyone.kindergarten.domain.user.entity.User; import com.onebyone.kindergarten.domain.user.service.UserService; -import com.onebyone.kindergarten.domain.userBlock.exception.AlreadyBlockException; -import com.onebyone.kindergarten.domain.userBlock.exception.SelfBlockException; import com.onebyone.kindergarten.domain.userBlock.dto.response.BlockedUserResponseDto; import java.util.List; import com.onebyone.kindergarten.domain.userBlock.entity.UserBlock; import com.onebyone.kindergarten.domain.userBlock.repository.UserBlockRepository; +import com.onebyone.kindergarten.global.exception.BusinessException; +import com.onebyone.kindergarten.global.exception.ErrorCodes; import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.stereotype.Service; @@ -46,10 +46,10 @@ public void unblockUser(UserDetails userDetails, String targetUserEmail) { private void validateBlockRequest(Long userId, Long targetUserId) { if (userId.equals(targetUserId)) { - throw new SelfBlockException("자기 자신을 차단할 수 없습니다."); + throw new BusinessException(ErrorCodes.SELF_BLOCK_NOT_ALLOWED); } if (userBlockRepository.existsByUserIdAndBlockedUserId(userId, targetUserId)) { - throw new AlreadyBlockException("이미 차단한 사용자입니다."); + throw new BusinessException(ErrorCodes.ALREADY_BLOCK_USER); } } diff --git a/src/main/java/com/onebyone/kindergarten/domain/userFavoriteKindergartens/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/userFavoriteKindergartens/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/domain/userNotification/exception/.gitkeep b/src/main/java/com/onebyone/kindergarten/domain/userNotification/exception/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/global/config/SecurityConfig.java b/src/main/java/com/onebyone/kindergarten/global/config/SecurityConfig.java index e94887f..48d03b8 100644 --- a/src/main/java/com/onebyone/kindergarten/global/config/SecurityConfig.java +++ b/src/main/java/com/onebyone/kindergarten/global/config/SecurityConfig.java @@ -72,6 +72,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/v3/api-docs/**", "/community/**", "/swagger-resources/**", + "/sample/v2/sample", "/webjars/**", "/notice/**") .permitAll() diff --git a/src/main/java/com/onebyone/kindergarten/global/error/.gitkeep b/src/main/java/com/onebyone/kindergarten/global/error/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/onebyone/kindergarten/global/error/Error.java b/src/main/java/com/onebyone/kindergarten/global/error/Error.java deleted file mode 100644 index 894fc53..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/error/Error.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.onebyone.kindergarten.global.error; - -import lombok.Getter; - -@Getter -public enum Error { - // INVALID_INPUT_VALUE("입력값이 올바르지 않습니다."), - // EMAIL_DUPLICATION("중복된 이메일입니다."), - // ACCOUNT_NOT_FOUND("계정을 찾을 수 없습니다."), - // INVALID_TOKEN("올바르지 않은 Token 입니다."), - // REFRESH_TOKEN_NOT_FOUND("이미 로그아웃된 사용자입니다."), - // POST_NOT_FOUND("게시글을 찾을 수 없습니다."), - // COMMENT_NOT_FOUND("댓글을 찾을 수 없습니다."); - INVALID_PASSWORD_ERROR("비밀번호가 일치하지 않습니다."), - SAMPLE("예시 에러입니다"), - NOT_FOUND_EMAIL_ERROR("이메일이 존재하지 않습니다."), - PASSWORD_MISMATCH_ERROR("비밀번호가 일치하지 않습니다."), - INTERNAL_SERVER_ERROR("알 수 없는 에러 발생"), - INQUIRY_NOT_FOUND("문의를 찾을 수 없습니다."), - INQUIRY_NOT_ADMIN_CANNOT_WRITE("관리자가 아니면 문의를 작성할 수 없습니다."), - INQUIRY_NOT_ADMIN_CANNOT_READ("관리자가 아니면 문의를 읽을 수 없습니다."), - POST_NOT_FOUND("게시글을 찾을 수 없습니다."), - KINDERGARTEN_NOT_FOUND("유치원을 찾을 수 없습니다."), - WORK_HISTORY_NOT_FOUND("이력을 찾을 수 없습니다."), - UNAUTHORIZED_DELETE("삭제 권한이 없습니다."), - REPORT_NOT_FOUND("신고를 찾을 수 없습니다."), - INVALID_REPORT_STATUS("잘못된 신고 상태입니다."), - INVALID_REPORT_TARGET("존재하지 않는 신고 대상입니다."), - NOTICE_NOT_FOUND("존재하지 않는 공지사항입니다."), - ALREADY_EXIST_INTERNSHIP_REVIEW("이미 등록된 실습 리뷰가 존재합니다."), - NOT_FOUND_INTERNSHIP_REVIEW("실습 리뷰가 존재하지 않습니다."), - ALREADY_EXIST_WORK_REVIEW("이미 등록된 근무 리뷰가 존재합니다."), - NOT_FOUND_WORK_REVIEW("근무 리뷰가 존재하지 않습니다."), - INCORRECT_USER_EXCEPTION("유저가 일치하지 않습니다."), - INVALID_TOKEN_EXPIRED("만료된 토큰입니다."), - INVALID_TOKEN_UNSUPPORTED("지원되지 않는 토큰 형식입니다."), - INVALID_TOKEN_MALFORMED("구조가 잘못된 토큰입니다."), - INVALID_TOKEN_SIGNATURE("서명이 올바르지 않은 토큰입니다."), - INVALID_TOKEN_ILLEGAL("잘못 생성된 토큰입니다."), - NOTIFICATION_ERROR("알림 전송 중 오류가 발생했습니다."), - ENTITY_NOT_FOUND_EXCEPTION("유치원을 찾을 수 없습니다."), - HTTP_MESSAGE_NOT_REDABLE_EXCEPTION("잘못된 요청 형식입니다."), - EMAIL_DUPLICATION_EXCEPTION("이메일이 중복 되었습니다."), - NOT_FOUND_EXCEPTION_BY_TEMPORARY_PASSWORD_EXCEPTION("이메일이 인증되지 않았습니다."), - ILLEGAL_ARGUMENT_STAR_RATING_EXCEPTION("starRating은 1부터 5 사이의 값이어야 합니다."), - ALREADY_BLOCK_USER("이미 차단한 사용자입니다."), - SELF_BLOCK_NOT_ALLOWED("자기 자신을 차단할 수 없습니다."); - - private final String message; - - Error(String message) { - this.message = message; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/error/ErrorResponse.java b/src/main/java/com/onebyone/kindergarten/global/error/ErrorResponse.java deleted file mode 100644 index faad57b..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/error/ErrorResponse.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.onebyone.kindergarten.global.error; - -import lombok.Builder; -import lombok.Getter; - -@Getter -public class ErrorResponse { - private final String message; - - @Builder - public ErrorResponse(String message) { - this.message = message; - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/BusinessException.java b/src/main/java/com/onebyone/kindergarten/global/exception/BusinessException.java new file mode 100644 index 0000000..4b97215 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/global/exception/BusinessException.java @@ -0,0 +1,14 @@ +package com.onebyone.kindergarten.global.exception; + +public class BusinessException extends RuntimeException { + private final ErrorCodes errorCodes; + + public BusinessException(ErrorCodes errorCodes) { + super(errorCodes.getCode()); + this.errorCodes = errorCodes; + } + + public ErrorCodes getErrorCode() { + return errorCodes; + } +} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/EntityNotFoundException.java b/src/main/java/com/onebyone/kindergarten/global/exception/EntityNotFoundException.java deleted file mode 100644 index 00ca4fb..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/EntityNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - - -public class EntityNotFoundException extends RuntimeException { - public EntityNotFoundException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/ErrorCodes.java b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorCodes.java new file mode 100644 index 0000000..84fcf68 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorCodes.java @@ -0,0 +1,59 @@ +package com.onebyone.kindergarten.global.exception; + +import lombok.Getter; + +@Getter +public enum ErrorCodes { + INVALID_PASSWORD_ERROR("E0001","비밀번호가 일치하지 않습니다."), + NOT_FOUND_EMAIL("E0002", "이메일이 존재하지 않습니다."), + PASSWORD_MISMATCH_ERROR("E0003", "비밀번호가 일치하지 않습니다."), + NOT_FOUND_INQUIRY("E0004","문의를 찾을 수 없습니다."), + INQUIRY_NOT_ADMIN_CANNOT_WRITE("E0005","관리자가 아니면 문의를 작성할 수 없습니다."), + INQUIRY_NOT_ADMIN_CANNOT_READ("E0006","관리자가 아니면 문의를 읽을 수 없습니다."), + POST_NOT_FOUND("E0007", "게시글을 찾을 수 없습니다."), + KINDERGARTEN_NOT_FOUND("E0008","유치원을 찾을 수 없습니다."), + WORK_HISTORY_NOT_FOUND("E0009","이력을 찾을 수 없습니다."), + UNAUTHORIZED_DELETE("E0010","삭제 권한이 없습니다."), + NOT_FOUND_REPORT("E0011","신고를 찾을 수 없습니다."), + INVALID_REPORT_STATUS("E0012", "잘못된 신고 상태입니다."), + INVALID_REPORT_POST_TARGET("E0013", "존재하지 않는 신고 게시글입니다."), + NOT_FOUND_NOTICE("E0014", "존재하지 않는 공지사항입니다."), + ALREADY_EXIST_INTERNSHIP_REVIEW("E0015", "이미 등록된 실습 리뷰가 존재합니다."), + NOT_FOUND_INTERNSHIP_REVIEW("E0016", "실습 리뷰가 존재하지 않습니다."), + ALREADY_EXIST_WORK_REVIEW("E0017","이미 등록된 근무 리뷰가 존재합니다."), + NOT_FOUND_WORK_REVIEW("E0018", "근무 리뷰가 존재하지 않습니다."), + INCORRECT_USER_EXCEPTION("E0019", "유저가 일치하지 않습니다."), + INVALID_TOKEN_EXPIRED("E0020", "만료된 토큰입니다."), + INVALID_TOKEN_UNSUPPORTED("E0021","지원되지 않는 토큰 형식입니다."), + INVALID_TOKEN_MALFORMED("E0022","구조가 잘못된 토큰입니다."), + INVALID_TOKEN_SIGNATURE("E0023","서명이 올바르지 않은 토큰입니다."), + INVALID_TOKEN_ILLEGAL("E0024","잘못 생성된 토큰입니다."), + NOTIFICATION_ERROR("E0025", "알림 전송 중 오류가 발생했습니다."), + ENTITY_NOT_FOUND_EXCEPTION("E0026","유치원을 찾을 수 없습니다."), + HTTP_MESSAGE_NOT_REDABLE_EXCEPTION("E0027","잘못된 요청 형식입니다."), + ALREADY_EXIST_EMAIL("E0028","이미 존재하는 이메일입니다."), + NOT_FOUND_EXCEPTION_BY_TEMPORARY_PASSWORD_EXCEPTION("E0029","이메일이 인증되지 않았습니다."), + ILLEGAL_ARGUMENT_STAR_RATING_EXCEPTION("E0030","starRating은 1부터 5 사이의 값이어야 합니다."), + ALREADY_BLOCK_USER("E0031","이미 차단한 사용자입니다."), + SELF_BLOCK_NOT_ALLOWED("E0032","자기 자신을 차단할 수 없습니다."), + NOT_FOUND_POST("E0033","게시글을 찾을 수 없습니다."), + NOT_FOUND_PARENT_COMMENT("E0034", "원 댓글을 찾을 수 없습니다."), + PARENT_POST_MISMATCH("E0035", "원 댓글의 게시글이 일치하지 않습니다."), + REPLY_TO_REPLY_NOT_ALLOWED("E0036", "대댓글에는 답글을 작성할 수 없습니다."), + REPLY_TO_DELETED_COMMENT_NOT_ALLOWED("E0037", "삭제된 댓글에는 답글을 작성할 수 없습니다."), + NOT_FOUND_COMMENT("E0038", "댓글이 존재하지 않습니다."), + REVIEW_EDIT_NOT_OWNER("E0039", "본인의 리뷰만 수정할 수 있습니다."), + NOT_FOUND_USER("E0040", "사용자가 존재하지 않습니다."), + INVALID_REPORT_COMMENT_TARGET("E0041", "존재하지 않는 신고 댓글입니다."), + REVIEW_REPORT_NOT_IMPLEMENTED("E0042", "리뷰 처리는 아직 구현되지 않았습니다."), + INVALID_REPORT_TARGET_TYPE("E0043", "지원하지 않는 신고 대상 타입입니다."), + INTERNAL_SERVER_ERROR("E9999","알 수 없는 에러 발생"); + + private final String code; + private final String message; + + ErrorCodes(String code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/ErrorHandler.java b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorHandler.java index 196573f..4bfbaf4 100644 --- a/src/main/java/com/onebyone/kindergarten/global/exception/ErrorHandler.java +++ b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorHandler.java @@ -1,290 +1,26 @@ package com.onebyone.kindergarten.global.exception; -import com.onebyone.kindergarten.domain.communityPosts.exception.PostNotFoundException; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotAdminReadException; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotAdminWriteException; -import com.onebyone.kindergarten.domain.inquires.exception.InquiryNotFoundException; -import com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception.AlreadyExistInternshipReviewException; -import com.onebyone.kindergarten.domain.kindergartenInternshipReview.exception.NotFoundInternshipReviewException; -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.KindergartenNotFoundException; -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.UnauthorizedDeleteException; -import com.onebyone.kindergarten.domain.kindergartenWorkHistories.exception.WorkHistoryNotFoundException; -import com.onebyone.kindergarten.domain.notice.exception.NoticeNotFoundException; -import com.onebyone.kindergarten.domain.kindergartenWorkReview.exception.AlreadyExistWorkReviewException; -import com.onebyone.kindergarten.domain.kindergartenWorkReview.exception.NotFoundWorkReviewException; -import com.onebyone.kindergarten.domain.pushNotification.exception.NotificationException; -import com.onebyone.kindergarten.domain.reports.exception.InvalidReportStatusException; -import com.onebyone.kindergarten.domain.reports.exception.InvalidReportTargetException; -import com.onebyone.kindergarten.domain.reports.exception.ReportNotFoundException; -import com.onebyone.kindergarten.domain.sample.exception.SampleException; -import com.onebyone.kindergarten.domain.user.exception.EmailDuplicationException; -import com.onebyone.kindergarten.domain.user.exception.InvalidPasswordException; -import com.onebyone.kindergarten.domain.user.exception.NotFoundEmailException; -import com.onebyone.kindergarten.domain.user.exception.NotFoundEmailExceptionByTemporaryPassword; -import com.onebyone.kindergarten.domain.userBlock.exception.AlreadyBlockException; -import com.onebyone.kindergarten.domain.userBlock.exception.SelfBlockException; -import com.onebyone.kindergarten.domain.user.exception.PasswordMismatchException; -import com.onebyone.kindergarten.global.error.Error; -import com.onebyone.kindergarten.global.error.ErrorResponse; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; -import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.servlet.resource.NoResourceFoundException; +import org.springframework.web.bind.annotation.ResponseBody; @Slf4j -@RestControllerAdvice +@ControllerAdvice public class ErrorHandler { - @ExceptionHandler(SampleException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleSampleException(SampleException e) { - log.error("SampleException 발생: {}", e.getMessage(), e); - return buildError(Error.SAMPLE); + @ExceptionHandler(BusinessException.class) + @ResponseBody + public ErrorResponse handleBusinessException(BusinessException e) { + ErrorCodes errorCodes = e.getErrorCode(); + log.error("BusinessException: 발생: 에러코드:{} 에러 메시지:{}", e.getMessage(), e.getErrorCode()); + return ErrorResponse.buildError(errorCodes); } - @ExceptionHandler(InvalidPasswordException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleInvalidPasswordException(InvalidPasswordException e) { - log.error("InvalidPasswordException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_PASSWORD_ERROR); - } - - @ExceptionHandler(NotFoundEmailException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleNotFoundEmailException(NotFoundEmailException e) { - log.error("NotFoundEmailException 발생: {}", e.getMessage(), e); - return buildError(Error.NOT_FOUND_EMAIL_ERROR); - } - - @ExceptionHandler(PasswordMismatchException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handlePasswordMismatchException(PasswordMismatchException e) { - log.error("PasswordMismatchException 발생: {}", e.getMessage(), e); - return buildError(Error.PASSWORD_MISMATCH_ERROR); - } @ExceptionHandler(Exception.class) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) // 기본적으로 500 처리 + @ResponseBody public ErrorResponse handleAllExceptions(Exception e) { log.error("알 수 없는 예외 발생: {}", e.getMessage(), e); - return buildError(Error.INTERNAL_SERVER_ERROR); - } - - @ExceptionHandler(InquiryNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse inQueryNotFoundExceptions(InquiryNotFoundException error) { - log.error("InquiryNotFoundException 발생: {}", error.getMessage(), error); - return buildError(Error.INQUIRY_NOT_FOUND); - } - - @ExceptionHandler(PostNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse postNotFoundExceptions(PostNotFoundException error) { - log.error("PostNotFoundException 발생: {}", error.getMessage(), error); - return buildError(Error.POST_NOT_FOUND); - } - - @ExceptionHandler(KindergartenNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse handleKindergartenNotFoundException(KindergartenNotFoundException e) { - log.error("KindergartenNotFoundException 발생: {}", e.getMessage(), e); - return buildError(Error.KINDERGARTEN_NOT_FOUND); - } - - @ExceptionHandler(WorkHistoryNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse handleWorkHistoryNotFoundException(WorkHistoryNotFoundException e) { - log.error("WorkHistoryNotFoundException 발생: {}", e.getMessage(), e); - return buildError(Error.WORK_HISTORY_NOT_FOUND); - } - - @ExceptionHandler(UnauthorizedDeleteException.class) - @ResponseStatus(HttpStatus.FORBIDDEN) - protected ErrorResponse handleUnauthorizedDeleteException(UnauthorizedDeleteException e) { - log.error("UnauthorizedDeleteException 발생: {}", e.getMessage(), e); - return buildError(Error.UNAUTHORIZED_DELETE); - } - - @ExceptionHandler(ReportNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse handleReportNotFoundException(ReportNotFoundException e) { - log.error("ReportNotFoundException 발생: {}", e.getMessage(), e); - return buildError(Error.REPORT_NOT_FOUND); - } - - @ExceptionHandler(InvalidReportStatusException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleInvalidReportStatusException(InvalidReportStatusException e) { - log.error("InvalidReportStatusException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_REPORT_STATUS); - } - - @ExceptionHandler(InvalidReportTargetException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleInvalidReportTargetException(InvalidReportTargetException e) { - log.error("InvalidReportTargetException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_REPORT_TARGET); - } - - @ExceptionHandler(InquiryNotAdminReadException.class) - @ResponseStatus(HttpStatus.FORBIDDEN) - protected ErrorResponse handleInquiryNotAdminException(InquiryNotAdminReadException e) { - log.error("InquiryNotAdminException 발생: {}", e.getMessage(), e); - return buildError(Error.INQUIRY_NOT_ADMIN_CANNOT_READ); - } - - @ExceptionHandler(InquiryNotAdminWriteException.class) - @ResponseStatus(HttpStatus.FORBIDDEN) - protected ErrorResponse handleInquiryNotAdminWriteException(InquiryNotAdminWriteException e) { - log.error("InquiryNotAdminWriteException 발생: {}", e.getMessage(), e); - return buildError(Error.INQUIRY_NOT_ADMIN_CANNOT_WRITE); - } - - @ExceptionHandler(NoticeNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse handleEntityNotFoundException(NoticeNotFoundException e) { - log.error("NoticeNotFoundException 발생: {}", e.getMessage(), e); - return buildError(Error.NOTICE_NOT_FOUND); - } - - @ExceptionHandler(NotFoundInternshipReviewException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleNotFoundInternshipReviewException(NotFoundInternshipReviewException e) { - log.error("NotFoundInternshipReviewException 발생: {}", e.getMessage(), e); - return buildError(Error.NOT_FOUND_INTERNSHIP_REVIEW); - } - - @ExceptionHandler(AlreadyExistInternshipReviewException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleAlreadyExistInternshipReviewException(AlreadyExistInternshipReviewException e) { - log.error("AlearyExistsInternshipReviewException 발생: {}", e.getMessage(), e); - return buildError(Error.ALREADY_EXIST_INTERNSHIP_REVIEW); - } - - @ExceptionHandler(NotFoundWorkReviewException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleNotFoundWorkReviewException(NotFoundWorkReviewException e) { - log.error("NotFoundWorkReviewException 발생: {}", e.getMessage(), e); - return buildError(Error.NOT_FOUND_WORK_REVIEW); - } - - @ExceptionHandler(AlreadyExistWorkReviewException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleAlreadyExistWorkReviewException(AlreadyExistWorkReviewException e) { - log.error("AlreadyExistWorkReviewException 발생: {}", e.getMessage(), e); - return buildError(Error.ALREADY_EXIST_WORK_REVIEW); - } - - @ExceptionHandler(IncorrectUserException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleIncorrectUserException(IncorrectUserException e) { - log.error("IncorrectUserException 발생: {}", e.getMessage(), e); - return buildError(Error.INCORRECT_USER_EXCEPTION); - } - - @ExceptionHandler(ExpiredTokenException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - protected ErrorResponse handleExpiredTokenException(ExpiredTokenException e) { - log.error("ExpiredTokenException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_TOKEN_EXPIRED); - } - - @ExceptionHandler(UnsupportedTokenException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - protected ErrorResponse handleUnsupportedTokenException(UnsupportedTokenException e) { - log.error("UnsupportedTokenException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_TOKEN_UNSUPPORTED); - } - - @ExceptionHandler(MalformedTokenException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - protected ErrorResponse handleMalformedTokenException(MalformedTokenException e) { - log.error("MalformedTokenException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_TOKEN_MALFORMED); - } - - @ExceptionHandler(InvalidSignatureTokenException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - protected ErrorResponse handleInvalidSignatureTokenException(InvalidSignatureTokenException e) { - log.error("InvalidSignatureTokenException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_TOKEN_SIGNATURE); - } - - @ExceptionHandler(InvalidTokenArgumentException.class) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - protected ErrorResponse handleInvalidTokenArgumentException(InvalidTokenArgumentException e) { - log.error("InvalidTokenArgumentException 발생: {}", e.getMessage(), e); - return buildError(Error.INVALID_TOKEN_ILLEGAL); - } - - @ExceptionHandler(NotificationException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleNotificationException(NotificationException e) { - log.error("NotificationException 발생: {}", e.getMessage(), e); - return ErrorResponse.builder() - .message(e.getMessage()) - .build(); - } - - @ExceptionHandler(EntityNotFoundException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - protected ErrorResponse handleEntityNotFoundException(EntityNotFoundException e) { - log.error("EntityNotFoundException 발생: {}", e.getMessage(), e); - return buildError(Error.ENTITY_NOT_FOUND_EXCEPTION); - } - - @ExceptionHandler(HttpMessageNotReadableException.class) - public ErrorResponse handleEnumParseError(HttpMessageNotReadableException e) { - log.error("HttpMessageNotRedableException 발생: {}", e.getMessage(), e); - return buildError(Error.HTTP_MESSAGE_NOT_REDABLE_EXCEPTION); - } - - @ExceptionHandler(EmailDuplicationException.class) - public ErrorResponse handleEmailDuplicationError(EmailDuplicationException e) { - log.error("EmailDuplicationException 발생: {}", e.getMessage(), e); - return buildError(Error.EMAIL_DUPLICATION_EXCEPTION); - } - - @ExceptionHandler(NotFoundEmailExceptionByTemporaryPassword.class) - public ErrorResponse handleNotFoundEmailExceptionByTemporaryPasswordError(NotFoundEmailExceptionByTemporaryPassword e) { - log.error("NotFoundEmailExceptionByTemporaryPassword 발생: {}", e.getMessage(), e); - return buildError(Error.NOT_FOUND_EXCEPTION_BY_TEMPORARY_PASSWORD_EXCEPTION); - } - - @ExceptionHandler(IllegalArgumentStarRatingException.class) - public ErrorResponse handleIllegalArgumentStarRatingError(IllegalArgumentStarRatingException e) { - log.error("IllegalArgumentStarRatingException 발생: {}", e.getMessage(), e); - return buildError(Error.ILLEGAL_ARGUMENT_STAR_RATING_EXCEPTION); - } - - @ExceptionHandler(AlreadyBlockException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - public ErrorResponse handleAlreadyBlockException(AlreadyBlockException e) { - log.error("AlreadyBlockException 발생: {}", e.getMessage(), e); - return buildError(Error.ALREADY_BLOCK_USER); - } - - @ExceptionHandler(SelfBlockException.class) - @ResponseStatus(HttpStatus.BAD_REQUEST) - public ErrorResponse handleSelfBlockException(SelfBlockException e) { - log.error("SelfBlockException 발생: {}", e.getMessage(), e); - return buildError(Error.SELF_BLOCK_NOT_ALLOWED); - } - - @ExceptionHandler(NoResourceFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - protected ErrorResponse handleStaticResource404(NoResourceFoundException e) { - return ErrorResponse.builder() - .message("존재하지 않는 Url 입니다") - .build(); - } - - private ErrorResponse buildError(Error error) { - ErrorResponse retError = ErrorResponse.builder() - .message(error.getMessage()) - .build(); - return retError; + return ErrorResponse.buildError(ErrorCodes.INTERNAL_SERVER_ERROR); } } \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/ErrorResponse.java b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorResponse.java new file mode 100644 index 0000000..1e04f11 --- /dev/null +++ b/src/main/java/com/onebyone/kindergarten/global/exception/ErrorResponse.java @@ -0,0 +1,23 @@ +package com.onebyone.kindergarten.global.exception; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class ErrorResponse { + private final String code; + private final String message; + + @Builder + public ErrorResponse(String code, String message) { + this.code = code; + this.message = message; + } + + public static ErrorResponse buildError(ErrorCodes errorCodes) { + return ErrorResponse.builder() + .code(errorCodes.getCode()) + .message(errorCodes.getMessage()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/ExpiredTokenException.java b/src/main/java/com/onebyone/kindergarten/global/exception/ExpiredTokenException.java deleted file mode 100644 index 7bd7249..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/ExpiredTokenException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class ExpiredTokenException extends RuntimeException { - private String value; - - public ExpiredTokenException(String value) { - super(value); - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/IllegalArgumentStarRatingException.java b/src/main/java/com/onebyone/kindergarten/global/exception/IllegalArgumentStarRatingException.java deleted file mode 100644 index 5c8e77e..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/IllegalArgumentStarRatingException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class IllegalArgumentStarRatingException extends RuntimeException { - private String value; - - public IllegalArgumentStarRatingException(String value) { - super(value); - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/IncorrectUserException.java b/src/main/java/com/onebyone/kindergarten/global/exception/IncorrectUserException.java deleted file mode 100644 index 33a86a7..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/IncorrectUserException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class IncorrectUserException extends RuntimeException { - private String value; - - public IncorrectUserException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/InvalidSignatureTokenException.java b/src/main/java/com/onebyone/kindergarten/global/exception/InvalidSignatureTokenException.java deleted file mode 100644 index b736ee8..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/InvalidSignatureTokenException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class InvalidSignatureTokenException extends RuntimeException { - private String value; - - public InvalidSignatureTokenException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/InvalidTokenArgumentException.java b/src/main/java/com/onebyone/kindergarten/global/exception/InvalidTokenArgumentException.java deleted file mode 100644 index 702d77e..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/InvalidTokenArgumentException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class InvalidTokenArgumentException extends RuntimeException { - private String value; - - public InvalidTokenArgumentException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/MalformedTokenException.java b/src/main/java/com/onebyone/kindergarten/global/exception/MalformedTokenException.java deleted file mode 100644 index 3ebcf73..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/MalformedTokenException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class MalformedTokenException extends RuntimeException { - private String value; - - public MalformedTokenException(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/onebyone/kindergarten/global/exception/UnsupportedTokenException.java b/src/main/java/com/onebyone/kindergarten/global/exception/UnsupportedTokenException.java deleted file mode 100644 index 78176df..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/exception/UnsupportedTokenException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.exception; - -public class UnsupportedTokenException extends RuntimeException { - private String value; - - public UnsupportedTokenException(String value) { - this.value = value; - } -} \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/jwt/JwtEntryPoint.java b/src/main/java/com/onebyone/kindergarten/global/jwt/JwtEntryPoint.java index a390b7a..5150cb8 100644 --- a/src/main/java/com/onebyone/kindergarten/global/jwt/JwtEntryPoint.java +++ b/src/main/java/com/onebyone/kindergarten/global/jwt/JwtEntryPoint.java @@ -1,7 +1,6 @@ package com.onebyone.kindergarten.global.jwt; import lombok.extern.slf4j.Slf4j; -import org.json.JSONObject; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -16,19 +15,7 @@ public class JwtEntryPoint implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { - // 유효한 자격증명이 아닌 경우에는 401 에러 반환 - log.error("Unauthorized Error : {}", authException.getMessage()); - response.setContentType("application/json"); - response.setCharacterEncoding("utf-8"); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - - try { - String jsonResponse = new JSONObject() - .put("message", "인증에 실패했습니다") - .toString(); - response.getWriter().write(jsonResponse); - } catch (org.json.JSONException e) { - response.getWriter().write("알 수 없는 에러"); - } +// 유효한 자격증명이 아닌 경우에는 401 에러 반환 + log.error("Unauthorized Error : {} {}", authException.getMessage()); } } \ No newline at end of file diff --git a/src/main/java/com/onebyone/kindergarten/global/jwt/JwtProvider.java b/src/main/java/com/onebyone/kindergarten/global/jwt/JwtProvider.java index 6b7cb6d..1fbf35f 100644 --- a/src/main/java/com/onebyone/kindergarten/global/jwt/JwtProvider.java +++ b/src/main/java/com/onebyone/kindergarten/global/jwt/JwtProvider.java @@ -77,15 +77,15 @@ public boolean validateToken(String token) { .parseClaimsJws(token); return true; } catch (ExpiredJwtException e) { - throw new ExpiredTokenException("만료된 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_EXPIRED); } catch (UnsupportedJwtException e) { - throw new UnsupportedTokenException("잘못된 형식의 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_UNSUPPORTED); } catch (MalformedJwtException e) { - throw new MalformedTokenException("잘못된 구조의 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_MALFORMED); } catch (SignatureException e) { - throw new InvalidSignatureTokenException("잘못 서명된 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_SIGNATURE); } catch (IllegalArgumentException e) { - throw new InvalidTokenArgumentException("잘못 생성된 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_ILLEGAL); } } @@ -103,7 +103,7 @@ private Claims getClaims(String token) { } catch (Exception e) { // 다른 예외인 경우 throw log.error("유효하지 않은 토큰입니다. {}", e.toString()); - throw new InvalidTokenArgumentException("유효하지 않은 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_ILLEGAL); } } @@ -116,7 +116,7 @@ public Authentication getAuthentication(String token) { if (email == null) { log.error("권한 정보가 없는 토큰입니다. {}", token); - throw new InvalidTokenArgumentException("권한 정보가 없는 토큰입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_ILLEGAL); } UserDetails userDetails = customUserDetailService.loadUserByUsername(email); @@ -131,7 +131,7 @@ public Long getRemainingTime(String token) { public String getEmailFromRefreshToken(String refreshToken) { if (!validateToken(refreshToken)) { - throw new InvalidTokenArgumentException("유효하지 않은 RefreshToken입니다."); + throw new BusinessException(ErrorCodes.INVALID_TOKEN_ILLEGAL); } return getClaims(refreshToken).getSubject(); // email diff --git a/src/main/java/com/onebyone/kindergarten/global/jwt/exception/InvalidTokenException.java b/src/main/java/com/onebyone/kindergarten/global/jwt/exception/InvalidTokenException.java deleted file mode 100644 index 519fdad..0000000 --- a/src/main/java/com/onebyone/kindergarten/global/jwt/exception/InvalidTokenException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.onebyone.kindergarten.global.jwt.exception; - -public class InvalidTokenException extends RuntimeException{ - private String message; - - public InvalidTokenException(String message) { - this.message = message; - } -} diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 3320cbf..7226e18 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -39,15 +39,6 @@ - - - - - - - - -