Skip to content
Snippets Groups Projects
Commit fcc322e3 authored by Gwan Ju's avatar Gwan Ju
Browse files

feat : create Comment, Post, and User entities

parent cd43ecc0
Branches
No related tags found
1 merge request!1게시글 작성, 댓글 작성, 유저 관리 기능 추가
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;
}
package com.umc.post.data.entity; package umc.spring.post.data.entity;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
@Entity @Entity
@Table(name = "Post") @Table(name = "Post")
...@@ -17,14 +19,31 @@ public class Post{ ...@@ -17,14 +19,31 @@ public class Post{
private Long id; private Long id;
@Column(nullable = false) @Column(nullable = false)
private String title; private Long userId;
@Column(nullable = false) @Column(nullable = false)
private String author; private String title;
@Column(nullable = false) @Column(nullable = false)
private String body; private String body;
@Column(nullable = false) @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<>();
} }
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment