2023.11.22 - [Spring/[PROJECT] 도서 대여 프로그램] - 🩶 ERD 설계하기 🩶
⬆️⬆️⬆️ 기반 ⬆️⬆️⬆️
🗂️ Common - BaseEntity
· 모든 테이블에 공통적으로 들어가는 컬럼 엔티티
· 추상 클래스 선언 후 다른 클래스에서 상속 받기
· createdAt (생성시간), updatedAt (수정시간)
☑️ BaseEntity
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
public abstract class BaseEntity {
@CreatedDate
private LocalDateTime createdAt;
@LastModifiedDate
private LocalDateTime updatedAt;
}
☑️ SpringBootApplication
· JpaAuditing 사용 가능하도록 변경 : @EnableJpaAuditing
@SpringBootApplication
@EnableJpaAuditing // <--
public class StudyDApplication {
public static void main(String[] args) {
SpringApplication.run(StudyDApplication.class, args);
}
}
📝 Enums
☑️ MemberGender
· 회원 성별
public enum MemberGender {
MALE, FEMALE;
}
☑️ MemberStatus
· 회원의 활동 상태 → 회원 탈퇴 시 soft delete 을 구현하기 위한 상태 표시
public enum MemberStatus {
ACTIVE, INACTIVE
}
☑️ AlarmStatus
· 알림 상태
public enum AlarmStatus {
CHALLENGING, COMPLETE
}
🔗 Mapping
· 매핑 테이블은 따로 패키지에 모아 관리하는 것이 보기 편리
☑️ Rent
· Member - Book
· 여러 회원이 여러 권의 책 대여 가능
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Rent extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private int count;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "book_id")
private Book book;
}
☑️ Likes
· Member - Book
· 여러 회원이 여러 권의 책에 좋아요 추가 가능
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Likes extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private boolean likeStatus;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "book_id")
private Book book;
}
☑️ BookHashtag
· Book - Hashtag
· 여러 권의 책에 여러 개의 해시태그 적용 가능
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BookHashtag extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bookHashtag_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "book_id")
private Book book;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "hashtag_id")
private Hashtag hashtag;
}
☑️ MemberAlarm
· Member - Alarm
· 여러 회원에게 여러 개의 알림 적용 가능
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class MemberAlarm extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "memberAlarm_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "alarm_id")
private Alarm alarm;
}
📌
☑️ Member
· 회원 정보
· 이메일, 비밀번호, 별명, 전화번호, 성별
· inactiveDate 비활성기간 : 일정 기간 동안 계정 비활성 상태 지속될 경우 delete (soft delete 구현)
· status 계정 상태 : 회원 가입 시 ACTIVE, 회원 탈퇴 신청 시 INACTIVE 로 전환 (전환됨과 동시에 inactiveDate 활성화)
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Member extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;
@Column(nullable = false, length = 50)
private String email;
@Column(nullable = false, columnDefinition = "TEXT")
private String password;
@Column(nullable = false, length = 10)
private String nickname;
@Column(nullable = false, length = 20)
private String phoneNum;
private LocalDateTime inactiveDate;
@Enumerated(EnumType.STRING)
private MemberGender gender;
@Enumerated(EnumType.STRING)
private MemberStatus status;
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Likes> likes = new ArrayList<>();
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Rent> rents = new ArrayList<>();
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<MemberAlarm> memberAlarms = new ArrayList<>();
}
☑️ Book
· 책 정보
· 책 이름, 책 설명, 좋아요 개수
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Book extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "book_id")
private Long id;
@Column(nullable = false, length = 20)
private String name;
@Column(nullable = false)
private String description;
private int likeCount;
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
private List<Likes> likes = new ArrayList<>();
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
private List<Rent> rents = new ArrayList<>();
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
private List<BookHashtag> bookHashtags = new ArrayList<>();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;
}
☑️ Category
· 카테고리 정보
· 카테고리 이름
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Category extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
private Long id;
@Column(nullable = false, length = 10)
private String name;
@OneToMany(mappedBy = "category")
private List<Book> books = new ArrayList<>();
}
☑️ Hashtag
· 해시태그 정보
· 해시태그 이름
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Hashtag extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "hashtag_id")
private Long id;
@Column(nullable = false, length = 10)
private String name;
@OneToMany(mappedBy = "hashtag", cascade = CascadeType.ALL)
private List<BookHashtag> bookHashtags = new ArrayList<>();
}
☑️ Alarm
· 알림 정보
· 알림 종류, 제목, 내용, 상태
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Alarm extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "alarm_id")
private Long id;
@Column(nullable = false, length = 10)
private String dtype;
@Column(nullable = false, length = 20)
private String title;
@Column(nullable = false)
private String content;
@Enumerated(EnumType.STRING)
private AlarmStatus status;
@OneToMany(mappedBy = "alarm", cascade = CascadeType.ALL)
private List<MemberAlarm> memberAlarms = new ArrayList<>();
}
'Spring > [P] 도서 대여 프로그램' 카테고리의 다른 글
🩵 Spring Security (1) 회원가입 🩵 (0) | 2023.11.27 |
---|---|
💜 MySQL DB 연결하기 (+ Docker, DataGrip) 💜 (0) | 2023.11.27 |
🖤 API 명세서 작성하기 (+ DTO) 🖤 (1) | 2023.11.22 |
🩶 ERD 설계하기 🩶 (2) | 2023.11.22 |
🤍 비즈니스 요구사항 설계하기 🤍 (5) | 2023.11.22 |