Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.back.matchduo.domain.party.dto.request;

public record PartyCloseRequest(
Long partyId
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.back.matchduo.domain.party.dto.request;

import jakarta.validation.constraints.NotEmpty;

import java.util.List;

public record PartyMemberAddRequest(
@NotEmpty(message = "추가할 유저를 최소 1명 이상 선택해주세요.")
List<Long> targetUserIds // 다인파티 확정성 고려하여 List로 받음
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.back.matchduo.domain.party.dto.response;

import com.back.matchduo.domain.party.entity.PartyMemberRole;
import com.back.matchduo.domain.party.entity.PartyStatus;

import java.time.LocalDateTime;
import java.util.List;

public record MyPartyListResponse(
List<MyPartyDto> parties
) {
public record MyPartyDto(
Long partyId,
Long postId,
String postTitle,
String gameMode,
PartyStatus status,
PartyMemberRole myRole,
LocalDateTime joinedAt
) {
public static MyPartyDto of(Long partyId, Long postId, String postTitle, String gameMode, PartyStatus status, PartyMemberRole myRole, LocalDateTime joinedAt) {
return new MyPartyDto(
partyId,
postId,
postTitle,
gameMode,
status,
myRole,
joinedAt
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.back.matchduo.domain.party.dto.response;

import com.back.matchduo.domain.party.entity.PartyMemberRole;
import com.back.matchduo.domain.party.entity.PartyStatus;

import java.time.LocalDateTime;
import java.util.List;

public record PartyByPostResponse(
Long partyId,
Long postId,
PartyStatus status,
int currentCount,
int maxCount,
LocalDateTime createdAt,
boolean isJoined,
List<PartyMemberDto> members
) {
public record PartyMemberDto(
Long partyMemberId,
Long userId,
String nickname,
String profileImage,
PartyMemberRole role
) {
public static PartyMemberDto of(Long partyMemberId, Long userId, String nickname, String profileImage, PartyMemberRole role) {
return new PartyMemberDto(partyMemberId, userId, nickname, profileImage, role);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.back.matchduo.domain.party.dto.response;

import java.time.LocalDateTime;

public record PartyCloseResponse(
Long partyId,
String status, // "CLOSED"
LocalDateTime closedAt
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.back.matchduo.domain.party.dto.response;

import com.back.matchduo.domain.party.entity.PartyMember;
import com.back.matchduo.domain.party.entity.PartyMemberRole;
import com.back.matchduo.domain.party.entity.PartyMemberState;

import java.time.LocalDateTime;

public record PartyMemberAddResponse(
Long partyMemberId,
Long userId,
String nickname,
String profileImage,
PartyMemberRole role,// LEADER / MEMBER
PartyMemberState state,// JOINED
LocalDateTime joinedAt
) {
public static PartyMemberAddResponse of(PartyMember member, String nickname, String profileImage) {
return new PartyMemberAddResponse(
member.getId(),
member.getUserId(),
nickname,
profileImage,
member.getRole(),
member.getState(),
member.getJoinedAt()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.back.matchduo.domain.party.dto.response;

import com.back.matchduo.domain.party.entity.PartyMemberRole;

import java.time.LocalDateTime;
import java.util.List;

public record PartyMemberListResponse(
Long partyId,
int currentCount,
int maxCount,
List<PartyMemberDto> members
) {
public record PartyMemberDto(
Long partyMemberId,
Long userId,
String nickname,
String profileImage,
PartyMemberRole role, // LEADER / MEMBER
LocalDateTime joinedAt
) {
public static PartyMemberDto of(Long partyMemberId, Long userId, PartyMemberRole role, LocalDateTime joinedAt, String nickname, String profileImage) {
return new PartyMemberDto(
partyMemberId,
userId,
nickname,
profileImage,
role,
joinedAt
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.back.matchduo.domain.party.dto.response;

import com.back.matchduo.domain.party.entity.PartyMember;
import java.time.LocalDateTime;

public record PartyMemberRemoveResponse(
Long partyMemberId,
Long userId,
String state,// "LEFT"
LocalDateTime leftAt
) {
public static PartyMemberRemoveResponse from(PartyMember member) {
return new PartyMemberRemoveResponse(
member.getId(),
member.getUserId(),
member.getState().name(),
member.getLeftAt()
);
}
}
57 changes: 57 additions & 0 deletions src/main/java/com/back/matchduo/domain/party/entity/Party.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,67 @@
package com.back.matchduo.domain.party.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "party")
public class Party {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "party_id")
private Long id;

@Column(name = "post_id", nullable = false)
private Long postId;

@Column(name = "leader_id", nullable = false)
private Long leaderId;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private PartyStatus status;

@Column(name = "created_at", nullable = false)
private LocalDateTime createdAt;

// 자동 파티완료 된 경우
@Column(name = "expires_at", nullable = false)
private LocalDateTime expiresAt;

// 수동 파티완료, 자동 파티완료 된 경우의 시간
@Column(name = "closed_at")
private LocalDateTime closedAt;


public Party(Long postId, Long leaderId) {
this.postId = postId;
this.leaderId = leaderId;
this.status = PartyStatus.ACTIVE;
this.createdAt = LocalDateTime.now();
this.expiresAt = this.createdAt.plusHours(6);
}


// 파티장이 수동 파티완료 처리
public void closeParty() {
if (this.status == PartyStatus.ACTIVE) {
this.status = PartyStatus.CLOSED;
this.closedAt = LocalDateTime.now(); // 현재 시간 기록
}
}

// 스케줄러가 자동 파티완료 처리
public void expireParty() {
if (this.status == PartyStatus.ACTIVE) {
this.status = PartyStatus.CLOSED;
this.closedAt = this.expiresAt; // 만료 예정 시간이 곧 종료 시간
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.back.matchduo.domain.party.entity;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(
// 파티 중복 참여 방지 unique
name = "party_member",
uniqueConstraints = {
@UniqueConstraint(
name = "uk_party_member_user",
columnNames = {"party_id", "user_id"}
)
}
)
public class PartyMember {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "party_member_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "party_id", nullable = false)
private Party party;

@Column(name = "user_id", nullable = false)
private Long userId;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private PartyMemberRole role; // LEADER, MEMBER

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private PartyMemberState state; // JOINED, LEFT

@Column(name = "joined_at", nullable = false)
private LocalDateTime joinedAt;

@Column(name = "left_at")
private LocalDateTime leftAt;


public PartyMember(Party party, Long userId, PartyMemberRole role) {
this.party = party;
this.userId = userId;
this.role = role;
this.state = PartyMemberState.JOINED;
this.joinedAt = LocalDateTime.now();
}


public void leaveParty() {
this.state = PartyMemberState.LEFT;
this.leftAt = LocalDateTime.now();
}

// 나갔던 유저가 다시 들어올 때 사용
public void rejoinParty() {
this.state = PartyMemberState.JOINED;
this.joinedAt = LocalDateTime.now();
this.leftAt = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.back.matchduo.domain.party.entity;

public enum PartyMemberRole {
LEADER, // 파티장
MEMBER // 파티원
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.back.matchduo.domain.party.entity;

public enum PartyMemberState {
JOINED, // 참여 중
LEFT, // 나감 (탈퇴/강퇴)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.back.matchduo.domain.party.entity;

public enum PartyStatus {
ACTIVE, // 모집완료 시
CLOSED // 모집중 , 게임완료(수동, 6시간 자동 포함)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.back.matchduo.domain.party.repository;

import com.back.matchduo.domain.party.entity.PartyMember;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface PartyMemberRepository extends JpaRepository<PartyMember, Long> {

// 1. 특정 파티의 멤버 목록 조회 (가입된 상태만 가져오거나, 전체 다 가져오거나)
List<PartyMember> findByPartyId(Long partyId);

// 2. 내가 참여한 파티 목록 조회
List<PartyMember> findByUserId(Long userId);

// 3. 이미 참여했는지 확인 (중복 참여 방지)
boolean existsByPartyIdAndUserId(Long partyId, Long userId);

// 4. 특정 파티에서 내 멤버 정보 찾기
Optional<PartyMember> findByPartyIdAndUserId(Long partyId, Long userId);
}
Loading