Skip to content
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
31 changes: 28 additions & 3 deletions src/main/java/com/hyetaekon/hyetaekon/answer/entity/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.hyetaekon.hyetaekon.user.entity.User;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;


@Entity
Expand All @@ -14,7 +18,8 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "answer")
public class Answer extends BaseEntity {
@EntityListeners(AuditingEntityListener.class)
public class Answer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // ๋‹ต๋ณ€ ID
Expand All @@ -33,10 +38,30 @@ public class Answer extends BaseEntity {
@Column(name = "selected", nullable = false)
private boolean selected; // ์ฑ„ํƒ ์—ฌ๋ถ€

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

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Column(name = "suspend_at")
private LocalDateTime suspendAt;

// ์‚ญ์ œ ์ฒ˜๋ฆฌ
public void delete() {
this.deletedAt = LocalDateTime.now();
}

// ์ •์ง€ ์ฒ˜๋ฆฌ
public void suspend() {
this.suspendAt = LocalDateTime.now();
}

public String getDisplayContent() {
if (getDeletedAt() != null) {
if (this.deletedAt != null) {
return "์‚ญ์ œ๋œ ๋‹ต๋ณ€์ž…๋‹ˆ๋‹ค.";
} else if (getSuspendAt() != null) {
} else if (this.suspendAt != null) {
return "๊ด€๋ฆฌ์ž์— ์˜ํ•ด ์‚ญ์ œ๋œ ๋‹ต๋ณ€์ž…๋‹ˆ๋‹ค.";
}
return content;
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/com/hyetaekon/hyetaekon/comment/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.hyetaekon.hyetaekon.user.entity.User;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

Expand All @@ -15,7 +17,8 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "comments")
public class Comment extends BaseEntity {
@EntityListeners(AuditingEntityListener.class)
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -33,10 +36,30 @@ public class Comment extends BaseEntity {
@Column(nullable = false, length = 1000)
private String content;

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

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Column(name = "suspend_at")
private LocalDateTime suspendAt;

// ์‚ญ์ œ ์ฒ˜๋ฆฌ
public void delete() {
this.deletedAt = LocalDateTime.now();
}

// ์ •์ง€ ์ฒ˜๋ฆฌ
public void suspend() {
this.suspendAt = LocalDateTime.now();
}

public String getDisplayContent() {
if (getDeletedAt() != null) {
if (this.deletedAt != null) {
return "์‚ญ์ œ๋œ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.";
} else if (getSuspendAt() != null) {
} else if (this.suspendAt != null) {
return "๊ด€๋ฆฌ์ž์— ์˜ํ•ด ์‚ญ์ œ๋œ ๋Œ“๊ธ€์ž…๋‹ˆ๋‹ค.";
}
return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/com/hyetaekon/hyetaekon/common/util/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,4 @@ public class BaseEntity {
@Column(name = "modified_at", nullable = false, columnDefinition = "DATETIME(0)")
private LocalDateTime modifiedAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Column(name = "suspend_at")
private LocalDateTime suspendAt;

// ์‚ญ์ œ ์ฒ˜๋ฆฌ
public void delete() {
this.deletedAt = LocalDateTime.now();
}

// ์ •์ง€ ์ฒ˜๋ฆฌ
public void suspend() {
this.suspendAt = LocalDateTime.now();
}

// ๋ณต์›์‹œ
public void restore() {
this.deletedAt = null;
this.suspendAt = null;
}
}
29 changes: 26 additions & 3 deletions src/main/java/com/hyetaekon/hyetaekon/post/entity/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.hyetaekon.hyetaekon.user.entity.User;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -19,7 +22,8 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "post")
public class Post extends BaseEntity {
@EntityListeners(AuditingEntityListener.class)
public class Post {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -69,6 +73,16 @@ public class Post extends BaseEntity {
@Column(name = "category_id")
private Long categoryId;

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

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

@Column(name = "suspend_at")
private LocalDateTime suspendAt;


@Builder.Default
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down Expand Up @@ -101,11 +115,20 @@ public void decrementCommentCnt() {
this.commentCnt = Math.max(0, this.commentCnt - 1);
}

// ์‚ญ์ œ ์ฒ˜๋ฆฌ
public void delete() {
this.deletedAt = LocalDateTime.now();
}

// ์ •์ง€ ์ฒ˜๋ฆฌ
public void suspend() {
this.suspendAt = LocalDateTime.now();
}

public String getDisplayContent() {
if (getDeletedAt() != null) {
if (this.deletedAt != null) {
return "์‚ญ์ œ๋œ ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค.";
} else if (getSuspendAt() != null) {
} else if (this.suspendAt != null) {
return "๊ด€๋ฆฌ์ž์— ์˜ํ•ด ์‚ญ์ œ๋œ ๊ฒŒ์‹œ๊ธ€์ž…๋‹ˆ๋‹ค.";
}
return content;
Expand Down