| Domain 구현1에 이어서 나머지 Domain들을 구현하자
package wonju.howcook.domain;
import lombok.Getter;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "RECIPE")
@Getter
public class Recipe {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RECIPE_ID")
private Long id;
@Column(name = "DESCRIPTION", length = 450, nullable = false)
private String description;
@Column(name = "THUMBNAIL_URL", length = 2048, nullable = false)
private String thumbnailUrl;
@Column(name = "TITLE", length = 90, nullable = false)
private String title;
@Column(name = "REFERENCE_URL", length = 2048, nullable = false)
private String referenceUrl;
@Column(name = "SERVING", nullable = false)
@Enumerated(value = EnumType.STRING)
private Serving serving;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "USER_ID")
private User user;
@OneToMany(mappedBy = "recipe")
private List<RecipeIngredient> recipeIngredients = new ArrayList<>();
@OneToMany(mappedBy = "recipe")
private List<RecipeDescription> recipeDescriptions = new ArrayList<>();
}
export default class Recipe {
...
@ManyToMany(() => User, (user) => user.bookmarks, { lazy: true, nullable: false })
likeUsers: User[];
...
}
export default class User {
...
@ManyToMany(() => Recipe, (recipe) => recipe.likeUsers, { lazy: true, nullable: false })
@JoinTable({ name: 'BOOKMARK', joinColumn: { name: 'USER_ID' }, inverseJoinColumn: { name: 'RECIPE_ID' } })
bookmarks: Recipe[];
...
}
package wonju.howcook.domain;
import lombok.Getter;
import javax.persistence.*;
@Entity
@Table(name = "RECIPE_DESCRIPTION")
@Getter
public class RecipeDescription {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RECIPE_DESCRIPTION_ID")
private Long id;
@Column(name = "IMAGE_DESCRIPTION", length = 900, nullable = false)
private String imageDescription;
@Column(name = "IMAGE_URL", length = 2048, nullable = false)
private String imageUrl;
@Column(name = "DESCRIPTION_ORDER", nullable = false)
private byte descriptionOrder;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "RECIPE_ID")
private Recipe recipe;
}
package wonju.howcook.domain;
import lombok.Getter;
import javax.persistence.*;
@Entity
@Table(name = "RECIPE_TAG")
@Getter
public class RecipeTag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RECIPE_TAG")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "RECIPE_ID")
private Recipe recipe;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "TAG_ID")
private Tag tag;
}
package wonju.howcook.domain;
import lombok.Getter;
import org.hibernate.annotations.ColumnDefault;
import javax.persistence.*;
@Entity
@Table(name = "RECIPE_INGREDIENT")
@Getter
public class RecipeIngredient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "RECIPE_INGREDIENT_ID")
private Long id;
@Column(name = "QUANTITY", nullable = false)
@ColumnDefault(value = "0")
private int amount;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "RECIPE_ID")
private Recipe recipe;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "INGREDIENT_ID")
private Ingredient ingredient;
}
package wonju.howcook.domain;
import javax.persistence.*;
@Entity
@Table(name = "BOOKMARK")
public class Bookmark {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BOOKMAKR_ID")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "USER_ID")
private User user;
@ManyToOne(optional = false)
@JoinColumn(name = "RECIPE_ID")
private Recipe recipe;
}