Skip to content

Commit

Permalink
드로잉 게임 전 기대평 작성 시 버그 해결합니다. (#215)
Browse files Browse the repository at this point in the history
fix: 드로잉에 대한 이벤트 유저가 없을 시 Event_user 생성 (#214)
  • Loading branch information
min9805 committed Aug 25, 2024
1 parent 756fa00 commit 91dd658
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
Expand Down Expand Up @@ -94,10 +95,16 @@ public Expectation expectationRegisterApi(
expectation.setExpectationComment(expectationRegisterRequest.getComment());

List<SubEvent> 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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 91dd658

Please sign in to comment.