diff --git a/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java b/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java index 1fbd9914..3fed14f5 100644 --- a/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java +++ b/src/main/java/com/hyundai/softeer/backend/domain/expectation/service/ExpectationService.java @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.List; @Service @@ -94,10 +95,16 @@ public Expectation expectationRegisterApi( expectation.setExpectationComment(expectationRegisterRequest.getComment()); List subEvents = subEventRepository.findByEventIdAndExecuteType(eventId, SubEventExecuteType.LOTTERY); + LocalDateTime now = LocalDateTime.now(); for (SubEvent subEvent : subEvents) { EventUser eventUser = eventUserRepository.findByUserIdAndSubEventId(authenticatedUser.getId(), subEvent.getId()) - .orElseThrow(() -> new EventNotFoundException()); + .orElseGet(() -> EventUser.builder() + .user(authenticatedUser) + .subEvent(subEventRepository.getReferenceById(subEvent.getId())) + .lastVisitedAt(now) + .lastChargeAt(now) + .build()); eventUser.updateExpectationBonusChanceIfNotUsed(); eventUserRepository.save(eventUser); @@ -107,7 +114,7 @@ public Expectation expectationRegisterApi( } public static String maskName(String name) { - if(name == null || name.length() < 2) { + if (name == null || name.length() < 2) { return name; }