diff --git a/src/main/java/com/jangburich/domain/team/domain/Team.java b/src/main/java/com/jangburich/domain/team/domain/Team.java index 2cde16e..3634cb6 100644 --- a/src/main/java/com/jangburich/domain/team/domain/Team.java +++ b/src/main/java/com/jangburich/domain/team/domain/Team.java @@ -1,11 +1,17 @@ package com.jangburich.domain.team.domain; +import java.util.HashSet; +import java.util.Set; + import com.jangburich.domain.common.BaseEntity; +import com.jangburich.domain.user.domain.User; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.ManyToMany; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -29,6 +35,9 @@ public class Team extends BaseEntity { @Column(name = "member_limit") private Integer memberLimit; + @ManyToMany(mappedBy = "teams") + private Set users = new HashSet<>(); + public void updatePoint(Integer point) { this.point += point; } diff --git a/src/main/java/com/jangburich/domain/user/domain/User.java b/src/main/java/com/jangburich/domain/user/domain/User.java index 4079231..55eacb6 100644 --- a/src/main/java/com/jangburich/domain/user/domain/User.java +++ b/src/main/java/com/jangburich/domain/user/domain/User.java @@ -1,5 +1,8 @@ package com.jangburich.domain.user.domain; +import java.util.HashSet; +import java.util.Set; + import com.jangburich.domain.common.BaseEntity; import com.jangburich.domain.team.domain.Team; import jakarta.persistence.Column; @@ -9,6 +12,8 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Getter; @@ -50,9 +55,14 @@ public class User extends BaseEntity { @Column(name = "role") private String role; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "team_id") - private Team team; + + @ManyToMany + @JoinTable( + name = "user_team", + joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "team_id") + ) + private Set teams = new HashSet<>(); public static User create(String userId, String nickname, String image, String role) { User newUser = new User();