diff --git a/spring/src/main/java/umc/spring/domain/Region.java b/spring/src/main/java/umc/spring/domain/Region.java new file mode 100644 index 0000000..b1e1ed6 --- /dev/null +++ b/spring/src/main/java/umc/spring/domain/Region.java @@ -0,0 +1,22 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import lombok.*; + +import umc.spring.domain.common.BaseEntity; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Table(uniqueConstraints = {@UniqueConstraint(columnNames = "name")}) +public class Region extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "region_id") + private Long id; + + @Column(nullable = false, length = 20) + private String name; +} diff --git a/spring/src/main/java/umc/spring/domain/Restaurant.java b/spring/src/main/java/umc/spring/domain/Restaurant.java index 7b98a4a..d806446 100644 --- a/spring/src/main/java/umc/spring/domain/Restaurant.java +++ b/spring/src/main/java/umc/spring/domain/Restaurant.java @@ -4,6 +4,9 @@ import lombok.*; import umc.spring.domain.common.BaseEntity; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @@ -19,11 +22,14 @@ public class Restaurant extends BaseEntity{ @Column(nullable = false, length = 255) private String name; - @Column(nullable = false, length = 100) + @Column(length = 100) private String category; private Float score; + @Column(length = 100) + private String address; + @Column(length = 100) private String addressBig; //시 @@ -32,4 +38,25 @@ public class Restaurant extends BaseEntity{ @Column(length = 100) private String addressSmall; //동 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, name = "region_id") + private Region region; + + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) + private List missionList = new ArrayList<>(); + + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL) + private List reviewList = new ArrayList<>(); + + @Override + public String toString() { + return "Restaurant{" + + "id=" + id + + ", name='" + name + '\'' + + ", address='" + address + '\'' + + ", score=" + score + + ", region=" + (region != null ? region.getName() : "N/A") + // region의 이름 출력 + '}'; + } } diff --git a/spring/src/main/java/umc/spring/domain/Review.java b/spring/src/main/java/umc/spring/domain/Review.java index 3db1eed..b24ccff 100644 --- a/spring/src/main/java/umc/spring/domain/Review.java +++ b/spring/src/main/java/umc/spring/domain/Review.java @@ -16,7 +16,7 @@ public class Review extends BaseEntity{ @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false, length = 200) + @Column(length = 200) private String title; private Float rate;