Skip to content

Commit

Permalink
[BE] FIX: Blackhole checking fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
enaenen committed Aug 13, 2024
1 parent 67896b2 commit 0509e7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<ItemHistory> itemInInventory =
itemHistoryQueryService.findUnusedItemsInUserInventory(user.getId(), item.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


}

0 comments on commit 0509e7f

Please sign in to comment.