Skip to content

Commit

Permalink
Revert "fix: 약속방 로그 목록 조회 시 입장 로그가 출발 알림 로그보다 먼저 출력되도록 수정 (#680)" (#739)
Browse files Browse the repository at this point in the history
This reverts commit 75475eb
  • Loading branch information
mzeong authored Oct 16, 2024
1 parent e488594 commit a051bde
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 85 deletions.
3 changes: 1 addition & 2 deletions backend/src/main/java/com/ody/common/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
@Getter
public class BaseEntity {

@Column(updatable = false, columnDefinition = "TIMESTAMP(6)")
@Column(updatable = false)
@NotNull
@CreatedDate
private LocalDateTime createdAt;

@Column(columnDefinition = "TIMESTAMP(6)")
@NotNull
@LastModifiedDate
private LocalDateTime updatedAt;
Expand Down
17 changes: 8 additions & 9 deletions backend/src/main/java/com/ody/eta/domain/Eta.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public class Eta {

@Column(updatable = false)
@NotNull
private LocalDateTime firstApiCallAt;
private LocalDateTime createdAt;

@NotNull
private LocalDateTime lastApiCallAt;
private LocalDateTime updatedAt;

@Column(columnDefinition = "TIMESTAMP(6)")
private LocalDateTime deletedAt;

public Eta(Mate mate, Long remainingMinutes) {
Expand All @@ -70,17 +69,17 @@ public Eta(Mate mate, Long remainingMinutes) {
}

// TODO: 테스트에서만 쓰이는 생성자
public Eta(Mate mate, long remainingMinutes, LocalDateTime firstApiCallAt, LocalDateTime lastApiCallAt) {
this(null, mate, remainingMinutes, false, false, firstApiCallAt, lastApiCallAt, null);
public Eta(Mate mate, long remainingMinutes, LocalDateTime createdAt, LocalDateTime updatedAt) {
this(null, mate, remainingMinutes, false, false, createdAt, updatedAt, null);
}

public boolean isModified() {
return !firstApiCallAt.isEqual(lastApiCallAt);
return !createdAt.isEqual(updatedAt);
}

public long countDownMinutes() {
LocalDateTime now = TimeUtil.nowWithTrim();
long minutesDifference = Duration.between(lastApiCallAt, now).toMinutes();
long minutesDifference = Duration.between(updatedAt, now).toMinutes();
return Math.max(remainingMinutes - minutesDifference, 0);
}

Expand All @@ -91,11 +90,11 @@ public boolean isArrivalSoon(Meeting meeting) {
}

public long differenceMinutesFromLastUpdated() {
return Duration.between(lastApiCallAt, TimeUtil.nowWithTrim()).toMinutes();
return Duration.between(updatedAt, TimeUtil.nowWithTrim()).toMinutes();
}

public void updateRemainingMinutes(long remainingMinutes) {
this.lastApiCallAt = TimeUtil.nowWithTrim();
this.updatedAt = TimeUtil.nowWithTrim();
this.remainingMinutes = remainingMinutes;
}

Expand Down
2 changes: 0 additions & 2 deletions backend/src/main/java/com/ody/mate/domain/Mate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.ody.meeting.domain.Location;
import com.ody.meeting.domain.Meeting;
import com.ody.member.domain.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down Expand Up @@ -64,7 +63,6 @@ public class Mate {
@NotNull
private long estimatedMinutes;

@Column(columnDefinition = "TIMESTAMP(6)")
private LocalDateTime deletedAt;

public Mate(Meeting meeting, Member member, Nickname nickname, Location origin, long estimatedMinutes) {
Expand Down
2 changes: 0 additions & 2 deletions backend/src/main/java/com/ody/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.ody.auth.token.RefreshToken;
import com.ody.mate.domain.Nickname;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -47,7 +46,6 @@ public class Member {
@Embedded
private RefreshToken refreshToken;

@Column(columnDefinition = "TIMESTAMP(6)")
private LocalDateTime deletedAt;

public Member(String providerId, Nickname nickname, String imageUrl, DeviceToken deviceToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.ody.common.domain.BaseEntity;
import com.ody.mate.domain.Mate;
import jakarta.persistence.Column;
import com.ody.util.TimeUtil;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -40,7 +40,6 @@ public class Notification extends BaseEntity {
private NotificationType type;

@NotNull
@Column(columnDefinition = "TIMESTAMP(6)")
private LocalDateTime sendAt;

@Enumerated(value = EnumType.STRING)
Expand Down Expand Up @@ -108,11 +107,16 @@ public boolean isStatusDismissed() {
return status == NotificationStatus.DISMISSED;
}

public boolean isNow() {
return this.sendAt.equals(TimeUtil.nowWithTrim());
}

public void updateStatusToDone() {
this.status = NotificationStatus.DONE;
}

public void updateStatusToDismissed() {
this.status = NotificationStatus.DISMISSED;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface NotificationRepository extends JpaRepository<Notification, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ private void saveAndSendDepartureReminderNotification(Meeting meeting, Mate mate

private LocalDateTime calculateSendAt(DepartureTime departureTime) {
if (departureTime.isBefore(LocalDateTime.now())) {
return LocalDateTime.now();
return TimeUtil.nowWithTrim();
}
return departureTime.getValue();
return TimeUtil.trimSecondsAndNanos(departureTime.getValue());
}

private void saveAndSendNotification(Notification notification) {
Expand Down

This file was deleted.

14 changes: 2 additions & 12 deletions backend/src/test/java/com/ody/common/FixtureGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,16 @@ public Notification generateNotification(Mate mate) {
}

public Notification generateNotification(Mate mate, NotificationStatus notificationStatus) {
LocalDateTime now = TimeUtil.nowWithTrim();
return notificationRepository.save(new Notification(
mate,
NotificationType.ENTRY,
LocalDateTime.now(),
now,
notificationStatus,
new FcmTopic(mate.getMeeting())
));
}

public Notification generateNotification(
Mate mate,
NotificationType type,
LocalDateTime sentAt,
NotificationStatus status
) {
return notificationRepository.save(
new Notification(mate, type, sentAt, status, new FcmTopic(mate.getMeeting()))
);
}

public String generateAccessTokenValueByMember(Member member) {
return "Bearer access-token=" + jwtTokenProvider.createAccessToken(member.getId()).getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,38 @@

class NotificationRepositoryTest extends BaseRepositoryTest {

@DisplayName("특정 모임의 알림 발송 시간이 지나지 않은 알림 전송 시간을 기준하여 오름차순으로 반환한다.")
@DisplayName("특정 모임의 Notification 반환")
@Test
void findAllMeetingLogsBeforeThanEqual() {
Member member = memberRepository.save(Fixture.MEMBER1);
void findAllMeetingLogsById() {
Member member1 = memberRepository.save(Fixture.MEMBER1);
Member member2 = memberRepository.save(Fixture.MEMBER2);

Meeting odyMeeting = meetingRepository.save(Fixture.ODY_MEETING);
Mate mate = fixtureGenerator.generateMate(odyMeeting, member);

Notification entryNotification = fixtureGenerator.generateNotification(
mate,
NotificationType.ENTRY,
Mate mate1 = fixtureGenerator.generateMate(odyMeeting, member1);
Mate mate2 = fixtureGenerator.generateMate(odyMeeting, member2);

Notification notification1 = new Notification(
mate1,
NotificationType.DEPARTURE_REMINDER,
LocalDateTime.now(),
NotificationStatus.DONE
NotificationStatus.DONE,
new FcmTopic(odyMeeting)
);
Notification departurnReminderNotification = fixtureGenerator.generateNotification(
mate,

Notification notification2 = new Notification(
mate2,
NotificationType.DEPARTURE_REMINDER,
LocalDateTime.now(),
NotificationStatus.PENDING
NotificationStatus.PENDING,
new FcmTopic(odyMeeting)
);
notificationRepository.save(notification1);
notificationRepository.save(notification2);

List<Notification> notifications = notificationRepository.findAllMeetingLogsBeforeThanEqual(
odyMeeting.getId(),
LocalDateTime.now()
);
List<Notification> notifications = notificationRepository.findAllMeetingLogsBeforeThanEqual(odyMeeting.getId(), LocalDateTime.now());

assertThat(notifications).containsExactly(entryNotification, departurnReminderNotification);
assertThat(notifications.size()).isEqualTo(2);
}

@DisplayName("현재 시간 이전의 모임 notification만 가져온다")
Expand Down Expand Up @@ -80,8 +86,7 @@ void findAllNotificationsById() {
notificationRepository.save(pastNotification);
notificationRepository.save(futureNotification);

List<Notification> notifications = notificationRepository.findAllMeetingLogsBeforeThanEqual(odyMeeting.getId(),
LocalDateTime.now());
List<Notification> notifications = notificationRepository.findAllMeetingLogsBeforeThanEqual(odyMeeting.getId(), LocalDateTime.now());

assertThat(notifications.size()).isOne();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,17 @@ class NotificationServiceTest extends BaseServiceTest {
@MockBean
private KakaoAuthUnlinkClient kakaoAuthUnlinkClient;

@DisplayName("출발 알림 생성 시점이 알림 전송 시점보다 늦은 경우 즉시 전송된다")
@DisplayName("알림 생성 시점이 전송 시점보다 늦은 경우 즉시 전송된다")
@Test
void sendImmediatelyIfDepartureTimeIsPast() {
Member member = fixtureGenerator.generateMember();
Meeting savedPastMeeting = fixtureGenerator.generateMeeting(LocalDateTime.now().minusDays(1));
Mate mate = fixtureGenerator.generateMate(savedPastMeeting, member); // 소요 시간 : 10분

LocalDateTime expect = LocalDateTime.now();
Mate mate = fixtureGenerator.generateMate(savedPastMeeting, member);
notificationService.saveAndSendNotifications(savedPastMeeting, mate, member.getDeviceToken());

Notification departureReminderNotification = notificationRepository.findAll().stream()
.filter(Notification::isDepartureReminder)
.findAny()
.get();

assertThat(departureReminderNotification.getSendAt()).isEqualToIgnoringNanos(expect);
Optional<Notification> departureNotification = notificationRepository.findAll().stream()
.filter(notification -> notification.isDepartureReminder() && notification.isNow())
.findAny();
assertThat(departureNotification).isPresent();
}

@DisplayName("PENDING 상태의 알림들을 TaskScheduler로 스케줄링 한다.")
Expand Down Expand Up @@ -139,21 +134,6 @@ void updateAllStatusPendingToDismissedByMateId() {
);
}

@DisplayName("참여자의 출발 시간이 현재 시간보다 전이라면 입장 알림 - 출발 알림 순으로 로그 목록이 조회된다.")
@Test
void findAllMeetingLogsOrderOfEntryAndDepartureNotification() {
Member member = fixtureGenerator.generateMember();
Meeting savedPastMeeting = fixtureGenerator.generateMeeting(LocalDateTime.now().minusDays(1));
Mate mate = fixtureGenerator.generateMate(savedPastMeeting, member); // 소요 시간 : 10분

notificationService.saveAndSendNotifications(savedPastMeeting, mate, member.getDeviceToken());

NotiLogFindResponses allMeetingLogs = notificationService.findAllMeetingLogs(savedPastMeeting.getId());

assertThat(allMeetingLogs.notiLog()).extracting(NotiLogFindResponse::type)
.containsExactly(NotificationType.ENTRY.name(), NotificationType.DEPARTURE_REMINDER.name());
}

@DisplayName("삭제 회원이 포함된 로그 목록을 조회한다.")
@Test
void findAllMeetingLogsIncludingDeletedMember() {
Expand Down

0 comments on commit a051bde

Please sign in to comment.