From b44f069710ccf3d9ab7b1c2714084e7307817adc Mon Sep 17 00:00:00 2001 From: Jinwoo Lee Date: Tue, 24 Oct 2023 14:00:43 +0900 Subject: [PATCH] fix: set invalid password count limit --- .../repl/gifthub/giftcard/entity/Giftcard.java | 9 ++++++--- .../giftcard/service/GiftcardService.java | 17 +++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/giftcard/entity/Giftcard.java b/src/main/java/org/swmaestro/repl/gifthub/giftcard/entity/Giftcard.java index 1a243ab1..3c972ef3 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/giftcard/entity/Giftcard.java +++ b/src/main/java/org/swmaestro/repl/gifthub/giftcard/entity/Giftcard.java @@ -57,17 +57,20 @@ public Giftcard(String id, Voucher voucher, String message, LocalDateTime expire this.invalidPasswordCount = 0; } - public void expire() { + public Giftcard expire() { this.expiresAt = LocalDateTime.now(); + return this; } - public void increaseInvalidPasswordCount() { + public Giftcard increaseInvalidPasswordCount() { this.invalidPasswordCount++; + return this; } - public void resetInvalidPasswordCount() { + public Giftcard resetInvalidPasswordCount() { this.invalidPasswordCount = 0; + return this; } public boolean isEnable() { diff --git a/src/main/java/org/swmaestro/repl/gifthub/giftcard/service/GiftcardService.java b/src/main/java/org/swmaestro/repl/gifthub/giftcard/service/GiftcardService.java index bc5201e2..ae7f8857 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/giftcard/service/GiftcardService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/giftcard/service/GiftcardService.java @@ -79,20 +79,19 @@ public GiftcardResponseDto read(String id, String password) { Giftcard giftcard = read(id); if (!giftcard.isEnable()) { - throw new BusinessException("만료된 링크입니다.", StatusEnum.BAD_REQUEST); + throw new BusinessException("기간이 만료된 링크입니다.", StatusEnum.BAD_REQUEST); } if (giftcard.getInvalidPasswordCount() >= 10) { - throw new BusinessException("비밀번호를 10회 이상 틀렸습니다. 고객센터에 문의해주세요.", StatusEnum.FORBIDDEN); + throw new BusinessException("비밀번호를 10회 이상 틀렸습니다. 이 링크는 더 이상 사용할 수 없습니다.", StatusEnum.FORBIDDEN); } if (!decryptPassword(giftcard.getPassword()).equals(password)) { - giftcard.increaseInvalidPasswordCount(); + save(giftcard.increaseInvalidPasswordCount()); throw new BusinessException("비밀번호가 일치하지 않습니다.", StatusEnum.FORBIDDEN); } - giftcard.resetInvalidPasswordCount(); - giftCardRepository.save(giftcard); + save(giftcard.resetInvalidPasswordCount()); return GiftcardResponseDto.builder() .sender(giftcard.getVoucher().getUser().getNickname()) @@ -103,6 +102,10 @@ public GiftcardResponseDto read(String id, String password) { .build(); } + public Giftcard save(Giftcard giftcard) { + return giftCardRepository.save(giftcard); + } + /** * 기프트 카드의 소유자를 변경합니다. * @param giftcardId: 변경할 기프트 카드의 id @@ -120,9 +123,7 @@ public Giftcard changeVoucherUser(String giftcardId, String username) { User newUser = userService.read(username); updatedVoucher.setUser(newUser); voucherRepository.save(updatedVoucher); - - giftcard.expire(); - giftCardRepository.save(giftcard); + giftCardRepository.save(giftcard.expire()); return giftcard; }