diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/AccountExistsException.java b/src/main/java/leets/weeth/domain/account/application/exception/AccountExistsException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/AccountExistsException.java rename to src/main/java/leets/weeth/domain/account/application/exception/AccountExistsException.java index d40c0c83..bb04801b 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/AccountExistsException.java +++ b/src/main/java/leets/weeth/domain/account/application/exception/AccountExistsException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.account.application.exception; import jakarta.persistence.EntityExistsException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/AccountNotFoundException.java b/src/main/java/leets/weeth/domain/account/application/exception/AccountNotFoundException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/AccountNotFoundException.java rename to src/main/java/leets/weeth/domain/account/application/exception/AccountNotFoundException.java index 27113136..42a81da6 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/AccountNotFoundException.java +++ b/src/main/java/leets/weeth/domain/account/application/exception/AccountNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.account.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/ReceiptNotFoundException.java b/src/main/java/leets/weeth/domain/account/application/exception/ReceiptNotFoundException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/ReceiptNotFoundException.java rename to src/main/java/leets/weeth/domain/account/application/exception/ReceiptNotFoundException.java index 091767f6..d85e41fd 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/ReceiptNotFoundException.java +++ b/src/main/java/leets/weeth/domain/account/application/exception/ReceiptNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.account.application.exception; import jakarta.persistence.EntityExistsException; diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java b/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java index efb15100..591b1f34 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/AccountUseCaseImpl.java @@ -7,7 +7,7 @@ import leets.weeth.domain.account.domain.entity.Account; import leets.weeth.domain.account.domain.service.AccountGetService; import leets.weeth.domain.account.domain.service.AccountSaveService; -import leets.weeth.global.common.error.exception.custom.AccountExistsException; +import leets.weeth.domain.account.application.exception.AccountExistsException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/account/domain/service/AccountGetService.java b/src/main/java/leets/weeth/domain/account/domain/service/AccountGetService.java index f12abb3f..fd7abc73 100644 --- a/src/main/java/leets/weeth/domain/account/domain/service/AccountGetService.java +++ b/src/main/java/leets/weeth/domain/account/domain/service/AccountGetService.java @@ -2,7 +2,7 @@ import leets.weeth.domain.account.domain.entity.Account; import leets.weeth.domain.account.domain.repository.AccountRepository; -import leets.weeth.global.common.error.exception.custom.AccountNotFoundException; +import leets.weeth.domain.account.application.exception.AccountNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/account/domain/service/ReceiptGetService.java b/src/main/java/leets/weeth/domain/account/domain/service/ReceiptGetService.java index 63459fb9..9eb565b2 100644 --- a/src/main/java/leets/weeth/domain/account/domain/service/ReceiptGetService.java +++ b/src/main/java/leets/weeth/domain/account/domain/service/ReceiptGetService.java @@ -2,7 +2,7 @@ import leets.weeth.domain.account.domain.entity.Receipt; import leets.weeth.domain.account.domain.repository.ReceiptRepository; -import leets.weeth.global.common.error.exception.custom.ReceiptNotFoundException; +import leets.weeth.domain.account.application.exception.ReceiptNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceCodeMismatchException.java b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceCodeMismatchException.java new file mode 100644 index 00000000..d9387b00 --- /dev/null +++ b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceCodeMismatchException.java @@ -0,0 +1,7 @@ +package leets.weeth.domain.attendance.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class AttendanceCodeMismatchException extends BusinessLogicException { + public AttendanceCodeMismatchException() {super(400 ,"출석 코드가 일치하지 않습니다.");} +} \ No newline at end of file diff --git a/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceEventTypeNotMatchException.java b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceEventTypeNotMatchException.java new file mode 100644 index 00000000..f282c64e --- /dev/null +++ b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceEventTypeNotMatchException.java @@ -0,0 +1,7 @@ +package leets.weeth.domain.attendance.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class AttendanceEventTypeNotMatchException extends BusinessLogicException { + public AttendanceEventTypeNotMatchException() {super(400, "출석일정은 직접 수정할 수 없습니다.");} +} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceNotFoundException.java b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceNotFoundException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceNotFoundException.java rename to src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceNotFoundException.java index abb7f30c..f80c3be0 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceNotFoundException.java +++ b/src/main/java/leets/weeth/domain/attendance/application/exception/AttendanceNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.attendance.application.exception; import jakarta.persistence.EntityNotFoundException; public class AttendanceNotFoundException extends EntityNotFoundException { diff --git a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCase.java b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCase.java index 4b007480..6f61a801 100644 --- a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCase.java +++ b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCase.java @@ -1,6 +1,6 @@ package leets.weeth.domain.attendance.application.usecase; -import leets.weeth.global.common.error.exception.custom.AttendanceCodeMismatchException; +import leets.weeth.domain.attendance.application.exception.AttendanceCodeMismatchException; import java.time.LocalDate; diff --git a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java index 58090238..95eebc5d 100644 --- a/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/attendance/application/usecase/AttendanceUseCaseImpl.java @@ -9,9 +9,9 @@ import leets.weeth.domain.schedule.domain.service.MeetingGetService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.global.common.error.exception.custom.AttendanceCodeMismatchException; -import leets.weeth.global.common.error.exception.custom.AttendanceNotFoundException; -import leets.weeth.global.common.error.exception.custom.MeetingNotFoundException; +import leets.weeth.domain.attendance.application.exception.AttendanceCodeMismatchException; +import leets.weeth.domain.attendance.application.exception.AttendanceNotFoundException; +import leets.weeth.domain.schedule.application.exception.MeetingNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/attendance/presentation/AttendanceController.java b/src/main/java/leets/weeth/domain/attendance/presentation/AttendanceController.java index 856bd687..fea34016 100644 --- a/src/main/java/leets/weeth/domain/attendance/presentation/AttendanceController.java +++ b/src/main/java/leets/weeth/domain/attendance/presentation/AttendanceController.java @@ -3,7 +3,7 @@ import leets.weeth.domain.attendance.application.dto.AttendanceDTO; import leets.weeth.domain.attendance.application.usecase.AttendanceUseCase; import leets.weeth.global.auth.annotation.CurrentUser; -import leets.weeth.global.common.error.exception.custom.AttendanceCodeMismatchException; +import leets.weeth.domain.attendance.application.exception.AttendanceCodeMismatchException; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/NoticeNotFoundException.java b/src/main/java/leets/weeth/domain/board/application/exception/NoticeNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/NoticeNotFoundException.java rename to src/main/java/leets/weeth/domain/board/application/exception/NoticeNotFoundException.java index 929e72f9..5dffd8a7 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/NoticeNotFoundException.java +++ b/src/main/java/leets/weeth/domain/board/application/exception/NoticeNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.board.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/board/application/exception/NoticeTypeNotMatchException.java b/src/main/java/leets/weeth/domain/board/application/exception/NoticeTypeNotMatchException.java new file mode 100644 index 00000000..6bf48238 --- /dev/null +++ b/src/main/java/leets/weeth/domain/board/application/exception/NoticeTypeNotMatchException.java @@ -0,0 +1,7 @@ +package leets.weeth.domain.board.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class NoticeTypeNotMatchException extends BusinessLogicException { + public NoticeTypeNotMatchException() {super(400, "공지사항은 공지사항 게시판에서 수정하세요.");} +} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/PostNotFoundException.java b/src/main/java/leets/weeth/domain/board/application/exception/PostNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/PostNotFoundException.java rename to src/main/java/leets/weeth/domain/board/application/exception/PostNotFoundException.java index 4f195af2..337be339 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/PostNotFoundException.java +++ b/src/main/java/leets/weeth/domain/board/application/exception/PostNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.board.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java index bba5fb5e..4c98526e 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecase.java @@ -1,8 +1,7 @@ package leets.weeth.domain.board.application.usecase; import leets.weeth.domain.board.application.dto.NoticeDTO; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; -import org.springframework.web.bind.annotation.RequestParam; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import org.springframework.web.multipart.MultipartFile; import java.util.List; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java index a5afa4c6..6fbe0ba0 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/NoticeUsecaseImpl.java @@ -10,8 +10,8 @@ import leets.weeth.domain.file.service.FileSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.global.common.error.exception.custom.NoticeNotFoundException; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.board.application.exception.NoticeNotFoundException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java index 60c2cf58..28bcdd8a 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUseCaseImpl.java @@ -10,8 +10,8 @@ import leets.weeth.domain.file.service.FileSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.global.common.error.exception.custom.PostNotFoundException; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.board.application.exception.PostNotFoundException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java b/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java index f4f39878..30bbf762 100644 --- a/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java +++ b/src/main/java/leets/weeth/domain/board/application/usecase/PostUsecase.java @@ -1,8 +1,7 @@ package leets.weeth.domain.board.application.usecase; import leets.weeth.domain.board.application.dto.PostDTO; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; -import org.springframework.web.bind.annotation.RequestParam; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import org.springframework.web.multipart.MultipartFile; import java.util.List; diff --git a/src/main/java/leets/weeth/domain/board/domain/service/NoticeFindService.java b/src/main/java/leets/weeth/domain/board/domain/service/NoticeFindService.java index a225cc36..fcd95362 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/NoticeFindService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/NoticeFindService.java @@ -2,7 +2,7 @@ import leets.weeth.domain.board.domain.entity.Notice; import leets.weeth.domain.board.domain.repository.NoticeRepository; -import leets.weeth.global.common.error.exception.custom.NoticeNotFoundException; +import leets.weeth.domain.board.application.exception.NoticeNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/board/domain/service/PostFindService.java b/src/main/java/leets/weeth/domain/board/domain/service/PostFindService.java index 74efc223..da51453b 100644 --- a/src/main/java/leets/weeth/domain/board/domain/service/PostFindService.java +++ b/src/main/java/leets/weeth/domain/board/domain/service/PostFindService.java @@ -1,9 +1,8 @@ package leets.weeth.domain.board.domain.service; -import leets.weeth.domain.board.domain.entity.Notice; import leets.weeth.domain.board.domain.entity.Post; import leets.weeth.domain.board.domain.repository.PostRepository; -import leets.weeth.global.common.error.exception.custom.PostNotFoundException; +import leets.weeth.domain.board.application.exception.PostNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java b/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java index 34cc6d11..cd6f4f6b 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/NoticeAdminController.java @@ -4,9 +4,8 @@ import jakarta.validation.Valid; import leets.weeth.domain.board.application.dto.NoticeDTO; import leets.weeth.domain.board.application.usecase.NoticeUsecase; -import leets.weeth.domain.board.domain.entity.enums.ResponseMessage; import leets.weeth.global.auth.annotation.CurrentUser; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/leets/weeth/domain/board/presentation/PostController.java b/src/main/java/leets/weeth/domain/board/presentation/PostController.java index d5391272..a9a7e59e 100644 --- a/src/main/java/leets/weeth/domain/board/presentation/PostController.java +++ b/src/main/java/leets/weeth/domain/board/presentation/PostController.java @@ -4,7 +4,7 @@ import leets.weeth.domain.board.application.dto.PostDTO; import leets.weeth.domain.board.application.usecase.PostUsecase; import leets.weeth.global.auth.annotation.CurrentUser; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/CommentNotFoundException.java b/src/main/java/leets/weeth/domain/comment/application/exception/CommentNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/CommentNotFoundException.java rename to src/main/java/leets/weeth/domain/comment/application/exception/CommentNotFoundException.java index 15cb3465..75dbbe60 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/CommentNotFoundException.java +++ b/src/main/java/leets/weeth/domain/comment/application/exception/CommentNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.comment.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecase.java b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecase.java index 4a216cf2..0e613231 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecase.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecase.java @@ -1,7 +1,7 @@ package leets.weeth.domain.comment.application.usecase; import leets.weeth.domain.comment.application.dto.CommentDTO; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; public interface NoticeCommentUsecase { diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java index 5fbd7ac9..7cd8fde1 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/NoticeCommentUsecaseImpl.java @@ -10,10 +10,9 @@ import leets.weeth.domain.comment.domain.service.CommentSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.global.common.error.exception.custom.CommentNotFoundException; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.comment.application.exception.CommentNotFoundException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecase.java b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecase.java index 289bd674..b40410b8 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecase.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecase.java @@ -1,7 +1,7 @@ package leets.weeth.domain.comment.application.usecase; import leets.weeth.domain.comment.application.dto.CommentDTO; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; public interface PostCommentUsecase { diff --git a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java index d580ea68..314987a2 100644 --- a/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java +++ b/src/main/java/leets/weeth/domain/comment/application/usecase/PostCommentUsecaseImpl.java @@ -10,8 +10,8 @@ import leets.weeth.domain.comment.domain.service.CommentSaveService; import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.service.UserGetService; -import leets.weeth.global.common.error.exception.custom.CommentNotFoundException; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.comment.application.exception.CommentNotFoundException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/leets/weeth/domain/comment/domain/service/CommentFindService.java b/src/main/java/leets/weeth/domain/comment/domain/service/CommentFindService.java index ba3c0390..f7ed3442 100644 --- a/src/main/java/leets/weeth/domain/comment/domain/service/CommentFindService.java +++ b/src/main/java/leets/weeth/domain/comment/domain/service/CommentFindService.java @@ -2,7 +2,7 @@ import leets.weeth.domain.comment.domain.entity.Comment; import leets.weeth.domain.comment.domain.repository.CommentRepository; -import leets.weeth.global.common.error.exception.custom.CommentNotFoundException; +import leets.weeth.domain.comment.application.exception.CommentNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/comment/presentation/NoticeCommentController.java b/src/main/java/leets/weeth/domain/comment/presentation/NoticeCommentController.java index 8b27def2..ad4522e5 100644 --- a/src/main/java/leets/weeth/domain/comment/presentation/NoticeCommentController.java +++ b/src/main/java/leets/weeth/domain/comment/presentation/NoticeCommentController.java @@ -3,10 +3,8 @@ import jakarta.validation.Valid; import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.comment.application.usecase.NoticeCommentUsecase; -import leets.weeth.domain.comment.application.usecase.PostCommentUsecase; -import leets.weeth.domain.comment.domain.entity.enums.ResponseMessage; import leets.weeth.global.auth.annotation.CurrentUser; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/leets/weeth/domain/comment/presentation/PostCommentController.java b/src/main/java/leets/weeth/domain/comment/presentation/PostCommentController.java index 4e8bda87..00416f27 100644 --- a/src/main/java/leets/weeth/domain/comment/presentation/PostCommentController.java +++ b/src/main/java/leets/weeth/domain/comment/presentation/PostCommentController.java @@ -3,9 +3,8 @@ import jakarta.validation.Valid; import leets.weeth.domain.comment.application.dto.CommentDTO; import leets.weeth.domain.comment.application.usecase.PostCommentUsecase; -import leets.weeth.domain.comment.domain.entity.enums.ResponseMessage; import leets.weeth.global.auth.annotation.CurrentUser; -import leets.weeth.global.common.error.exception.custom.UserNotMatchException; +import leets.weeth.domain.user.application.exception.UserNotMatchException; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/PenaltyNotFoundException.java b/src/main/java/leets/weeth/domain/penalty/application/exception/PenaltyNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/PenaltyNotFoundException.java rename to src/main/java/leets/weeth/domain/penalty/application/exception/PenaltyNotFoundException.java index f63ff2c6..7034a6ef 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/PenaltyNotFoundException.java +++ b/src/main/java/leets/weeth/domain/penalty/application/exception/PenaltyNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.penalty.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/penalty/domain/service/PenaltyFindService.java b/src/main/java/leets/weeth/domain/penalty/domain/service/PenaltyFindService.java index 8f8bfbd4..88de0c4e 100644 --- a/src/main/java/leets/weeth/domain/penalty/domain/service/PenaltyFindService.java +++ b/src/main/java/leets/weeth/domain/penalty/domain/service/PenaltyFindService.java @@ -2,7 +2,7 @@ import leets.weeth.domain.penalty.domain.entity.Penalty; import leets.weeth.domain.penalty.domain.repository.PenaltyRepository; -import leets.weeth.global.common.error.exception.custom.PenaltyNotFoundException; +import leets.weeth.domain.penalty.application.exception.PenaltyNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/EventNotFoundException.java b/src/main/java/leets/weeth/domain/schedule/application/exception/EventNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/EventNotFoundException.java rename to src/main/java/leets/weeth/domain/schedule/application/exception/EventNotFoundException.java index 2ade0bbf..66423600 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/EventNotFoundException.java +++ b/src/main/java/leets/weeth/domain/schedule/application/exception/EventNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.schedule.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/MeetingNotFoundException.java b/src/main/java/leets/weeth/domain/schedule/application/exception/MeetingNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/MeetingNotFoundException.java rename to src/main/java/leets/weeth/domain/schedule/application/exception/MeetingNotFoundException.java index eae2d07b..9c7a4d09 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/MeetingNotFoundException.java +++ b/src/main/java/leets/weeth/domain/schedule/application/exception/MeetingNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.schedule.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/schedule/domain/service/EventGetService.java b/src/main/java/leets/weeth/domain/schedule/domain/service/EventGetService.java index 27f68f2f..226f0f8d 100644 --- a/src/main/java/leets/weeth/domain/schedule/domain/service/EventGetService.java +++ b/src/main/java/leets/weeth/domain/schedule/domain/service/EventGetService.java @@ -4,7 +4,7 @@ import leets.weeth.domain.schedule.application.mapper.ScheduleMapper; import leets.weeth.domain.schedule.domain.entity.Event; import leets.weeth.domain.schedule.domain.repository.EventRepository; -import leets.weeth.global.common.error.exception.custom.EventNotFoundException; +import leets.weeth.domain.schedule.application.exception.EventNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/schedule/domain/service/MeetingGetService.java b/src/main/java/leets/weeth/domain/schedule/domain/service/MeetingGetService.java index 91b40845..65fd655c 100644 --- a/src/main/java/leets/weeth/domain/schedule/domain/service/MeetingGetService.java +++ b/src/main/java/leets/weeth/domain/schedule/domain/service/MeetingGetService.java @@ -4,7 +4,7 @@ import leets.weeth.domain.schedule.application.mapper.ScheduleMapper; import leets.weeth.domain.schedule.domain.entity.Meeting; import leets.weeth.domain.schedule.domain.repository.MeetingRepository; -import leets.weeth.global.common.error.exception.custom.MeetingNotFoundException; +import leets.weeth.domain.schedule.application.exception.MeetingNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/CardinalNotFoundException.java b/src/main/java/leets/weeth/domain/user/application/exception/CardinalNotFoundException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/CardinalNotFoundException.java rename to src/main/java/leets/weeth/domain/user/application/exception/CardinalNotFoundException.java index 5c13e501..07943154 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/CardinalNotFoundException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/CardinalNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/DepartmentNotFoundException.java b/src/main/java/leets/weeth/domain/user/application/exception/DepartmentNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/DepartmentNotFoundException.java rename to src/main/java/leets/weeth/domain/user/application/exception/DepartmentNotFoundException.java index 5be4d1db..a60959f8 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/DepartmentNotFoundException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/DepartmentNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java b/src/main/java/leets/weeth/domain/user/application/exception/StudentIdExistsException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java rename to src/main/java/leets/weeth/domain/user/application/exception/StudentIdExistsException.java index 2a968e91..ee184eed 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/StudentIdExistsException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/StudentIdExistsException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java b/src/main/java/leets/weeth/domain/user/application/exception/TelExistsException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java rename to src/main/java/leets/weeth/domain/user/application/exception/TelExistsException.java index c95a0d6b..d98c0ff4 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/TelExistsException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/TelExistsException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/UserExistsException.java b/src/main/java/leets/weeth/domain/user/application/exception/UserExistsException.java similarity index 78% rename from src/main/java/leets/weeth/global/common/error/exception/custom/UserExistsException.java rename to src/main/java/leets/weeth/domain/user/application/exception/UserExistsException.java index c19ba702..26bf80db 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/UserExistsException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/UserExistsException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/user/application/exception/UserMismatchException.java b/src/main/java/leets/weeth/domain/user/application/exception/UserMismatchException.java new file mode 100644 index 00000000..35da8c04 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/exception/UserMismatchException.java @@ -0,0 +1,9 @@ +package leets.weeth.domain.user.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class UserMismatchException extends BusinessLogicException { + public UserMismatchException() { + super(400, "사용자가 현재 사용자와 일치하지 않습니다."); + } +} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/UserNotFoundException.java b/src/main/java/leets/weeth/domain/user/application/exception/UserNotFoundException.java similarity index 79% rename from src/main/java/leets/weeth/global/common/error/exception/custom/UserNotFoundException.java rename to src/main/java/leets/weeth/domain/user/application/exception/UserNotFoundException.java index 8f10bd39..32d87ed4 100644 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/UserNotFoundException.java +++ b/src/main/java/leets/weeth/domain/user/application/exception/UserNotFoundException.java @@ -1,4 +1,4 @@ -package leets.weeth.global.common.error.exception.custom; +package leets.weeth.domain.user.application.exception; import jakarta.persistence.EntityNotFoundException; diff --git a/src/main/java/leets/weeth/domain/user/application/exception/UserNotMatchException.java b/src/main/java/leets/weeth/domain/user/application/exception/UserNotMatchException.java new file mode 100644 index 00000000..45c9c330 --- /dev/null +++ b/src/main/java/leets/weeth/domain/user/application/exception/UserNotMatchException.java @@ -0,0 +1,7 @@ +package leets.weeth.domain.user.application.exception; + +import leets.weeth.global.common.exception.BusinessLogicException; + +public class UserNotMatchException extends BusinessLogicException { + public UserNotMatchException() {super(400, "생성한 사용자와 일치하지 않습니다.");} +} diff --git a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java index 8a87abee..3a724785 100644 --- a/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/user/application/usecase/UserUseCaseImpl.java @@ -10,8 +10,8 @@ import leets.weeth.domain.user.domain.service.UserGetService; import leets.weeth.domain.user.domain.service.UserSaveService; import leets.weeth.domain.user.domain.service.UserUpdateService; -import leets.weeth.global.common.error.exception.custom.StudentIdExistsException; -import leets.weeth.global.common.error.exception.custom.TelExistsException; +import leets.weeth.domain.user.application.exception.StudentIdExistsException; +import leets.weeth.domain.user.application.exception.TelExistsException; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/domain/user/domain/entity/User.java b/src/main/java/leets/weeth/domain/user/domain/entity/User.java index 73425923..2d6062c0 100644 --- a/src/main/java/leets/weeth/domain/user/domain/entity/User.java +++ b/src/main/java/leets/weeth/domain/user/domain/entity/User.java @@ -10,7 +10,7 @@ import leets.weeth.domain.user.domain.entity.enums.Role; import leets.weeth.domain.user.domain.entity.enums.Status; import leets.weeth.global.common.entity.BaseEntity; -import leets.weeth.global.common.error.exception.custom.CardinalNotFoundException; +import leets.weeth.domain.user.application.exception.CardinalNotFoundException; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/leets/weeth/domain/user/domain/entity/enums/Department.java b/src/main/java/leets/weeth/domain/user/domain/entity/enums/Department.java index 90a2d368..274ce78a 100644 --- a/src/main/java/leets/weeth/domain/user/domain/entity/enums/Department.java +++ b/src/main/java/leets/weeth/domain/user/domain/entity/enums/Department.java @@ -1,6 +1,6 @@ package leets.weeth.domain.user.domain.entity.enums; -import leets.weeth.global.common.error.exception.custom.DepartmentNotFoundException; +import leets.weeth.domain.user.application.exception.DepartmentNotFoundException; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java index 09818749..83243e38 100644 --- a/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java +++ b/src/main/java/leets/weeth/domain/user/domain/service/UserGetService.java @@ -3,7 +3,7 @@ import leets.weeth.domain.user.domain.entity.User; import leets.weeth.domain.user.domain.entity.enums.Status; import leets.weeth.domain.user.domain.repository.UserRepository; -import leets.weeth.global.common.error.exception.custom.UserNotFoundException; +import leets.weeth.domain.user.application.exception.UserNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/leets/weeth/global/common/error/CommonExceptionController.java b/src/main/java/leets/weeth/global/common/error/CommonExceptionController.java deleted file mode 100644 index 0a375e21..00000000 --- a/src/main/java/leets/weeth/global/common/error/CommonExceptionController.java +++ /dev/null @@ -1,56 +0,0 @@ -package leets.weeth.global.common.error; - -import leets.weeth.global.common.error.exception.ExceptionType; -import leets.weeth.global.common.response.CommonResponse; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.BindException; -import org.springframework.web.ErrorResponse; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -import java.util.Optional; - -@Slf4j -@RestControllerAdvice -public class CommonExceptionController { - - private static final String INPUT_FORMAT_ERROR_MESSAGE = "입력 포맷이 올바르지 않습니다."; - - @ExceptionHandler(Exception.class) // 모든 Exception 처리 - public CommonResponse handle(Exception ex) { - int status = 500; - - Optional e = ExceptionType.findException(ex); // ExceptionType 찾기 - if (e.isPresent()) { // 클라이언트 오류 시 - status = e.get().getHttpStatus().value(); // 상태 값 4XX로 설정 - } - log.error("Error", ex); - - return CommonResponse.createFailure(status, ex.getMessage()); - } - - @ExceptionHandler(BindException.class) // BindException == @ModelAttribute 어노테이션으로 받은 파라미터의 @Valid 통해 발생한 Exception - public CommonResponse handle(BindException e) { // 클라이언트의 오류일 경우 - int status = 400; // 파라미터 값 실수이므로 4XX - - if (e instanceof ErrorResponse) { // Exception이 ErrorResponse의 인스턴스라면 - status = ((ErrorResponse) e).getStatusCode().value(); // ErrorResponse에서 상태 값 가져오기 - } - log.error("Error", e); - - return CommonResponse.createFailure(status, e.getFieldError().getField() + " : " + e.getFieldError().getDefaultMessage()); - } - - @ExceptionHandler(MethodArgumentTypeMismatchException.class) // MethodArgumentTypeMismatchException == 클라이언트가 날짜 포맷을 다르게 입력한 경우 - public CommonResponse handle(MethodArgumentTypeMismatchException e) { - int status = 400; // 파라미터 값 실수이므로 4XX - - if (e instanceof ErrorResponse) { // Exception이 ErrorResponse의 인스턴스라면 - status = ((ErrorResponse) e).getStatusCode().value(); // ErrorResponse에서 상태 값 가져오기 - } - log.error("Error", e); - - return CommonResponse.createFailure(status, INPUT_FORMAT_ERROR_MESSAGE); - } -} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java b/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java deleted file mode 100644 index 6863b3cf..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/ExceptionType.java +++ /dev/null @@ -1,45 +0,0 @@ -package leets.weeth.global.common.error.exception; - -import jakarta.persistence.EntityExistsException; -import jakarta.persistence.EntityNotFoundException; -import leets.weeth.global.common.error.exception.custom.*; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; - -import java.util.Arrays; -import java.util.Optional; - -@Getter -@RequiredArgsConstructor -public enum ExceptionType { - ENTITY_NOT_FOUND(HttpStatus.BAD_REQUEST, EntityNotFoundException.class), - ENTITY_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, EntityExistsException.class), - BUSINESS_LOGIC_ERROR(HttpStatus.BAD_REQUEST, BusinessLogicException.class), - TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, TypeNotMatchException.class), - USER_NOT_MATCH(HttpStatus.BAD_REQUEST, UserNotMatchException.class), - USER_NOT_FOUND(HttpStatus.BAD_REQUEST, UserNotFoundException.class), - USER_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, UserExistsException.class), - INVALID_ACCESS_EXCEPTION(HttpStatus.BAD_REQUEST, InvalidAccessException.class), - NOTICE_NOT_FOUND(HttpStatus.BAD_REQUEST, NoticeNotFoundException.class), - EVENT_NOT_FOUND(HttpStatus.BAD_REQUEST, EventNotFoundException.class), - POST_NOT_FOUND(HttpStatus.BAD_REQUEST, PostNotFoundException.class), - PENALTY_NOT_FOUND(HttpStatus.BAD_REQUEST, PenaltyNotFoundException.class), - COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST, CommentNotFoundException.class), - INVALID_INPUT_DATE(HttpStatus.BAD_REQUEST, InvalidInputDateException.class), - NOTICE_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, NoticeTypeNotMatchException.class), - ACCOUNT_NOT_FOUND(HttpStatus.BAD_REQUEST, AccountNotFoundException.class), - ACCOUNT_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, AccountExistsException.class), - ATTENDANCE_EVENT_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, AttendanceEventTypeNotMatchException.class), - STUDENT_ID_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, StudentIdExistsException.class), - TEL_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, TelExistsException.class); - - private final HttpStatus httpStatus; - private final Class type; - - public static Optional findException(Exception ex) { - return Arrays.stream(ExceptionType.values()) - .filter(e -> e.getType().equals(ex.getClass())) // 클래스 타입 - .findAny(); - } -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceCodeMismatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceCodeMismatchException.java deleted file mode 100644 index 3d79d2ab..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceCodeMismatchException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class AttendanceCodeMismatchException extends BusinessLogicException { - public AttendanceCodeMismatchException() {super("출석 코드가 일치하지 않습니다.");} -} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceEventTypeNotMatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceEventTypeNotMatchException.java deleted file mode 100644 index 879018c8..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/AttendanceEventTypeNotMatchException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class AttendanceEventTypeNotMatchException extends TypeNotMatchException{ - public AttendanceEventTypeNotMatchException() {super("출석일정은 직접 수정할 수 없습니다.");} -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/BusinessLogicException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/BusinessLogicException.java deleted file mode 100644 index f5952293..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/BusinessLogicException.java +++ /dev/null @@ -1,7 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class BusinessLogicException extends Exception { - public BusinessLogicException(String message) { - super(message); - } -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidAccessException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidAccessException.java deleted file mode 100644 index 01093cb1..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidAccessException.java +++ /dev/null @@ -1,7 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class InvalidAccessException extends BusinessLogicException { - public InvalidAccessException() { - super("잘못된 접근입니다."); - } -} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidInputDateException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidInputDateException.java deleted file mode 100644 index c45a7b71..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/InvalidInputDateException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class InvalidInputDateException extends BusinessLogicException { - public InvalidInputDateException() {super("입력한 날짜가 올바르지 않습니다.");} -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/NoticeTypeNotMatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/NoticeTypeNotMatchException.java deleted file mode 100644 index 3357314c..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/NoticeTypeNotMatchException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class NoticeTypeNotMatchException extends TypeNotMatchException{ - public NoticeTypeNotMatchException() {super("공지사항은 공지사항 게시판에서 수정하세요.");} -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/TypeNotMatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/TypeNotMatchException.java deleted file mode 100644 index 325b0d73..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/TypeNotMatchException.java +++ /dev/null @@ -1,9 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class TypeNotMatchException extends BusinessLogicException{ - public TypeNotMatchException() {super("타입이 맞지 않습니다.(NOTICE, EVENT, ATTENDANCE)");} - - public TypeNotMatchException(String message) { - super(message); - } -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/UserMismatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/UserMismatchException.java deleted file mode 100644 index f000ed08..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/UserMismatchException.java +++ /dev/null @@ -1,7 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class UserMismatchException extends BusinessLogicException { - public UserMismatchException() { - super("사용자가 현재 사용자와 일치하지 않습니다."); - } -} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/UserNotMatchException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/UserNotMatchException.java deleted file mode 100644 index 44a83f32..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/UserNotMatchException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class UserNotMatchException extends BusinessLogicException{ - public UserNotMatchException() {super("생성한 사용자와 일치하지 않습니다.");} -} diff --git a/src/main/java/leets/weeth/global/common/error/exception/custom/WeekNotFoundException.java b/src/main/java/leets/weeth/global/common/error/exception/custom/WeekNotFoundException.java deleted file mode 100644 index e9d6e5d0..00000000 --- a/src/main/java/leets/weeth/global/common/error/exception/custom/WeekNotFoundException.java +++ /dev/null @@ -1,5 +0,0 @@ -package leets.weeth.global.common.error.exception.custom; - -public class WeekNotFoundException extends BusinessLogicException { - public WeekNotFoundException() {super("존재하지 않는 주차정보입니다.");} -} diff --git a/src/main/java/leets/weeth/global/common/exception/BindExceptionResponse.java b/src/main/java/leets/weeth/global/common/exception/BindExceptionResponse.java new file mode 100644 index 00000000..b56e1539 --- /dev/null +++ b/src/main/java/leets/weeth/global/common/exception/BindExceptionResponse.java @@ -0,0 +1,10 @@ +package leets.weeth.global.common.exception; + +import lombok.Builder; + +@Builder +public record BindExceptionResponse( + String message, + Object value +) { +} diff --git a/src/main/java/leets/weeth/global/common/exception/BusinessLogicException.java b/src/main/java/leets/weeth/global/common/exception/BusinessLogicException.java new file mode 100644 index 00000000..fef8f249 --- /dev/null +++ b/src/main/java/leets/weeth/global/common/exception/BusinessLogicException.java @@ -0,0 +1,14 @@ +package leets.weeth.global.common.exception; + +import lombok.Getter; + +@Getter +public class BusinessLogicException extends RuntimeException { + + private final int statusCode; + + public BusinessLogicException(int code, String message) { + super(message); + this.statusCode = code; + } +} diff --git a/src/main/java/leets/weeth/global/common/exception/CommonExceptionHandler.java b/src/main/java/leets/weeth/global/common/exception/CommonExceptionHandler.java new file mode 100644 index 00000000..c0f53c8f --- /dev/null +++ b/src/main/java/leets/weeth/global/common/exception/CommonExceptionHandler.java @@ -0,0 +1,95 @@ +package leets.weeth.global.common.exception; + +import leets.weeth.global.common.response.CommonResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindException; +import org.springframework.web.ErrorResponse; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestControllerAdvice +public class CommonExceptionHandler { + + private static final String INPUT_FORMAT_ERROR_MESSAGE = "입력 포맷이 올바르지 않습니다."; + private static final String LOG_FORMAT = "Class : {}, Code : {}, Message : {}"; + + @ExceptionHandler(BusinessLogicException.class) // 커스텀 예외 처리 + public ResponseEntity> handle(BusinessLogicException ex) { + log.warn("구체로그: ", ex); + log.warn(LOG_FORMAT, ex.getClass().getSimpleName(), ex.getStatusCode(), ex.getMessage()); + + CommonResponse response = CommonResponse.createFailure(ex.getStatusCode(), ex.getMessage()); + + return ResponseEntity + .status(ex.getStatusCode()) + .body(response); + } + + @ExceptionHandler(BindException.class) // BindException == @ModelAttribute 어노테이션으로 받은 파라미터의 @Valid 통해 발생한 Exception + public ResponseEntity>> handle(BindException ex) { + int statusCode = 400; + List exceptionResponses = new ArrayList<>(); + + if (ex instanceof ErrorResponse) { + statusCode = ((ErrorResponse) ex).getStatusCode().value(); + ex.getBindingResult().getFieldErrors().forEach(fieldError -> { + exceptionResponses.add(BindExceptionResponse.builder() + .message(fieldError.getDefaultMessage()) + .value(fieldError.getRejectedValue()) + .build()); + }); + } + + log.warn("구체로그: ", ex); + log.warn(LOG_FORMAT, ex.getClass().getSimpleName(), statusCode, exceptionResponses); + + CommonResponse> response = CommonResponse.createFailure(statusCode, "bindException", exceptionResponses); + + return ResponseEntity + .status(statusCode) + .body(response); + } + + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + // MethodArgumentTypeMismatchException == 클라이언트가 날짜 포맷을 다르게 입력한 경우 + public ResponseEntity> handle(MethodArgumentTypeMismatchException ex) { + int statusCode = 400; // 파라미터 값 실수이므로 4XX + + if (ex instanceof ErrorResponse) { // Exception이 ErrorResponse의 인스턴스라면 + statusCode = ((ErrorResponse) ex).getStatusCode().value(); // ErrorResponse에서 상태 값 가져오기 + } + + log.warn("구체로그: ", ex); + log.warn(LOG_FORMAT, ex.getClass().getSimpleName(), statusCode, ex.getMessage()); + + CommonResponse response = CommonResponse.createFailure(statusCode, INPUT_FORMAT_ERROR_MESSAGE); + + return ResponseEntity + .status(statusCode) + .body(response); + } + + @ExceptionHandler(Exception.class) // 모든 Exception 처리 + public ResponseEntity> handle(Exception ex) { + int statusCode = 500; + + if (ex instanceof ErrorResponse) { // Exception이 ErrorResponse의 인스턴스라면 (http status를 가지는 예외) + statusCode = ((ErrorResponse) ex).getStatusCode().value(); // ErrorResponse에서 상태 값 가져오기 + } + + log.warn("구체로그: ", ex); + log.warn(LOG_FORMAT, ex.getClass().getSimpleName(), statusCode, ex.getMessage()); + + CommonResponse response = CommonResponse.createFailure(statusCode, ex.getMessage()); + + return ResponseEntity + .status(statusCode) + .body(response); + } +} \ No newline at end of file diff --git a/src/main/java/leets/weeth/global/common/response/CommonResponse.java b/src/main/java/leets/weeth/global/common/response/CommonResponse.java index d77af37a..3facee6f 100644 --- a/src/main/java/leets/weeth/global/common/response/CommonResponse.java +++ b/src/main/java/leets/weeth/global/common/response/CommonResponse.java @@ -21,6 +21,10 @@ public static CommonResponse createFailure(int code, String message) { return new CommonResponse<>(code, message, null); } + public static CommonResponse createFailure(int code, String message, T data) { // 실패 + return new CommonResponse<>(code, message, data); + } + public CommonResponse(int code, String message, T data) { this.code = code; this.message = message;