From 36dc164a8294adb24e5e6b34d4d85fbecf9394c2 Mon Sep 17 00:00:00 2001 From: nowgnas Date: Tue, 21 Nov 2023 14:37:51 +0900 Subject: [PATCH] :card_file_box: Add table --- build.gradle | 1 + .../java/kr/bb/product/entity/BaseEntity.java | 2 +- .../java/kr/bb/product/entity/Category.java | 29 +++++++++++++++++++ .../java/kr/bb/product/entity/Review.java | 6 +++- .../kr/bb/product/entity/ReviewImages.java | 22 +++++++++++--- src/main/java/kr/bb/product/entity/Tag.java | 29 +++++++++++++++++++ 6 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 src/main/java/kr/bb/product/entity/Category.java create mode 100644 src/main/java/kr/bb/product/entity/Tag.java diff --git a/build.gradle b/build.gradle index 05efb7af..7b8c83f4 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'com.h2database:h2' implementation 'mysql:mysql-connector-java:8.0.33' + implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '0.1.0-alpha1' } dependencyManagement { diff --git a/src/main/java/kr/bb/product/entity/BaseEntity.java b/src/main/java/kr/bb/product/entity/BaseEntity.java index fcb2f03b..01505d25 100644 --- a/src/main/java/kr/bb/product/entity/BaseEntity.java +++ b/src/main/java/kr/bb/product/entity/BaseEntity.java @@ -23,4 +23,4 @@ public class BaseEntity { @Column(name = "is_deleted") private Boolean isDeleted; -} \ No newline at end of file +} diff --git a/src/main/java/kr/bb/product/entity/Category.java b/src/main/java/kr/bb/product/entity/Category.java new file mode 100644 index 00000000..28df8bd1 --- /dev/null +++ b/src/main/java/kr/bb/product/entity/Category.java @@ -0,0 +1,29 @@ +package kr.bb.product.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Entity +@Table(name = "category") +public class Category extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "category_id") + private Long id; + + @Column(name = "category_name") + private String categoryName; +} diff --git a/src/main/java/kr/bb/product/entity/Review.java b/src/main/java/kr/bb/product/entity/Review.java index 697947e0..7b2a6f0e 100644 --- a/src/main/java/kr/bb/product/entity/Review.java +++ b/src/main/java/kr/bb/product/entity/Review.java @@ -1,10 +1,14 @@ package kr.bb.product.entity; +import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -18,7 +22,7 @@ @AllArgsConstructor @Entity @Table(name = "review") -public class Review { +public class Review extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "review_id") diff --git a/src/main/java/kr/bb/product/entity/ReviewImages.java b/src/main/java/kr/bb/product/entity/ReviewImages.java index 9a7b4ea5..6d982680 100644 --- a/src/main/java/kr/bb/product/entity/ReviewImages.java +++ b/src/main/java/kr/bb/product/entity/ReviewImages.java @@ -1,8 +1,14 @@ package kr.bb.product.entity; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -18,9 +24,17 @@ @Table(name = "review_images") public class ReviewImages extends BaseEntity { @Id - @Column(name = "review_id") - private Long reviewId; + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "review_images_id") + private Long id; + + @Column(name = "review_image_url") + private String reviewImageUrl; + + @ManyToOne( + fetch = FetchType.LAZY, + cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) + @JoinColumn(name = "review_id") + private Review review; - @Column(name = "review_image") - private String reviewImage; } diff --git a/src/main/java/kr/bb/product/entity/Tag.java b/src/main/java/kr/bb/product/entity/Tag.java new file mode 100644 index 00000000..34b380b9 --- /dev/null +++ b/src/main/java/kr/bb/product/entity/Tag.java @@ -0,0 +1,29 @@ +package kr.bb.product.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Entity +@Table(name = "tag") +public class Tag extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "tag_id") + private Long id; + + @Column(name = "tag_name") + private String categoryName; +}