-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPost.java
More file actions
41 lines (35 loc) · 951 Bytes
/
Post.java
File metadata and controls
41 lines (35 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.devSns.entity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.*;
import lombok.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Post {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String content;
private int likes;
private String username;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL,orphanRemoval = true)
@JsonManagedReference
private List<Comment> comments = new ArrayList<>();
@PrePersist
public void onCreate(){
createdAt = LocalDateTime.now();
updatedAt = LocalDateTime.now();
}
@PreUpdate
public void onUpdate(){
updatedAt = LocalDateTime.now();
}
}