From fe87c9a95f6c013b9a6f1d1cf53d00a76c540eb7 Mon Sep 17 00:00:00 2001 From: ohinhyuk <8156217@naver.com> Date: Fri, 28 Jul 2023 11:27:26 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=9B=90=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathonOne/hackathon/domain/Member.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/java/com/hackathonOne/hackathon/domain/Member.java b/src/main/java/com/hackathonOne/hackathon/domain/Member.java index 04b1a90..975a1d4 100644 --- a/src/main/java/com/hackathonOne/hackathon/domain/Member.java +++ b/src/main/java/com/hackathonOne/hackathon/domain/Member.java @@ -1,4 +1,55 @@ package com.hackathonOne.hackathon.domain; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; + +@Entity +@Getter @Setter public class Member { + + @Id @GeneratedValue + @Column(name="member_id") + private Long id; + + private String name; + + private String email; + + @OneToMany(mappedBy="member", cascade = CascadeType.ALL) + private List allergies = new ArrayList<>(); + @OneToMany(mappedBy="member", cascade = CascadeType.ALL) + private List canEats = new ArrayList<>(); + @OneToMany(mappedBy="member", cascade = CascadeType.ALL) + private List specialTypes = new ArrayList<>(); + + //== 연관관계 메서드 ==// +// public void addCanEat(CanEat canEat){ +// CanEats.add(canEat); +// CanEat.setMember(this); +// } + public void addAllergy(Allergy allergy){ + Allergies.add(allergy); + Allergy.setMember(this); + } + public void addSpecialType(SpecialType specialType){ + SpecialTypes.add(specialType); + SpecialType.setMember(this); + } + + public static Member createMember(Member member, SpecialType... specialTypes, Allergy... allergies){ + + for(SpecialType specialType : specialTypes){ + member.addSpecialType(specialType); + } + + for(Allergy allergy : allergies){ + member.addAllergy(allergy); + } + + return member; + } + }