Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -13,31 +13,37 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "block")
@Table(name = "block",
uniqueConstraints = @UniqueConstraint(columnNames = {"blocker_id", "blocked_id"}))
public class BlockEntity {


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long blockId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "blocker_id")
@JoinColumn(name = "blocker_id", nullable = false)
private UserEntity blocker;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "blocked_id")
@JoinColumn(name = "blocked_id", nullable = false)
private UserEntity blocked;



@Enumerated(EnumType.STRING)
@Column(length = 50)
private BlockStatus status;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status도 nullable=true가 들어갔음 싶네요

@Column(nullable = false)
private LocalDateTime time;
@Column(name = "status_changed_at", nullable = false)
private LocalDateTime statusChangedAt; // 상태가 바뀐 시각

@Column(name = "expire_at")
private LocalDateTime expireAt; // 만료 시각 (스케줄러 대상)


@Column(name = "feed_purged_at")
private LocalDateTime feedPurgedAt; // 스케줄러가 feed 지운 시각(라이트로그)



Expand All @@ -47,19 +53,33 @@ public BlockEntity(UserEntity blocker,UserEntity blocked,BlockStatus status){
this.blocker = blocker;
this.blocked = blocked;
this.status = status;
this.time = LocalDateTime.now();
this.statusChangedAt = LocalDateTime.now();

}

public void updateStatus(BlockStatus status) {
this.status = status;
this.time = LocalDateTime.now();

//상태 변경 + TTL 설정
public void updateStatus(BlockStatus newStatus , LocalDateTime now, int unfollowedDays, int blockedDays) {
if (this.status == newStatus) return;

this.status = newStatus;
this.statusChangedAt = now;

//만료 시간 설정
switch(newStatus){
case UNFOLLOWED -> this.expireAt = now.plusDays(unfollowedDays);
case BLOCKED -> this.expireAt = now.plusDays(blockedDays);
case REPORT -> this.expireAt = null;
}
}
public BlockEntity changeStatus(BlockStatus status) {
return BlockEntity.builder()
.blocker(this.blocker)
.blocked(this.blocked)
.status(status)
.build();

//스케쥴러 작동 여부에 대해 라이트로그 찍는 매서드
public void markFeedPurged(LocalDateTime now) {
this.feedPurgedAt = now;
}

//재팔로우 등 복구 시 라이트 로그 초기화
public void clearFeedPurged() {
this.feedPurgedAt = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.spoony.spoony_server.adapter.out.persistence.feed.db;

import java.time.LocalDateTime;

import com.spoony.spoony_server.adapter.out.persistence.post.db.PostEntity;
import com.spoony.spoony_server.adapter.out.persistence.user.db.UserEntity;
import jakarta.persistence.*;
Expand All @@ -11,28 +13,33 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "feed")
@Table(name = "feed",
uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "post_id"}))
public class FeedEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long feedId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "user_id", nullable = false)
private UserEntity user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
@JoinColumn(name = "author_id", nullable = false)
private UserEntity author;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id")
@JoinColumn(name = "post_id", nullable = false)
private PostEntity post;

@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt = LocalDateTime.now();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

생성 시각은 ORM/DB가 책임지게

필드 초기화(LocalDateTime.now())는 테스트/타임존 불일치 유발. @CreationTimestamp와 updatable=false 사용을 권장합니다.

-    @Column(name = "created_at", nullable = false)
-    private LocalDateTime createdAt = LocalDateTime.now();
+    @org.hibernate.annotations.CreationTimestamp
+    @Column(name = "created_at", nullable = false, updatable = false)
+    private LocalDateTime createdAt;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt = LocalDateTime.now();
@org.hibernate.annotations.CreationTimestamp
@Column(name = "created_at", nullable = false, updatable = false)
private LocalDateTime createdAt;
🤖 Prompt for AI Agents
In
src/main/java/com/spoony/spoony_server/adapter/out/persistence/feed/db/FeedEntity.java
around lines 35-37, remove the field initializer LocalDateTime.now() from
createdAt and let the database/ORM set the value: annotate the field with
Hibernate's @CreationTimestamp and set @Column(updatable = false, nullable =
false) so the timestamp is populated on insert and not updated; ensure the
proper import for org.hibernate.annotations.CreationTimestamp is added and
remove any direct initialization to avoid test/timezone inconsistencies.

@Builder
public FeedEntity(UserEntity user, PostEntity post,UserEntity author) {
public FeedEntity(UserEntity user, UserEntity author ,PostEntity post) {
this.user = user;
this.post = post;
this.author = author;
this.post = post;
this.createdAt = LocalDateTime.now();
}
}