From 1d1a1623270f42e362d41cf2a4b64f901bef3f3d Mon Sep 17 00:00:00 2001 From: shinyeongwoon Date: Fri, 16 Aug 2024 15:38:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?SB-254=20(feat)=20:=20=EC=9E=85=EA=B3=A0=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=84=9C=20=EC=A1=B0=ED=9A=8C=20(=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20:=20TAKING=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SB-254 (feat) : 입고 요청서 조회 ( 상태 : TAKING ) 1. errorCode 및 Exception - 차후 공통화 예정 2. Receiving 요청서 목록 조회 - Receiving Controller, Business, Service, Converter 구현 - Goods Business, Service, Converter 구현 - User Business, Service, Converter 구현 --- .../domain/receiving/ReceivingRepository.java | 3 + .../delivery/common/error/GoodsErrorCode.java | 22 +++++++ .../delivery/common/error/ImageErrorCode.java | 22 +++++++ .../common/error/ReceivingErrorCode.java | 19 ++++++ .../common/error/ShippingErrorCode.java | 18 ++++++ .../common/error/TakeBackErrorCode.java | 20 ++++++ .../delivery/common/error/TokenErrorCode.java | 24 +++++++ .../common/error/UsedGoodsErrorCode.java | 20 ++++++ .../delivery/common/error/UserErrorCode.java | 24 +++++++ .../common/exception/ApiException.java | 35 +++++++++++ .../exception/GoodsExceptionHandler.java | 40 ++++++++++++ .../exception/ReceivingExceptionHandler.java | 32 ++++++++++ .../exception/ShippingExceptionHandler.java | 23 +++++++ .../exception/TakeBackExceptionHandler.java | 32 ++++++++++ .../exception/UsedGoodsExceptionHandler.java | 31 +++++++++ .../exception/UserExceptionHandler.java | 63 +++++++++++++++++++ .../exception/ValidationExceptionHandler.java | 22 +++++++ .../goods/GoodsNotFoundException.java | 33 ++++++++++ .../goods/GoodsStrategyException.java | 33 ++++++++++ .../goods/InvalidGoodsStatusException.java | 33 ++++++++++ .../receiving/NoOwnershipException.java | 35 +++++++++++ .../receiving/NotOwnerException.java | 36 +++++++++++ .../receiving/ReceivingNotFoundException.java | 36 +++++++++++ .../shipping/ShippingNotFoundException.java | 34 ++++++++++ .../takeback/NotFoundRequestException.java | 34 ++++++++++ .../takeback/TakeBackNotAllowedException.java | 34 ++++++++++ .../usedGoods/GoodsNotInUsedStatus.java | 34 ++++++++++ .../usedGoods/UsedGoodsNotFoundException.java | 34 ++++++++++ .../user/AddressNotFoundException.java | 33 ++++++++++ .../exception/user/ExistUserException.java | 33 ++++++++++ .../user/FailedToRegisterException.java | 36 +++++++++++ .../common/exception/user/LogInException.java | 35 +++++++++++ .../exception/user/UserNotFoundException.java | 33 ++++++++++ .../user/UserUnregisterException.java | 33 ++++++++++ .../goods/converter/GoodsConverter.java | 8 +++ .../domain/goods/service/GoodsService.java | 18 ++++++ .../receiving/business/ReceivingBusiness.java | 58 +++++++++++++++++ .../controller/ReceivingApiController.java | 24 +++++++ .../controller/model/ReceivingResponse.java | 30 +++++++++ .../model/ReceivingResponseList.java | 13 ++++ .../converter/ReceivingConverter.java | 32 ++++++++++ .../receiving/service/ReceivingService.java | 28 +++++++++ .../domain/users/converter/UserConverter.java | 8 +++ .../domain/users/service/UserService.java | 20 ++++++ 44 files changed, 1268 insertions(+) create mode 100644 delivery/src/main/java/delivery/common/error/GoodsErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/ImageErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/ShippingErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/TakeBackErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/TokenErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/UsedGoodsErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/error/UserErrorCode.java create mode 100644 delivery/src/main/java/delivery/common/exception/ApiException.java create mode 100644 delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/TakeBackExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/UsedGoodsExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/UserExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/ValidationExceptionHandler.java create mode 100644 delivery/src/main/java/delivery/common/exception/goods/GoodsNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/goods/GoodsStrategyException.java create mode 100644 delivery/src/main/java/delivery/common/exception/goods/InvalidGoodsStatusException.java create mode 100644 delivery/src/main/java/delivery/common/exception/receiving/NoOwnershipException.java create mode 100644 delivery/src/main/java/delivery/common/exception/receiving/NotOwnerException.java create mode 100644 delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/shipping/ShippingNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/takeback/NotFoundRequestException.java create mode 100644 delivery/src/main/java/delivery/common/exception/takeback/TakeBackNotAllowedException.java create mode 100644 delivery/src/main/java/delivery/common/exception/usedGoods/GoodsNotInUsedStatus.java create mode 100644 delivery/src/main/java/delivery/common/exception/usedGoods/UsedGoodsNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/AddressNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/ExistUserException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/FailedToRegisterException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/LogInException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/UserNotFoundException.java create mode 100644 delivery/src/main/java/delivery/common/exception/user/UserUnregisterException.java create mode 100644 delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java create mode 100644 delivery/src/main/java/delivery/domain/goods/service/GoodsService.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponse.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponseList.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/converter/ReceivingConverter.java create mode 100644 delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java create mode 100644 delivery/src/main/java/delivery/domain/users/converter/UserConverter.java create mode 100644 delivery/src/main/java/delivery/domain/users/service/UserService.java diff --git a/db/src/main/java/db/domain/receiving/ReceivingRepository.java b/db/src/main/java/db/domain/receiving/ReceivingRepository.java index a0466819..91220ea2 100644 --- a/db/src/main/java/db/domain/receiving/ReceivingRepository.java +++ b/db/src/main/java/db/domain/receiving/ReceivingRepository.java @@ -1,5 +1,6 @@ package db.domain.receiving; +import db.domain.receiving.enums.ReceivingStatus; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,4 +10,6 @@ public interface ReceivingRepository extends JpaRepository findFirstById(Long receivingId); List findAllByUserIdOrderByIdDesc(Long userId); + + List findAllByStatusOrderByVisitDate(ReceivingStatus receivingStatus); } diff --git a/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java b/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java new file mode 100644 index 00000000..8068ad9a --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java @@ -0,0 +1,22 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GoodsErrorCode implements ErrorCodeIfs { + + GOODS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1200, "물품이 존재하지 않습니다."), + INVALID_GOODS_STATUS(HttpStatus.BAD_REQUEST.value(),1201,"잘못된 물품 상태입니다."), + INVALID_GOODS_STRATEGY(HttpStatus.BAD_REQUEST.value(), 1202, "요청서 종류가 잘못되었습니다."), + NOT_OWNER(HttpStatus.NOT_ACCEPTABLE.value(), 1203, "소유자가 아닙니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + +} diff --git a/delivery/src/main/java/delivery/common/error/ImageErrorCode.java b/delivery/src/main/java/delivery/common/error/ImageErrorCode.java new file mode 100644 index 00000000..08251372 --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/ImageErrorCode.java @@ -0,0 +1,22 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ImageErrorCode implements ErrorCodeIfs { + + IMAGE_STORAGE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1300, "이미지를 저장할 수 없습니다."), + NULL_POINT(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1301, "NULL POINT 입니다."), + IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1302, "요청하신 이미지를 찾을 수 없습니다."), + IMAGE_STORAGE_PATH_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), 1303, "업로드된 파일이 저장될 디렉터리를 생성할 수 없습니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java b/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java new file mode 100644 index 00000000..db47ae8a --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java @@ -0,0 +1,19 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ReceivingErrorCode implements ErrorCodeIfs { + + RECEIVING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1250, "입고 요청서가 존재하지 않습니다."), + NO_OWNERSHIP(HttpStatus.BAD_REQUEST.value(), 1251, "사용자의 물품이 아닙니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java b/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java new file mode 100644 index 00000000..d1e5d379 --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java @@ -0,0 +1,18 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ShippingErrorCode implements ErrorCodeIfs { + + SHIPPING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1500, "출고 요청서가 존재하지 않습니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; +} diff --git a/delivery/src/main/java/delivery/common/error/TakeBackErrorCode.java b/delivery/src/main/java/delivery/common/error/TakeBackErrorCode.java new file mode 100644 index 00000000..fd12c94e --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/TakeBackErrorCode.java @@ -0,0 +1,20 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum TakeBackErrorCode implements ErrorCodeIfs { + + TAKE_BAKE_NOT_ALLOWED(HttpStatus.BAD_REQUEST.value(), 1400, "반품을 진행할 수 없습니다."), + NOT_FOUNT_REQUEST(HttpStatus.BAD_REQUEST.value(), 1401, "반품 요청서를 찾을 수 없습니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + +} diff --git a/delivery/src/main/java/delivery/common/error/TokenErrorCode.java b/delivery/src/main/java/delivery/common/error/TokenErrorCode.java new file mode 100644 index 00000000..a0b8ec58 --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/TokenErrorCode.java @@ -0,0 +1,24 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum TokenErrorCode implements ErrorCodeIfs { + + NOT_AUTHENTICATION_USER(401,1100,"로그인이 필요합니다."), + NOT_AUTHORIZATION_USER(404,1101,"허가된 접근이 아닙니다."), + INVALID_TOKEN(401,1102,"유효하지 않은 토큰입니다."), + EXPIRED_TOKEN(401,1103,"만료된 토큰입니다."), + TOKEN_EXCEPTION(401,1104,"알 수 없는 토큰 에러입니다."), + NON_TOKEN_HEADER(401,1105,"인증 헤더 토큰이 없습니다."), + NO_EXPIRED_TOKEN(400,1106,"만료되지 않은 토큰입니다."), + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/error/UsedGoodsErrorCode.java b/delivery/src/main/java/delivery/common/error/UsedGoodsErrorCode.java new file mode 100644 index 00000000..73255c3e --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/UsedGoodsErrorCode.java @@ -0,0 +1,20 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum UsedGoodsErrorCode implements ErrorCodeIfs { + + USED_GOODS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1600, "중고 물품을 찾을 수 없습니다."), + GOODS_NOT_IN_USED_STATUS(HttpStatus.BAD_REQUEST.value(), 1601, "물품이 중고 전환 상태가 아닙니다."); + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + + } \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/error/UserErrorCode.java b/delivery/src/main/java/delivery/common/error/UserErrorCode.java new file mode 100644 index 00000000..e8d6aa58 --- /dev/null +++ b/delivery/src/main/java/delivery/common/error/UserErrorCode.java @@ -0,0 +1,24 @@ +package delivery.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum UserErrorCode implements ErrorCodeIfs { + + FAILED_TO_REGISTER(500, 1150, "회원가입이 실패했습니다."), + USER_NOT_FOUND(404, 1151, "사용자를 찾을 수 없습니다."), + UNREGISTERED_MEMBER(403, 1152, "탈퇴한 회원입니다."), + DORMANT_MEMBER(403, 1153, "휴면 계정입니다."), + EXIST_USER(403, 1154, "이미 존재하는 아이디입니다."), + LOGIN_FAIL(401, 1155, "로그인 정보가 일치하지 않습니다."), + ADDRESS_NOT_FOUND(404, 1156, "사용자의 주소를 찾을 수 없습니다."), + FAILED_TO_UNREGISTER(500, 1157, "회원 탈퇴에 실패했습니다."); + + private final Integer httpCode; + private final Integer errorCode; + private final String description; + +} diff --git a/delivery/src/main/java/delivery/common/exception/ApiException.java b/delivery/src/main/java/delivery/common/exception/ApiException.java new file mode 100644 index 00000000..c29a71b3 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/ApiException.java @@ -0,0 +1,35 @@ +package delivery.common.exception; + +import global.errorcode.ErrorCodeIfs; + +public class ApiException extends RuntimeException{ + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ApiException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ApiException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ApiException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ApiException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + +} diff --git a/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java new file mode 100644 index 00000000..438ae5a0 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java @@ -0,0 +1,40 @@ +package delivery.common.exception; + +import delivery.common.error.GoodsErrorCode; +import delivery.common.exception.goods.GoodsNotFoundException; +import delivery.common.exception.goods.InvalidGoodsStatusException; +import delivery.common.exception.receiving.NotOwnerException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +@Order(value = Integer.MIN_VALUE) +public class GoodsExceptionHandler { + + @ExceptionHandler(value = GoodsNotFoundException.class) + public ResponseEntity> imageException(GoodsNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(GoodsErrorCode.GOODS_NOT_FOUND)); + } + + @ExceptionHandler(value = InvalidGoodsStatusException.class) + public ResponseEntity> InvalidGoodsStatus(InvalidGoodsStatusException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(GoodsErrorCode.INVALID_GOODS_STATUS)); + } + + @ExceptionHandler(value = NotOwnerException.class) + public ResponseEntity> notOwnerException(NotOwnerException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(GoodsErrorCode.NOT_OWNER)); + } +} diff --git a/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java new file mode 100644 index 00000000..ec389060 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java @@ -0,0 +1,32 @@ +package delivery.common.exception; + +import delivery.common.error.ReceivingErrorCode; +import delivery.common.exception.receiving.NoOwnershipException; +import delivery.common.exception.receiving.ReceivingNotFoundException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +@Order(value = Integer.MIN_VALUE) +public class ReceivingExceptionHandler { + + @ExceptionHandler(value = ReceivingNotFoundException.class) + public ResponseEntity> imageException(ReceivingNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(ReceivingErrorCode.RECEIVING_REQUEST_NOT_FOUND)); + } + + @ExceptionHandler(value = NoOwnershipException.class) + public ResponseEntity> noOwnershipException(NoOwnershipException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(ReceivingErrorCode.NO_OWNERSHIP)); + } +} diff --git a/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java new file mode 100644 index 00000000..9cc14c38 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java @@ -0,0 +1,23 @@ +package delivery.common.exception; + +import delivery.common.error.ShippingErrorCode; +import delivery.common.exception.shipping.ShippingNotFoundException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class ShippingExceptionHandler { + + @ExceptionHandler(value = ShippingNotFoundException.class) + public ResponseEntity> shippingNotFoundException(ShippingNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(ShippingErrorCode.SHIPPING_REQUEST_NOT_FOUND)); + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/TakeBackExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/TakeBackExceptionHandler.java new file mode 100644 index 00000000..0d4b62ba --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/TakeBackExceptionHandler.java @@ -0,0 +1,32 @@ +package delivery.common.exception; + +import delivery.common.error.TakeBackErrorCode; +import delivery.common.exception.takeback.NotFoundRequestException; +import delivery.common.exception.takeback.TakeBackNotAllowedException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + + +@Slf4j +@RestControllerAdvice +public class TakeBackExceptionHandler { + + @ExceptionHandler(value = TakeBackNotAllowedException.class) + public ResponseEntity> takeBakeException(TakeBackNotAllowedException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(TakeBackErrorCode.TAKE_BAKE_NOT_ALLOWED)); + } + + @ExceptionHandler(value = NotFoundRequestException.class) + public ResponseEntity> notFoundRequestException(NotFoundRequestException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(TakeBackErrorCode.NOT_FOUNT_REQUEST)); + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/UsedGoodsExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/UsedGoodsExceptionHandler.java new file mode 100644 index 00000000..f5159f55 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/UsedGoodsExceptionHandler.java @@ -0,0 +1,31 @@ +package delivery.common.exception; + +import delivery.common.error.UsedGoodsErrorCode; +import delivery.common.exception.usedGoods.GoodsNotInUsedStatus; +import delivery.common.exception.usedGoods.UsedGoodsNotFoundException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class UsedGoodsExceptionHandler { + + @ExceptionHandler(value = UsedGoodsNotFoundException.class) + public ResponseEntity> usedGoodsNotFoundException(UsedGoodsNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(UsedGoodsErrorCode.USED_GOODS_NOT_FOUND)); + } + + @ExceptionHandler(value = GoodsNotInUsedStatus.class) + public ResponseEntity> goodsNotInUsedStatus(GoodsNotInUsedStatus e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(UsedGoodsErrorCode.GOODS_NOT_IN_USED_STATUS)); + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/UserExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/UserExceptionHandler.java new file mode 100644 index 00000000..2d26fee8 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/UserExceptionHandler.java @@ -0,0 +1,63 @@ +package delivery.common.exception; + +import delivery.common.error.UserErrorCode; +import delivery.common.exception.user.AddressNotFoundException; +import delivery.common.exception.user.ExistUserException; +import delivery.common.exception.user.FailedToRegisterException; +import delivery.common.exception.user.LogInException; +import delivery.common.exception.user.UserNotFoundException; +import delivery.common.exception.user.UserUnregisterException; +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class UserExceptionHandler { + + @ExceptionHandler(value = ExistUserException.class) + public ResponseEntity> existUserException(ExistUserException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.FORBIDDEN) + .body(Api.ERROR(UserErrorCode.EXIST_USER)); + } + + @ExceptionHandler(FailedToRegisterException.class) + public ResponseEntity> failedToRegisterException(FailedToRegisterException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Api.ERROR(UserErrorCode.FAILED_TO_REGISTER)); + } + + @ExceptionHandler(value = LogInException.class) + public ResponseEntity> logInException(LogInException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED) + .body(Api.ERROR(UserErrorCode.LOGIN_FAIL)); + } + + @ExceptionHandler(value = AddressNotFoundException.class) + public ResponseEntity> addressNotFoundException(AddressNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(UserErrorCode.ADDRESS_NOT_FOUND)); + } + + @ExceptionHandler(value = UserUnregisterException.class) + public ResponseEntity> userUnregisterException(UserUnregisterException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Api.ERROR(UserErrorCode.FAILED_TO_UNREGISTER)); + } + + @ExceptionHandler(value = UserNotFoundException.class) + public ResponseEntity> userNotFoundException(UserNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(UserErrorCode.USER_NOT_FOUND)); + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/ValidationExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/ValidationExceptionHandler.java new file mode 100644 index 00000000..29be1149 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/ValidationExceptionHandler.java @@ -0,0 +1,22 @@ +package delivery.common.exception; + +import global.api.Api; +import global.errorcode.ErrorCode; +import jakarta.validation.ValidationException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class ValidationExceptionHandler { + + @ExceptionHandler(value = ValidationException.class) + public ResponseEntity> validateException(ValidationException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(ErrorCode.INVALID_INPUT_DATA,e.getMessage())); + } +} diff --git a/delivery/src/main/java/delivery/common/exception/goods/GoodsNotFoundException.java b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotFoundException.java new file mode 100644 index 00000000..0e5e57a6 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotFoundException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/goods/GoodsStrategyException.java b/delivery/src/main/java/delivery/common/exception/goods/GoodsStrategyException.java new file mode 100644 index 00000000..ffbb2752 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/GoodsStrategyException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsStrategyException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsStrategyException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsStrategyException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsStrategyException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsStrategyException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/goods/InvalidGoodsStatusException.java b/delivery/src/main/java/delivery/common/exception/goods/InvalidGoodsStatusException.java new file mode 100644 index 00000000..6f212485 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/InvalidGoodsStatusException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class InvalidGoodsStatusException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public InvalidGoodsStatusException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public InvalidGoodsStatusException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public InvalidGoodsStatusException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public InvalidGoodsStatusException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/receiving/NoOwnershipException.java b/delivery/src/main/java/delivery/common/exception/receiving/NoOwnershipException.java new file mode 100644 index 00000000..bf2a0759 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/receiving/NoOwnershipException.java @@ -0,0 +1,35 @@ +package delivery.common.exception.receiving; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class NoOwnershipException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public NoOwnershipException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NoOwnershipException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public NoOwnershipException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NoOwnershipException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/receiving/NotOwnerException.java b/delivery/src/main/java/delivery/common/exception/receiving/NotOwnerException.java new file mode 100644 index 00000000..d5f82fb4 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/receiving/NotOwnerException.java @@ -0,0 +1,36 @@ +package delivery.common.exception.receiving; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class NotOwnerException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public NotOwnerException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NotOwnerException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public NotOwnerException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NotOwnerException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotFoundException.java b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotFoundException.java new file mode 100644 index 00000000..5b7aa252 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotFoundException.java @@ -0,0 +1,36 @@ +package delivery.common.exception.receiving; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class ReceivingNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ReceivingNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ReceivingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotFoundException.java b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotFoundException.java new file mode 100644 index 00000000..f4555fd8 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotFoundException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.shipping; + +import global.errorcode.ErrorCodeIfs; + +public class ShippingNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/takeback/NotFoundRequestException.java b/delivery/src/main/java/delivery/common/exception/takeback/NotFoundRequestException.java new file mode 100644 index 00000000..3b4ca405 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/takeback/NotFoundRequestException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.takeback; + +import global.errorcode.ErrorCodeIfs; + +public class NotFoundRequestException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public NotFoundRequestException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NotFoundRequestException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public NotFoundRequestException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public NotFoundRequestException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/takeback/TakeBackNotAllowedException.java b/delivery/src/main/java/delivery/common/exception/takeback/TakeBackNotAllowedException.java new file mode 100644 index 00000000..d2db55ed --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/takeback/TakeBackNotAllowedException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.takeback; + +import global.errorcode.ErrorCodeIfs; + +public class TakeBackNotAllowedException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public TakeBackNotAllowedException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public TakeBackNotAllowedException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public TakeBackNotAllowedException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public TakeBackNotAllowedException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/usedGoods/GoodsNotInUsedStatus.java b/delivery/src/main/java/delivery/common/exception/usedGoods/GoodsNotInUsedStatus.java new file mode 100644 index 00000000..ed5dc31c --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/usedGoods/GoodsNotInUsedStatus.java @@ -0,0 +1,34 @@ +package delivery.common.exception.usedGoods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsNotInUsedStatus extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsNotInUsedStatus(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInUsedStatus(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsNotInUsedStatus(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInUsedStatus(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/usedGoods/UsedGoodsNotFoundException.java b/delivery/src/main/java/delivery/common/exception/usedGoods/UsedGoodsNotFoundException.java new file mode 100644 index 00000000..b94cff03 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/usedGoods/UsedGoodsNotFoundException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.usedGoods; + +import global.errorcode.ErrorCodeIfs; + +public class UsedGoodsNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public UsedGoodsNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UsedGoodsNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public UsedGoodsNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UsedGoodsNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/user/AddressNotFoundException.java b/delivery/src/main/java/delivery/common/exception/user/AddressNotFoundException.java new file mode 100644 index 00000000..2a74bb11 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/AddressNotFoundException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; + +public class AddressNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public AddressNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public AddressNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public AddressNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public AddressNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/user/ExistUserException.java b/delivery/src/main/java/delivery/common/exception/user/ExistUserException.java new file mode 100644 index 00000000..55acb96a --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/ExistUserException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; + +public class ExistUserException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ExistUserException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ExistUserException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ExistUserException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ExistUserException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/user/FailedToRegisterException.java b/delivery/src/main/java/delivery/common/exception/user/FailedToRegisterException.java new file mode 100644 index 00000000..9f936857 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/FailedToRegisterException.java @@ -0,0 +1,36 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class FailedToRegisterException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public FailedToRegisterException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public FailedToRegisterException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public FailedToRegisterException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public FailedToRegisterException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} diff --git a/delivery/src/main/java/delivery/common/exception/user/LogInException.java b/delivery/src/main/java/delivery/common/exception/user/LogInException.java new file mode 100644 index 00000000..5e587d25 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/LogInException.java @@ -0,0 +1,35 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class LogInException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public LogInException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public LogInException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public LogInException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public LogInException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/user/UserNotFoundException.java b/delivery/src/main/java/delivery/common/exception/user/UserNotFoundException.java new file mode 100644 index 00000000..1f2af237 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/UserNotFoundException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; + +public class UserNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public UserNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UserNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public UserNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UserNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/common/exception/user/UserUnregisterException.java b/delivery/src/main/java/delivery/common/exception/user/UserUnregisterException.java new file mode 100644 index 00000000..9ea04a96 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/user/UserUnregisterException.java @@ -0,0 +1,33 @@ +package delivery.common.exception.user; + +import global.errorcode.ErrorCodeIfs; + +public class UserUnregisterException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public UserUnregisterException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UserUnregisterException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public UserUnregisterException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public UserUnregisterException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } +} diff --git a/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java b/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java new file mode 100644 index 00000000..e9ae98ed --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java @@ -0,0 +1,8 @@ +package delivery.domain.goods.converter; + +import global.annotation.Converter; + +@Converter +public class GoodsConverter { + +} diff --git a/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java b/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java new file mode 100644 index 00000000..c0ba4c49 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java @@ -0,0 +1,18 @@ +package delivery.domain.goods.service; + +import db.domain.goods.GoodsEntity; +import db.domain.goods.GoodsRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class GoodsService { + + private final GoodsRepository goodsRepository; + + public List getGoodsList(Long receivingId) { + return goodsRepository.findAllByReceivingIdOrderByIdDesc(receivingId); + } +} diff --git a/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java b/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java new file mode 100644 index 00000000..c2ba64ff --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java @@ -0,0 +1,58 @@ +package delivery.domain.receiving.business; + +import db.domain.goods.GoodsEntity; +import db.domain.receiving.ReceivingEntity; +import db.domain.users.UserEntity; +import delivery.domain.goods.converter.GoodsConverter; +import delivery.domain.goods.service.GoodsService; +import delivery.domain.receiving.controller.model.ReceivingResponseList; +import delivery.domain.receiving.converter.ReceivingConverter; +import delivery.domain.receiving.service.ReceivingService; +import delivery.domain.users.converter.UserConverter; +import delivery.domain.users.service.UserService; +import global.annotation.Business; +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +@Business +@RequiredArgsConstructor +public class ReceivingBusiness { + + private final ReceivingService receivingService; + private final ReceivingConverter receivingConverter; + private final UserService userService; + private final UserConverter userConverter; + private final GoodsService goodsService; + private final GoodsConverter goodsConverter; + + public ReceivingResponseList getReservationList() { + + List receivingEntityList = receivingService.getRequestList(); + + + ReceivingResponseList responseList = receivingConverter.toResponseList(receivingEntityList); + + receivingEntityList.forEach(receivingEntity -> { + + log.info("receivingList Id : {} " , receivingEntity.getId()); + + List goodsIdList = goodsService.getGoodsList(receivingEntity.getId()).stream().map( + goodsEntity -> { + return goodsEntity.getId(); + } + ).toList(); + + responseList.getReservationResponseList().forEach(reservationResponse -> { + reservationResponse.setGoodsIdList(goodsIdList); + reservationResponse.setUserName(userService.getUserBy(receivingEntity.getUserId()).getName()); + }); + + }); + + return responseList; + } +} diff --git a/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java b/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java new file mode 100644 index 00000000..0cca4aad --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java @@ -0,0 +1,24 @@ +package delivery.domain.receiving.controller; + +import delivery.domain.receiving.business.ReceivingBusiness; +import delivery.domain.receiving.controller.model.ReceivingResponseList; +import global.api.Api; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/reservation") +public class ReceivingApiController { + + private final ReceivingBusiness receivingBusiness; + + @GetMapping + public Api showReservationList(){ + ReceivingResponseList response = receivingBusiness.getReservationList(); + return Api.OK(response); + } + +} diff --git a/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponse.java b/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponse.java new file mode 100644 index 00000000..24ea850f --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponse.java @@ -0,0 +1,30 @@ +package delivery.domain.receiving.controller.model; + +import db.domain.receiving.enums.ReceivingStatus; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import java.time.LocalDateTime; +import java.util.List; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ReceivingResponse { + + private Long id; + + private LocalDateTime visitDate; + + private String visitAddress; + + private ReceivingStatus status; + + private LocalDateTime guaranteeAt; + + private String userName; + + private List goodsIdList; + +} diff --git a/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponseList.java b/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponseList.java new file mode 100644 index 00000000..f5565bdf --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/controller/model/ReceivingResponseList.java @@ -0,0 +1,13 @@ +package delivery.domain.receiving.controller.model; + +import java.util.List; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ReceivingResponseList { + + private List reservationResponseList ; + +} diff --git a/delivery/src/main/java/delivery/domain/receiving/converter/ReceivingConverter.java b/delivery/src/main/java/delivery/domain/receiving/converter/ReceivingConverter.java new file mode 100644 index 00000000..52f794aa --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/converter/ReceivingConverter.java @@ -0,0 +1,32 @@ +package delivery.domain.receiving.converter; + +import db.domain.receiving.ReceivingEntity; +import delivery.domain.receiving.controller.model.ReceivingResponse; +import delivery.domain.receiving.controller.model.ReceivingResponseList; +import global.annotation.Converter; +import java.util.List; + +@Converter +public class ReceivingConverter { + + public ReceivingResponseList toResponseList(List receivingEntityList){ + List responseList = receivingEntityList.stream().map(receivingEntity -> { + return toResponse(receivingEntity); + }).toList(); + + return ReceivingResponseList.builder() + .reservationResponseList(responseList) + .build(); + } + + private ReceivingResponse toResponse(ReceivingEntity receivingEntity) { + return ReceivingResponse.builder() + .id(receivingEntity.getId()) + .guaranteeAt(receivingEntity.getGuaranteeAt()) + .status(receivingEntity.getStatus()) + .visitAddress(receivingEntity.getVisitAddress()) + .visitDate(receivingEntity.getVisitDate()) + .build(); + } + +} diff --git a/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java b/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java new file mode 100644 index 00000000..784d9a47 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java @@ -0,0 +1,28 @@ +package delivery.domain.receiving.service; + +import db.domain.receiving.ReceivingEntity; +import db.domain.receiving.ReceivingRepository; +import db.domain.receiving.enums.ReceivingStatus; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class ReceivingService { + + private final ReceivingRepository receivingRepository; + + public List getRequestList() { + + List receivingEntityList = receivingRepository.findAllByStatusOrderByVisitDate(ReceivingStatus.TAKING); + + if(receivingEntityList.isEmpty()){ + throw new RuntimeException("존재하지 않음"); + } + + return receivingEntityList; + } +} diff --git a/delivery/src/main/java/delivery/domain/users/converter/UserConverter.java b/delivery/src/main/java/delivery/domain/users/converter/UserConverter.java new file mode 100644 index 00000000..c93897f3 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/users/converter/UserConverter.java @@ -0,0 +1,8 @@ +package delivery.domain.users.converter; + +import global.annotation.Converter; + +@Converter +public class UserConverter { + +} diff --git a/delivery/src/main/java/delivery/domain/users/service/UserService.java b/delivery/src/main/java/delivery/domain/users/service/UserService.java new file mode 100644 index 00000000..3814618c --- /dev/null +++ b/delivery/src/main/java/delivery/domain/users/service/UserService.java @@ -0,0 +1,20 @@ +package delivery.domain.users.service; + +import db.domain.users.UserEntity; +import db.domain.users.UsersRepository; +import delivery.common.error.UserErrorCode; +import delivery.common.exception.user.UserNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserService { + + private final UsersRepository usersRepository; + + public UserEntity getUserBy(Long userId) { + return usersRepository.findById(userId) + .orElseThrow(() -> new UserNotFoundException(UserErrorCode.USER_NOT_FOUND)); + } +} From a2722e4db878cd2d5ca743f71da99705efc4c49e Mon Sep 17 00:00:00 2001 From: JIUNG YANG Date: Sat, 17 Aug 2024 17:39:53 +0900 Subject: [PATCH 2/2] SB-255 (Chore) : Add Spring Cloud Gateway Module SB-255 (Chore) : Add Spring Cloud Gateway Module --- gateway/build.gradle | 46 +++++++++++++++++++ .../org/fx/gateway/GatewayApplication.java | 13 ++++++ settings.gradle | 1 + 3 files changed, 60 insertions(+) create mode 100644 gateway/build.gradle create mode 100644 gateway/src/main/java/org/fx/gateway/GatewayApplication.java diff --git a/gateway/build.gradle b/gateway/build.gradle new file mode 100644 index 00000000..c6e1a195 --- /dev/null +++ b/gateway/build.gradle @@ -0,0 +1,46 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'io.spring.dependency-management' +} + +group = 'org.fx' +version = '1.0-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +repositories { + mavenCentral() +} + +ext { + set('springCloudVersion', "2023.0.3") +} + +dependencies { + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + +test { + useJUnitPlatform() +} + +bootJar { + enabled = true +} + +jar { + enabled = false +} \ No newline at end of file diff --git a/gateway/src/main/java/org/fx/gateway/GatewayApplication.java b/gateway/src/main/java/org/fx/gateway/GatewayApplication.java new file mode 100644 index 00000000..b1f55c71 --- /dev/null +++ b/gateway/src/main/java/org/fx/gateway/GatewayApplication.java @@ -0,0 +1,13 @@ +package org.fx.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } + +} diff --git a/settings.gradle b/settings.gradle index cc3282ab..4e39ffca 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,5 @@ include 'db' include 'global' include 'warehouse' include 'delivery' +include 'gateway'