diff --git a/src/main/java/umc/spring/post/data/entity/Comment.java b/src/main/java/umc/spring/post/data/entity/Comment.java new file mode 100644 index 0000000000000000000000000000000000000000..92aab2c6c7b6ead7bb5c76e333f26438d6e82bcc --- /dev/null +++ b/src/main/java/umc/spring/post/data/entity/Comment.java @@ -0,0 +1,36 @@ +package umc.spring.post.data.entity; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.Date; + +@Entity +@Getter @Setter +public class Comment { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false) + private Long id; + + @Column(nullable = false) + private Long userId; + + @Column(nullable = false) + private Long postId; + + @Column(nullable = false) + private String author; + + @Column(nullable = false) + private String text; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "postId", nullable = false,insertable=false, updatable=false) + private Post post; + + @Column(nullable = false) + private Date timestamp; + +} diff --git a/src/main/java/umc/spring/post/data/entity/Post.java b/src/main/java/umc/spring/post/data/entity/Post.java index a3b743cbe3979905455cceacb528e5132d5efcdc..c3df9aa1cab46842779a100279057bfd8e814822 100644 --- a/src/main/java/umc/spring/post/data/entity/Post.java +++ b/src/main/java/umc/spring/post/data/entity/Post.java @@ -1,10 +1,12 @@ -package com.umc.post.data.entity; +package umc.spring.post.data.entity; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Entity @Table(name = "Post") @@ -17,14 +19,31 @@ public class Post{ private Long id; @Column(nullable = false) - private String title; + private Long userId; @Column(nullable = false) - private String author; + private String title; @Column(nullable = false) private String body; @Column(nullable = false) - private Date timestamp; + private String image; + + @Column(nullable = false) + private int likeCount; + + @Column(nullable = false) + private String author; + + @Column(nullable = true) + private Date createdTime; + + @Column(nullable = true) + private Date modifiedTime; + + @OneToMany(mappedBy = "post", cascade = CascadeType.ALL,fetch = FetchType.EAGER, + orphanRemoval = true) + private List<Comment> comments = new ArrayList<>(); + } diff --git a/src/main/java/umc/spring/post/data/entity/User.java b/src/main/java/umc/spring/post/data/entity/User.java new file mode 100644 index 0000000000000000000000000000000000000000..188308b9f9a9777dd8b23a4b506ec7c9ea2a776e --- /dev/null +++ b/src/main/java/umc/spring/post/data/entity/User.java @@ -0,0 +1,75 @@ +package umc.spring.post.data.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import umc.spring.post.config.security.Role; + +import java.util.ArrayList; +import java.util.Collection; + +//@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Data +@Table(name="user") +public class User implements UserDetails { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false) + private Long id; + + @Column(nullable = false) + private String userId; + + @Column(nullable = false) + private String password; + + @Column(nullable = false) + private String userName; + + @Enumerated(EnumType.STRING) + private Role role = Role.USER; + + @Override + public Collection<? extends GrantedAuthority> getAuthorities() { + Collection<GrantedAuthority> authorities = new ArrayList<>(); + System.out.println("entity " + authorities); + authorities.add(new SimpleGrantedAuthority(role.toString())); + System.out.println("entity " + authorities); + return authorities; + } + + @Override + public String getUsername() { + return this.userName; + } + + @Override + public boolean isAccountNonExpired() { + return false; + } + + @Override + public boolean isAccountNonLocked() { + return false; + } + + @Override + public boolean isCredentialsNonExpired() { + return false; + } + + @Override + public boolean isEnabled() { + return false; + } + + +}