Skip to content

Commit 994b6b3

Browse files
committed
feat(party): Party 엔티디 구현
1 parent 24e2e73 commit 994b6b3

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
package com.back.matchduo.domain.party.entity;
22

33
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.time.LocalDateTime;
49

510
@Entity
11+
@Getter
12+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
13+
@Table(name = "party")
614
public class Party {
15+
716
@Id
817
@GeneratedValue(strategy = GenerationType.IDENTITY)
18+
@Column(name = "party_id")
919
private Long id;
20+
21+
@Column(name = "post_id", nullable = false)
22+
private Long postId;
23+
24+
@Column(name = "leader_id", nullable = false)
25+
private Long leaderId;
26+
27+
@Enumerated(EnumType.STRING)
28+
@Column(nullable = false)
29+
private PartyStatus status;
30+
31+
@Column(name = "created_at", nullable = false)
32+
private LocalDateTime createdAt;
33+
34+
@Column(name = "closed_at", nullable = false)
35+
private LocalDateTime closedAt;
36+
37+
38+
public Party(Long postId, Long leaderId) {
39+
this.postId = postId;
40+
this.leaderId = leaderId;
41+
this.status = PartyStatus.ACTIVE;
42+
this.createdAt = LocalDateTime.now();
43+
this.closedAt = this.createdAt.plusHours(6);
44+
}
45+
46+
47+
public void closeParty() {
48+
if (this.status == PartyStatus.ACTIVE) {
49+
this.status = PartyStatus.CLOSED;
50+
}
51+
}
1052
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.back.matchduo.domain.party.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.time.LocalDateTime;
9+
10+
@Entity
11+
@Getter
12+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
13+
@Table(
14+
// 파티 중복 참여 방지 unique
15+
name = "party_member",
16+
uniqueConstraints = {
17+
@UniqueConstraint(
18+
name = "uk_party_member_user",
19+
columnNames = {"party_id", "user_id"}
20+
)
21+
}
22+
)
23+
public class PartyMember {
24+
25+
@Id
26+
@GeneratedValue(strategy = GenerationType.IDENTITY)
27+
@Column(name = "party_member_id")
28+
private Long id;
29+
30+
@ManyToOne(fetch = FetchType.LAZY)
31+
@JoinColumn(name = "party_id", nullable = false)
32+
private Party party;
33+
34+
@Column(name = "user_id", nullable = false)
35+
private Long userId;
36+
37+
@Enumerated(EnumType.STRING)
38+
@Column(nullable = false)
39+
private PartyMemberRole role; // LEADER, MEMBER
40+
41+
@Enumerated(EnumType.STRING)
42+
@Column(nullable = false)
43+
private PartyMemberState state; // JOINED, LEFT
44+
45+
@Column(name = "joined_at", nullable = false)
46+
private LocalDateTime joinedAt;
47+
48+
@Column(name = "left_at")
49+
private LocalDateTime leftAt;
50+
51+
52+
public PartyMember(Party party, Long userId, PartyMemberRole role) {
53+
this.party = party;
54+
this.userId = userId;
55+
this.role = role;
56+
this.state = PartyMemberState.JOINED;
57+
this.joinedAt = LocalDateTime.now();
58+
}
59+
60+
61+
public void leaveParty() {
62+
this.state = PartyMemberState.LEFT;
63+
this.leftAt = LocalDateTime.now();
64+
}
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.back.matchduo.domain.party.entity;
2+
3+
public enum PartyMemberRole {
4+
LEADER, // 파티장
5+
MEMBER // 파티원
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.back.matchduo.domain.party.entity;
2+
3+
public enum PartyMemberState {
4+
JOINED, // 참여 중
5+
LEFT, // 나감 (탈퇴/강퇴)
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.back.matchduo.domain.party.entity;
2+
3+
public enum PartyStatus {
4+
ACTIVE, // 모집완료 시
5+
CLOSED // 모집중 , 게임완료일 시
6+
}

0 commit comments

Comments
 (0)