Skip to content

Instantly share code, notes, and snippets.

@aliwo
Created October 9, 2021 12:56
Show Gist options
  • Save aliwo/2eea04a5f410ebeaa120d1e8e52a597d to your computer and use it in GitHub Desktop.
Save aliwo/2eea04a5f410ebeaa120d1e8e52a597d to your computer and use it in GitHub Desktop.
@Getter
@NoArgsConstructor
@Entity
public class User {
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<PartyUser> parties = new ArrayList<>();
}
@Getter
@NoArgsConstructor
@Entity
public class Party {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "leader_id")
private User leader;
@OneToMany(mappedBy = "party", fetch = FetchType.LAZY)
private List<PartyUser> users = new ArrayList<>();
}
@NoArgsConstructor
@Getter
@Entity
@Table(
name="party_user",
uniqueConstraints={
@UniqueConstraint(
columnNames={"user_id","party_id"}
)
}
)
public class PartyUser extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@ManyToOne
@JoinColumn(name = "party_id")
private Party party;
@Builder
public PartyUser(User user, Party party) {
this.user = user;
this.party = party;
}
}
// party dto 를 만들고 싶다면????
@Data
public class PartyResponseDto {
private final long id;
private final String title;
private final String body;
public PartyResponseDto(Party entity) {
id = entity.getId();
title = entity.getTitle();
body = entity.getBody();
// TODO: 세상에... Party 가 User 대신 필요도 없는 PartyUser 를 가져온다... User 를 가져오려면 어떻게 해야됨??
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment