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

refactor: Instant를 모두 LocalDateTime으로 변경 #200

Merged
merged 1 commit into from
Feb 12, 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
@@ -1,6 +1,6 @@
package net.teumteum.alert.domain;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -11,5 +11,5 @@ public interface AlertRepository extends JpaRepository<Alert, Long> {
List<Alert> findAllByUserId(Long userId);

@Query("select a from alert as a where a.createdAt <= :createdAt")
List<Alert> findAllByCreatedAt(@Param("createdAt") Instant createdAt);
List<Alert> findAllByCreatedAt(@Param("createdAt") LocalDateTime createdAt);
}
4 changes: 2 additions & 2 deletions src/main/java/net/teumteum/alert/domain/AlertService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.teumteum.alert.domain;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import lombok.RequiredArgsConstructor;
import net.teumteum.alert.domain.response.AlertsResponse;
Expand Down Expand Up @@ -33,7 +33,7 @@ public AlertsResponse findAllByUserId(Long userId) {
@Transactional
@Scheduled(cron = EVERY_12AM)
public void deleteOneMonthBeforeAlert() {
var deleteTargets = alertRepository.findAllByCreatedAt(Instant.now().minus(1, ChronoUnit.MONTHS));
var deleteTargets = alertRepository.findAllByCreatedAt(LocalDateTime.now().minus(1, ChronoUnit.MONTHS));
alertRepository.deleteAllInBatch(deleteTargets);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.teumteum.alert.domain.response;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import net.teumteum.alert.domain.Alert;

Expand All @@ -26,7 +26,7 @@ public record AlertResponse(
String title,
String body,
String type,
Instant createdAt,
LocalDateTime createdAt,
boolean isRead
) {

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/teumteum/core/entity/TimeBaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.Instant;

@Getter
@SuperBuilder
@NoArgsConstructor
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class TimeBaseEntity {

@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
private Instant createdAt;
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
private LocalDateTime updatedAt;
}

Loading