From 8b66ae4cefacb9c0413fe6248f165e60b0f411fe Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 21 Aug 2024 19:36:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EC=B6=94=EC=B2=9C=EC=9D=B8=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/LotteryEventService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index bb3cf4c9..5d625681 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -83,14 +83,7 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto participant = new LotteryParticipants(user); lotteryParticipantsRepository.save(participant); - if (casperBotRequestDto.getReferralId() != null) { - String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); - Optional referralParticipant = - lotteryParticipantsRepository.findByBaseUser( - userRepository.findById(referralId).orElse(null) - ); - referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); - } + addReferralAppliedCount(casperBotRequestDto); user.updateLotteryParticipants(participant); userRepository.save(user); @@ -99,6 +92,17 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto return participant; } + private void addReferralAppliedCount(CasperBotRequestDto casperBotRequestDto) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { + String encryptedReferralId = casperBotRequestDto.getReferralId(); + if (encryptedReferralId == null) return; + String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); + Optional referralParticipant = + lotteryParticipantsRepository.findByBaseUser( + userRepository.findById(referralId).orElse(null) + ); + referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); + } + public LotteryEventResponseDto getLotteryEvent() { LotteryEvent lotteryEvent = getEvent(); return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); From e96a8f13c504b6544d9b0fcbec86412a10fcc62a Mon Sep 17 00:00:00 2001 From: nnijgnus Date: Wed, 21 Aug 2024 19:45:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=EC=9D=B8=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EB=94=94=EA=B0=80=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EC=95=84=EB=8F=84=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EB=B0=9C=EC=83=9D=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EA=B3=A0=20=EA=B7=B8=EB=8C=80=EB=A1=9C=20=EB=8F=99=EC=9E=91?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eventService/LotteryEventService.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index 5d625681..76712bc1 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -17,6 +17,8 @@ import JGS.CasperEvent.global.jwt.repository.UserRepository; import JGS.CasperEvent.global.util.AESUtils; import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,6 +37,7 @@ @RequiredArgsConstructor public class LotteryEventService { + private static final Logger log = LoggerFactory.getLogger(LotteryEventService.class); private final UserRepository userRepository; private final LotteryEventRepository lotteryEventRepository; private final LotteryParticipantsRepository lotteryParticipantsRepository; @@ -95,12 +98,17 @@ public LotteryParticipants registerUserIfNeed(BaseUser user, CasperBotRequestDto private void addReferralAppliedCount(CasperBotRequestDto casperBotRequestDto) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { String encryptedReferralId = casperBotRequestDto.getReferralId(); if (encryptedReferralId == null) return; - String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); - Optional referralParticipant = - lotteryParticipantsRepository.findByBaseUser( - userRepository.findById(referralId).orElse(null) - ); - referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); + try { + String referralId = AESUtils.decrypt(casperBotRequestDto.getReferralId(), secretKey); + Optional referralParticipant = + lotteryParticipantsRepository.findByBaseUser( + userRepository.findById(referralId).orElse(null) + ); + referralParticipant.ifPresent(LotteryParticipants::linkClickedCountAdded); + } catch (Exception e) { + log.debug(e.getLocalizedMessage()); + } + } public LotteryEventResponseDto getLotteryEvent() {