Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SAMBAD-247] 이벤트 만료 로직 추가 #98

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public void inactivateLastEventByType(Long userId, Long meetingId, EventType typ
public PollingEventListResponse getActiveEvents(Long userId, Long meetingId) {
meetingMemberValidator.validateUserIsMemberOfMeeting(userId, meetingId);
List<Event> events = eventRepository.findByUserIdAndMeetingIdAndStatus(userId, meetingId, EventStatus.ACTIVE);
return PollingEventListResponse.from(events);
events.forEach(Event::inactivateIfExpired);

List<Event> notExpiredEvents = events.stream()
.filter(Event::isActive)
.toList();

return PollingEventListResponse.from(notExpiredEvents);
}

private Event getEventById(Long eventId) {
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/org/depromeet/sambad/moring/event/domain/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import static lombok.AccessLevel.PROTECTED;
import static org.depromeet.sambad.moring.event.domain.EventStatus.ACTIVE;
import static org.depromeet.sambad.moring.event.domain.EventStatus.INACTIVE;
import static org.depromeet.sambad.moring.meeting.question.domain.MeetingQuestion.*;

import java.time.LocalDateTime;

import org.depromeet.sambad.moring.common.domain.BaseTimeEntity;

Expand Down Expand Up @@ -32,21 +35,40 @@ public class Event extends BaseTimeEntity {

@Enumerated(STRING)
private EventType type;

@Enumerated(STRING)
private EventStatus status;

private Event(Long userId, Long meetingId, EventType type, EventStatus status) {
private LocalDateTime expiredAt;

private Event(Long userId, Long meetingId, EventType type, EventStatus status, LocalDateTime expiredAt) {
this.userId = userId;
this.meetingId = meetingId;
this.type = type;
this.status = status;
this.expiredAt = expiredAt;
}

public static Event publish(Long userId, Long meetingId, EventType type) {
return new Event(userId, meetingId, type, ACTIVE);
LocalDateTime expiredAt = LocalDateTime.now().plusHours(RESPONSE_TIME_LIMIT_HOURS);
return new Event(userId, meetingId, type, ACTIVE, expiredAt);
}

public void inactivate() {
this.status = INACTIVE;
}

public void inactivateIfExpired() {
if (isExpired()) {
inactivate();
}
}

private boolean isExpired() {
return LocalDateTime.now().isAfter(expiredAt);
}

public boolean isActive() {
return status == ACTIVE;
}
}
Loading