diff --git a/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java b/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java index 17f53a2..bb7b0fa 100644 --- a/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java +++ b/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java @@ -47,6 +47,7 @@ public enum ErrorMessage { /** gift menu **/ INVALID_GIFT_MENU("존재하지 않는 선물 종류입니다."), + WRONG_GIFT("잘못된 선물입니다."), ; private final String message; diff --git a/src/main/java/com/sopterm/makeawish/service/CakeService.java b/src/main/java/com/sopterm/makeawish/service/CakeService.java index 030f746..9d1c060 100644 --- a/src/main/java/com/sopterm/makeawish/service/CakeService.java +++ b/src/main/java/com/sopterm/makeawish/service/CakeService.java @@ -153,6 +153,9 @@ public CakeCreateResponseDTO createPresent(CakeCreateRequest request) { val cake = getCake(request.cakeId()); val wish = wishService.getWish(request.wishId()); val giftMenu = getGiftMenuInfo(request.giftMenuId()); + + checkGiftMenu(wish, giftMenu); + val present = Present.builder() .name(request.name()) .message(request.message()) @@ -174,4 +177,10 @@ public List getAllGiftMenu() { .map(GiftMenuResponseDTO::from) .collect(Collectors.toList()); } + + private void checkGiftMenu(Wish wish, GiftMenu giftMenu){ + if(!wish.isWantsGift() && !giftMenu.getId().equals(0L)){ + throw new IllegalArgumentException(WRONG_GIFT.getMessage()); + } + } }