Skip to content

Commit f0be4dc

Browse files
authored
Merge pull request #11 from prgrms-web-devcourse-final-project/feat/#2/party-basic
[BE/feat] Party 도메인 구현
2 parents 24e2e73 + a4437de commit f0be4dc

16 files changed

+351
-5
lines changed

src/main/java/com/back/matchduo/domain/party/dto/PartyDto.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.back.matchduo.domain.party.dto.request;
2+
3+
public record PartyCloseRequest(
4+
Long partyId
5+
) {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.back.matchduo.domain.party.dto.request;
2+
3+
import jakarta.validation.constraints.NotEmpty;
4+
5+
import java.util.List;
6+
7+
public record PartyMemberAddRequest(
8+
@NotEmpty(message = "추가할 유저를 최소 1명 이상 선택해주세요.")
9+
List<Long> targetUserIds // 다인파티 확정성 고려하여 List로 받음
10+
) {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import com.back.matchduo.domain.party.entity.PartyMemberRole;
4+
import com.back.matchduo.domain.party.entity.PartyStatus;
5+
6+
import java.time.LocalDateTime;
7+
import java.util.List;
8+
9+
public record MyPartyListResponse(
10+
List<MyPartyDto> parties
11+
) {
12+
public record MyPartyDto(
13+
Long partyId,
14+
Long postId,
15+
String postTitle,
16+
String gameMode,
17+
PartyStatus status,
18+
PartyMemberRole myRole,
19+
LocalDateTime joinedAt
20+
) {
21+
public static MyPartyDto of(Long partyId, Long postId, String postTitle, String gameMode, PartyStatus status, PartyMemberRole myRole, LocalDateTime joinedAt) {
22+
return new MyPartyDto(
23+
partyId,
24+
postId,
25+
postTitle,
26+
gameMode,
27+
status,
28+
myRole,
29+
joinedAt
30+
);
31+
}
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import com.back.matchduo.domain.party.entity.PartyMemberRole;
4+
import com.back.matchduo.domain.party.entity.PartyStatus;
5+
6+
import java.time.LocalDateTime;
7+
import java.util.List;
8+
9+
public record PartyByPostResponse(
10+
Long partyId,
11+
Long postId,
12+
PartyStatus status,
13+
int currentCount,
14+
int maxCount,
15+
LocalDateTime createdAt,
16+
boolean isJoined,
17+
List<PartyMemberDto> members
18+
) {
19+
public record PartyMemberDto(
20+
Long partyMemberId,
21+
Long userId,
22+
String nickname,
23+
String profileImage,
24+
PartyMemberRole role
25+
) {
26+
public static PartyMemberDto of(Long partyMemberId, Long userId, String nickname, String profileImage, PartyMemberRole role) {
27+
return new PartyMemberDto(partyMemberId, userId, nickname, profileImage, role);
28+
}
29+
}
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import java.time.LocalDateTime;
4+
5+
public record PartyCloseResponse(
6+
Long partyId,
7+
String status, // "CLOSED"
8+
LocalDateTime closedAt
9+
) {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import com.back.matchduo.domain.party.entity.PartyMember;
4+
import com.back.matchduo.domain.party.entity.PartyMemberRole;
5+
import com.back.matchduo.domain.party.entity.PartyMemberState;
6+
7+
import java.time.LocalDateTime;
8+
9+
public record PartyMemberAddResponse(
10+
Long partyMemberId,
11+
Long userId,
12+
String nickname,
13+
String profileImage,
14+
PartyMemberRole role,// LEADER / MEMBER
15+
PartyMemberState state,// JOINED
16+
LocalDateTime joinedAt
17+
) {
18+
public static PartyMemberAddResponse of(PartyMember member, String nickname, String profileImage) {
19+
return new PartyMemberAddResponse(
20+
member.getId(),
21+
member.getUserId(),
22+
nickname,
23+
profileImage,
24+
member.getRole(),
25+
member.getState(),
26+
member.getJoinedAt()
27+
);
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import com.back.matchduo.domain.party.entity.PartyMemberRole;
4+
5+
import java.time.LocalDateTime;
6+
import java.util.List;
7+
8+
public record PartyMemberListResponse(
9+
Long partyId,
10+
int currentCount,
11+
int maxCount,
12+
List<PartyMemberDto> members
13+
) {
14+
public record PartyMemberDto(
15+
Long partyMemberId,
16+
Long userId,
17+
String nickname,
18+
String profileImage,
19+
PartyMemberRole role, // LEADER / MEMBER
20+
LocalDateTime joinedAt
21+
) {
22+
public static PartyMemberDto of(Long partyMemberId, Long userId, PartyMemberRole role, LocalDateTime joinedAt, String nickname, String profileImage) {
23+
return new PartyMemberDto(
24+
partyMemberId,
25+
userId,
26+
nickname,
27+
profileImage,
28+
role,
29+
joinedAt
30+
);
31+
}
32+
}
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.back.matchduo.domain.party.dto.response;
2+
3+
import com.back.matchduo.domain.party.entity.PartyMember;
4+
import java.time.LocalDateTime;
5+
6+
public record PartyMemberRemoveResponse(
7+
Long partyMemberId,
8+
Long userId,
9+
String state,// "LEFT"
10+
LocalDateTime leftAt
11+
) {
12+
public static PartyMemberRemoveResponse from(PartyMember member) {
13+
return new PartyMemberRemoveResponse(
14+
member.getId(),
15+
member.getUserId(),
16+
member.getState().name(),
17+
member.getLeftAt()
18+
);
19+
}
20+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,67 @@
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+
// 자동 파티완료 된 경우
35+
@Column(name = "expires_at", nullable = false)
36+
private LocalDateTime expiresAt;
37+
38+
// 수동 파티완료, 자동 파티완료 된 경우의 시간
39+
@Column(name = "closed_at")
40+
private LocalDateTime closedAt;
41+
42+
43+
public Party(Long postId, Long leaderId) {
44+
this.postId = postId;
45+
this.leaderId = leaderId;
46+
this.status = PartyStatus.ACTIVE;
47+
this.createdAt = LocalDateTime.now();
48+
this.expiresAt = this.createdAt.plusHours(6);
49+
}
50+
51+
52+
// 파티장이 수동 파티완료 처리
53+
public void closeParty() {
54+
if (this.status == PartyStatus.ACTIVE) {
55+
this.status = PartyStatus.CLOSED;
56+
this.closedAt = LocalDateTime.now(); // 현재 시간 기록
57+
}
58+
}
59+
60+
// 스케줄러가 자동 파티완료 처리
61+
public void expireParty() {
62+
if (this.status == PartyStatus.ACTIVE) {
63+
this.status = PartyStatus.CLOSED;
64+
this.closedAt = this.expiresAt; // 만료 예정 시간이 곧 종료 시간
65+
}
66+
}
1067
}

0 commit comments

Comments
 (0)