From 0509e7f39e398c15bebf907d40f1f701a934f42c Mon Sep 17 00:00:00 2001 From: Woo Joo Chae Date: Tue, 13 Aug 2024 15:53:27 +0900 Subject: [PATCH] [BE] FIX: Blackhole checking fixed --- .../item/service/ItemFacadeService.java | 8 ++++--- .../blackhole/manager/BlackholeManager.java | 22 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java index 5d274df64..b6f0e5546 100644 --- a/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java +++ b/backend/src/main/java/org/ftclub/cabinet/item/service/ItemFacadeService.java @@ -45,6 +45,7 @@ import org.ftclub.cabinet.user.domain.User; import org.ftclub.cabinet.user.service.UserCommandService; import org.ftclub.cabinet.user.service.UserQueryService; +import org.ftclub.cabinet.utils.blackhole.manager.BlackholeManager; import org.ftclub.cabinet.utils.lock.LockUtil; import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; @@ -69,6 +70,7 @@ public class ItemFacadeService { private final CabinetQueryService cabinetQueryService; private final SectionAlarmCommandService sectionAlarmCommandService; private final SectionAlarmQueryService sectionAlarmQueryService; + private final BlackholeManager blackholeManager; private final ApplicationEventPublisher eventPublisher; @@ -239,11 +241,11 @@ private void saveCoinChangeOnRedis(Long userId, final int reward) { public void useItem(Long userId, Sku sku, ItemUseRequestDto data) { itemPolicyService.verifyDataFieldBySku(sku, data); User user = userQueryService.getUser(userId); + if (user.isBlackholed()) { - // 이벤트를 발생시켰는데 동기로직이다..? - // TODO: 근데 그 이벤트가 뭘 하는지 이 코드 흐름에서는 알 수 없다..? - eventPublisher.publishEvent(UserBlackHoleEvent.of(user)); + throw ExceptionStatus.BLACKHOLED_USER.asServiceException(); } + Item item = itemQueryService.getBySku(sku); List itemInInventory = itemHistoryQueryService.findUnusedItemsInUserInventory(user.getId(), item.getId()); diff --git a/backend/src/main/java/org/ftclub/cabinet/utils/blackhole/manager/BlackholeManager.java b/backend/src/main/java/org/ftclub/cabinet/utils/blackhole/manager/BlackholeManager.java index 23ead8047..5414778b1 100644 --- a/backend/src/main/java/org/ftclub/cabinet/utils/blackhole/manager/BlackholeManager.java +++ b/backend/src/main/java/org/ftclub/cabinet/utils/blackhole/manager/BlackholeManager.java @@ -94,19 +94,21 @@ public void handleBlackHole(UserBlackHoleEvent dto) { } } - private boolean isBlackholed(LocalDateTime blackholedAt) { - if (blackholedAt == null) { - return false; - } - return blackholedAt.isBefore(LocalDateTime.now()); - } public void blackholeUpdate(User user) { - if (isBlackholed(user.getBlackholedAt())) { - return; - } FtProfile userRecentIntraProfile = getUserRecentIntraProfile(user.getName()); - userCommandService.updateUserBlackholedAtById(user.getId(), + userCommandService.updateUserBlackholeStatus(user.getId(), userRecentIntraProfile.getBlackHoledAt()); } + + private boolean isBlackholeRemains(LocalDateTime blackholedAt) { + return blackholedAt == null || blackholedAt.isAfter(LocalDateTime.now()); + } + + public boolean isBlackholedUser(User user) { + FtProfile userRecentIntraProfile = getUserRecentIntraProfile(user.getName()); + return isBlackholeRemains(userRecentIntraProfile.getBlackHoledAt()); + } + + }