diff --git a/src/main/java/com/postsquad/scoup/web/group/domain/Group.java b/src/main/java/com/postsquad/scoup/web/group/domain/Group.java index 1c580e25..143969b2 100644 --- a/src/main/java/com/postsquad/scoup/web/group/domain/Group.java +++ b/src/main/java/com/postsquad/scoup/web/group/domain/Group.java @@ -2,21 +2,12 @@ import com.postsquad.scoup.web.common.BaseEntity; import com.postsquad.scoup.web.group.controller.request.GroupModificationRequest; -import com.postsquad.scoup.web.schedule.domain.ConfirmedSchedule; import com.postsquad.scoup.web.schedule.domain.Schedule; -import com.postsquad.scoup.web.schedule.domain.ScheduleCandidate; import com.postsquad.scoup.web.user.domain.User; import lombok.*; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; import javax.persistence.*; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import java.util.*; @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @@ -39,6 +30,14 @@ public class Group extends BaseEntity { @OneToMany(mappedBy = "group", cascade = CascadeType.ALL) private final List schedules = new ArrayList<>(); + @ManyToMany + @JoinTable( + name = "group_member", + joinColumns = @JoinColumn(name = "group_id"), + inverseJoinColumns = @JoinColumn(name = "user_id") + ) + private final List members = new ArrayList<>(); + protected Group(String name, String description, User owner) { this.name = name; this.description = description; @@ -72,4 +71,9 @@ public void addSchedule(Schedule schedule) { public void addSchedules(List schedules) { this.schedules.addAll(schedules); } + + public void addMember(User user) { + user.getJoinedGroups().add(this); + this.members.add(user); + } } diff --git a/src/main/java/com/postsquad/scoup/web/user/domain/User.java b/src/main/java/com/postsquad/scoup/web/user/domain/User.java index 6cb62876..0b8aea78 100644 --- a/src/main/java/com/postsquad/scoup/web/user/domain/User.java +++ b/src/main/java/com/postsquad/scoup/web/user/domain/User.java @@ -2,6 +2,7 @@ import com.postsquad.scoup.web.auth.OAuthType; import com.postsquad.scoup.web.common.BaseEntity; +import com.postsquad.scoup.web.group.domain.Group; import lombok.*; import javax.persistence.*; @@ -36,6 +37,9 @@ public class User extends BaseEntity { @CollectionTable(name = "oauth_user", joinColumns = @JoinColumn(name = "user_id")) private List oAuthUsers = new ArrayList<>(); + @ManyToMany(mappedBy = "members") + private List joinedGroups = new ArrayList<>(); + protected User(String nickname, String username, String email, String avatarUrl, String password, List oAuthUsers) { this.nickname = nickname; this.username = username;