Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions BE/o2o/src/main/java/com/one/o2o/constants/ProductStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.one.o2o.constants;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ProductStatus {
MISSING(6),
BROKEN(7);

private final Integer statusId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.one.o2o.exception.products.ProductException;
import com.one.o2o.exception.products.report.ProductReportException;
import com.one.o2o.exception.products.request.ProductRequestException;
import com.one.o2o.exception.rent.RentException;
import com.one.o2o.exception.reserve.ReserveException;
import com.one.o2o.exception.user.UserException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
Expand Down Expand Up @@ -66,4 +68,22 @@ public ResponseEntity<ErrorResponse> handleProductRequestExceptionException(Prod
);
return new ResponseEntity<>(errorResponse, e.getErrorCode().getHttpStatus());
}

@ExceptionHandler(RentException.class)
public ResponseEntity<ErrorResponse> handleRentException(RentException e) {
ErrorResponse errorResponse = ErrorResponse.of(
e.getErrorCode(),
e.getMessage()
);
return new ResponseEntity<>(errorResponse, e.getErrorCode().getHttpStatus());
}

@ExceptionHandler(ReserveException.class)
public ResponseEntity<ErrorResponse> handleReserveException(ReserveException e) {
ErrorResponse errorResponse = ErrorResponse.of(
e.getErrorCode(),
e.getMessage()
);
return new ResponseEntity<>(errorResponse, e.getErrorCode().getHttpStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
public enum LockerErrorCode implements ErrorCode {
LOCKER_ID_INVALID(HttpStatus.BAD_REQUEST, "잘못된 locker ID입니다."),
LOCKER_ID_NEGATIVE(HttpStatus.BAD_REQUEST, "locker ID의 값은 1이상의 수입니다."),
LOCKER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 locker ID입니다.");
LOCKER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 locker ID입니다."),
TOTAL_COUNT_UNDER_PRODUCT_COUNT(HttpStatus.BAD_REQUEST, "올바르지 않은 물품 개수 입력입니다."),
PRODUCT_NOT_USABLE(HttpStatus.BAD_REQUEST, "제품을 대여 및 예약할 수 없습니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@Getter
public enum ProductReportErrorCode implements ErrorCode {
PRODUCT_REPORT_ID_NOT_FOUND(HttpStatus.NOT_FOUND, "이상 신고 내용을 찾을 수 없습니다."),
PRODUCT_REPORT_CONTENT_LENGTH(HttpStatus.BAD_REQUEST, String.format("이상 신고 내용이 허용된 최대 길이(%d자)를 초과했습니다.", MAX_PRODUCT_REPORT_CONTENT_LENGTH));
PRODUCT_REPORT_CONTENT_LENGTH(HttpStatus.BAD_REQUEST, String.format("이상 신고 내용이 허용된 최대 길이(%d자)를 초과했습니다.", MAX_PRODUCT_REPORT_CONTENT_LENGTH)),
INVALID_PRODUCT_STATUS_ID(HttpStatus.BAD_REQUEST, "잘못된 상태 입력입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
20 changes: 20 additions & 0 deletions BE/o2o/src/main/java/com/one/o2o/exception/rent/RentErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.one.o2o.exception.rent;

import com.one.o2o.exception.ErrorCode;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum RentErrorCode implements ErrorCode {
RENT_ERROR_CODE(HttpStatus.BAD_REQUEST, "얼");

private final HttpStatus httpStatus;
private final String message;
private final Integer status;

RentErrorCode(final HttpStatus httpStatus, final String message) {
this.httpStatus = httpStatus;
this.status = httpStatus.value();
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.one.o2o.exception.rent;

import com.one.o2o.exception.GeneralException;
import lombok.Getter;

@Getter
public class RentException extends RuntimeException {

private final RentErrorCode errorCode;

public RentException(RentErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}


public class RentException {
public static class RentNotFoundException extends GeneralException {
public RentNotFoundException(){
super("대여 내역을 찾을 수 없습니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.one.o2o.exception.reserve;

import com.one.o2o.exception.ErrorCode;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum ReserveErrorCode implements ErrorCode {
RESERVE_ID_NOT_FOUND(HttpStatus.BAD_REQUEST, "예약 기록을 찾을 수 없습니다."),
RESERVE_TIME_INVALID(HttpStatus.BAD_REQUEST, "예약 시간이 유효하지 않습니다.");


private final HttpStatus httpStatus;
private final Integer status;
private final String message;

ReserveErrorCode(final HttpStatus httpStatus, final String message) {
this.httpStatus = httpStatus;
this.status = httpStatus.value();
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.one.o2o.exception.reserve;

import com.one.o2o.exception.GeneralException;
import lombok.Getter;

@Getter
public class ReserveException extends RuntimeException {

private final ReserveErrorCode errorCode;

public ReserveException(ReserveErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}

public class ReserveException {
public static class ReserveNotFoundException extends GeneralException {
public ReserveNotFoundException(){
super("예약 내역을 찾을 수 없습니다.");
Expand Down
16 changes: 15 additions & 1 deletion BE/o2o/src/main/java/com/one/o2o/validator/LockerValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ public void validateLockerId(Integer lockerId) {
log.error("존재하지 않는 lockerId: {}", lockerId);
throw new LockerException(LockerErrorCode.LOCKER_NOT_FOUND);
}

log.info("유효한 lockerId 확인됨: {}", lockerId);
}

/**
* locker 물품 등록 시, 물품의 개수를 검증
* 총 개수가 보다 물품 개수가 많은 경우 오류를 반환
*
* @param productCnt
* @param totalCnt
*/
public void validateTotalProductCnt(Integer productCnt, Integer totalCnt) {
log.info("productCnt = {}", productCnt);
log.info("totalCnt = {}", totalCnt);
if (totalCnt < productCnt) {
throw new LockerException(LockerErrorCode.TOTAL_COUNT_UNDER_PRODUCT_COUNT);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.one.o2o.validator;

import com.one.o2o.constants.ProductStatus;
import com.one.o2o.exception.products.report.ProductReportErrorCode;
import com.one.o2o.exception.products.report.ProductReportException;
import com.one.o2o.repository.ProductsReportRepository;
Expand All @@ -16,6 +17,12 @@ public class ProductReportValidator {
@Autowired
private ProductsReportRepository productsReportRepository;

/**
* 이상 신고의 처리 아이디 검증
* 존재하지 않는 ID인 경우 오류를 반환
*
* @param id 검증할 내용
*/
public void validateProductReportId(Integer id) {
boolean exist = productsReportRepository.existsById(id);
if (!exist) {
Expand All @@ -24,7 +31,19 @@ public void validateProductReportId(Integer id) {
}

/**
* 제품 보고서의 내용 길이 검증
* 이상 신고의 물품 상태 아이디 검증
* 분실(6), 파손(7)이 아닌 경우 오류를 반환
*
* @param statusId 검증할 내용
*/
public void validateProductStatusId(Integer statusId) {
if (ProductStatus.MISSING.getStatusId() != statusId && ProductStatus.BROKEN.getStatusId() != statusId) {
throw new ProductReportException(ProductReportErrorCode.INVALID_PRODUCT_STATUS_ID);
}
}

/**
* 이상 신고의 내용 길이 검증
* 내용의 길이가 허용된 최대 길이를 초과하는 경우 오류를 반환
*
* @param content 검증할 내용
Expand Down
5 changes: 5 additions & 0 deletions BE/o2o/src/main/java/com/one/o2o/validator/RentValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.one.o2o.validator;

public class RentValidator {

}
42 changes: 42 additions & 0 deletions BE/o2o/src/main/java/com/one/o2o/validator/ReserveValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.one.o2o.validator;

import com.one.o2o.exception.reserve.ReserveErrorCode;
import com.one.o2o.exception.reserve.ReserveException;
import com.one.o2o.repository.ReserveRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
@RequiredArgsConstructor
public class ReserveValidator {

private final ReserveRepository reserveRepository;

/**
* 예약 기록이 존재하는지 검증
* 예약 기록이 DB에 없는 경우 오류를 반환
*
* @param reserveId 검증할 예약 ID
*/
public void validateReserveId(Integer reserveId) {
if (!reserveRepository.existsById(reserveId)) {
throw new ReserveException(ReserveErrorCode.RESERVE_ID_NOT_FOUND);
}
}

/**
* 예약한 수령 시간이 유효한지 검증
* 예약한 수령 시간이 현재 시간보다 작은 경우 오류를 반환
*
* @param reserveTime 검증할 예약 수령 시간
*/
public void validateReserveDate(LocalDateTime reserveTime) {
if (reserveTime.isBefore(LocalDateTime.now())) {
throw new ReserveException(ReserveErrorCode.RESERVE_TIME_INVALID);
}
}
}