@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "authority")
public class Authority {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // PK
@Column(length = 40, nullable = false, unique = true) // 제약조건
private String name; // 권한명 ex) "ROLE_MEMBER", "ROLE_ADMIN"
}
관리자 권한과 회원 권한을 도메인을 따로 분리 시켜 도메인 설계 해주기
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private String username;
@Column(nullable = false)
@JsonIgnore
private String password;
@Transient // DB 에 반영 안함. (영속화 하지 않음)
@ToString.Exclude // toString() 결과에서 뺌.
@JsonIgnore
private String re_password; // 비밀번호 확인 입력
@ManyToMany(fetch = FetchType.EAGER)
@ToString.Exclude
@Builder.Default
@JsonIgnore
private List<Authority> authorities = new ArrayList<>();
public void addAuthoriy(Authority... authorities){
Collections.addAll(this.authorities, authorities);
} // 권한 변경
private LocalDateTime delete_at;
}
user table설계 해주기
(@ManyToMany(fetch = FetchType.EAGER)
@ToString.Exclude
@Builder.Default
@JsonIgnore
private List<Authority> authorities = new ArrayList<>();
왜 ManyToMany애노테이션을 썼냐면 권한을 가지는 유저도 여러명이고 , 유저가 가지는 권한이 회원이냐 관리자냐에에 따른 권한의 종류도 1개 이상 이기 때문에 ManyToMany = 다대다 관계
@Data
@NoArgsConstructor
@Builder
@AllArgsConstructor
@Entity(name="board")
public class Board {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private LocalDateTime created_at;
@Column(nullable = false)
private LocalDateTime modified_at;
@Column(nullable = false)
private String board_name;
@Column(nullable = false)
private String board_info;
private ColorEnum color;
private LocalDateTime delete_at;
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity(name="cards")
public class Cards {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long card_id;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String contnet;
private LocalDateTime deadline;
@Column(nullable = false)
private LocalDateTime created_at;
@Column(nullable = false)
private LocalDateTime modified_at;
private LocalDateTime deleted_at;
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name="colums")
public class Colums {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private String title;
private LocalDateTime deleted_at;
@ManyToOne(optional = false) // notnull+빈값이 들어가면 안딤
@JoinColumn(name = "board_id")
@Column(nullable = false)
private Board board;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(name="comments")
public class Comments {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long comment_id;
@Column(nullable = false)
private String content;
@Column(nullable = false)
private LocalDateTime created_at;
@Column(nullable = false)
private LocalDateTime modified;
@Column(nullable = false)
private LocalDateTime deleted_at;
}
주제 선정 API, ERD 설계, 디자인이 끝나고 본격적으로 개발 시작하기. (0) | 2024.01.09 |
---|---|
국비 프로젝트 시작!!! 해커톤에 참가하기 아이디어, 주제 선정, ERD설계, 디자인 정하기 (0) | 2023.11.26 |
댓글 영역