Skip to content

Commit

Permalink
♻️ Practice(#6) : 테이블 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssamssamukja committed Nov 7, 2024
1 parent 5758a2d commit 96fb51f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
22 changes: 22 additions & 0 deletions spring/src/main/java/umc/spring/domain/Region.java
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 28 additions & 1 deletion spring/src/main/java/umc/spring/domain/Restaurant.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import lombok.*;
import umc.spring.domain.common.BaseEntity;

import java.util.ArrayList;
import java.util.List;


@Entity
@Getter
Expand All @@ -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; //시

Expand All @@ -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<Mission> missionList = new ArrayList<>();

@OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL)
private List<Review> 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의 이름 출력
'}';
}
}
2 changes: 1 addition & 1 deletion spring/src/main/java/umc/spring/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 96fb51f

Please sign in to comment.