diff --git a/build.gradle b/build.gradle index 674a9c4..905bfdb 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,6 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' implementation 'org.springdoc:springdoc-openapi-ui:1.6.12' - runtimeOnly 'com.h2database:h2' } tasks.named('test') { diff --git a/src/main/java/com/hyunsolution/dangu/participant/Participant.java b/src/main/java/com/hyunsolution/dangu/participant/domain/Participant.java similarity index 96% rename from src/main/java/com/hyunsolution/dangu/participant/Participant.java rename to src/main/java/com/hyunsolution/dangu/participant/domain/Participant.java index 46dae07..b21e3b5 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/Participant.java +++ b/src/main/java/com/hyunsolution/dangu/participant/domain/Participant.java @@ -1,4 +1,4 @@ -package com.hyunsolution.dangu.participant; +package com.hyunsolution.dangu.participant.domain; import com.hyunsolution.dangu.user.domain.User; import com.hyunsolution.dangu.workspace.domain.Workspace; diff --git a/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java b/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java index 1266dc7..764775a 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java +++ b/src/main/java/com/hyunsolution/dangu/participant/domain/ParticipantRepository.java @@ -1,24 +1,19 @@ package com.hyunsolution.dangu.participant.domain; -import com.hyunsolution.dangu.participant.Participant; -import com.hyunsolution.dangu.user.domain.User; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -public interface ParticipantRepository extends JpaRepository { +public interface ParticipantRepository extends JpaRepository { // 같은 방에 있는 사람들 id(PK) 리스트 @Query(value = "SELECT p.id FROM Participant p WHERE p.workspace.id=:workspaceId") - List findByVisitorMatch(Long workspaceId); + List findParticipantIdByWorkspaceId(Long workspaceId); // ID별 매칭버튼 클릭 여부 - @Query( - value = - "SELECT COUNT(p) >0 FROM Participant p WHERE p.id=:id AND p.participantMatch=true") - Boolean existsById(long id); + Boolean existsByIdAndParticipantMatchTrue(long id); // 개인 ID 찾기 @Query( diff --git a/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java b/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java index ffbf706..597dd02 100644 --- a/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java +++ b/src/main/java/com/hyunsolution/dangu/participant/service/ParticipantService.java @@ -1,11 +1,12 @@ package com.hyunsolution.dangu.participant.service; -import com.hyunsolution.dangu.participant.Participant; +import com.hyunsolution.dangu.participant.domain.Participant; import com.hyunsolution.dangu.participant.domain.ParticipantRepository; import com.hyunsolution.dangu.user.domain.UserRepository; import com.hyunsolution.dangu.workspace.domain.Workspace; import com.hyunsolution.dangu.workspace.domain.WorkspaceRepository; import java.util.List; +import java.util.NoSuchElementException; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,25 +22,24 @@ public class ParticipantService { @Transactional public void changeMatching(Long id, Long workspaceId) { // 상태 변경 + Participant participantOptional = + participantRepository.findByUserIdAndWorkspaceId(id, workspaceId) + .orElseThrow(()-> new NoSuchElementException("Participant not found")); - Optional participantOptional = - participantRepository.findByUserIdAndWorkspaceId(id, workspaceId); - participantOptional.get().accept(); - // participantRepository.updateByIdAndWorkspace(id, workspaceId); + participantOptional.accept(); // participant테이블에서 roomNumber로 들어온 숫자를 통해 누가 있는지 파악 - List participants = participantRepository.findByVisitorMatch(workspaceId); + List participantIds = participantRepository.findParticipantIdByWorkspaceId(workspaceId); - for (Long participant : participants) { - boolean mathingCheck = participantRepository.existsById(participant); + // 방안에 모든 참가자가 "확정"버튼을 눌렀는지 확인 + for (Long participant : participantIds) { + boolean mathingCheck = participantRepository.existsByIdAndParticipantMatchTrue(participant); if (!mathingCheck) { return; } } - // 방안에 모든 참가자가 "확정"버튼을 눌렀는지 확인하고 게임방 테이블 속 매칭 결과를 true로 바꿈 - Workspace workspace1 = workspaceRepository.findById(workspaceId).get(); - workspace1.finalAccept(); - // workspaceRepository.UpdateWorkspaceStatus(workspaceId); - + // 게임방 테이블 속 매칭 결과를 true로 바꿈 + Workspace workspace1 = workspaceRepository.findById(workspaceId).orElseThrow(()-> new NoSuchElementException("Workspace not found")); + workspace1.acceptFinal(); } } diff --git a/src/main/java/com/hyunsolution/dangu/user/domain/UserRepository.java b/src/main/java/com/hyunsolution/dangu/user/domain/UserRepository.java index d4383dd..e1d05ec 100644 --- a/src/main/java/com/hyunsolution/dangu/user/domain/UserRepository.java +++ b/src/main/java/com/hyunsolution/dangu/user/domain/UserRepository.java @@ -1,8 +1,9 @@ package com.hyunsolution.dangu.user.domain; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface UserRepository extends JpaRepository { Optional findByUid(String uid); } diff --git a/src/main/java/com/hyunsolution/dangu/workspace/domain/WorkspaceRepository.java b/src/main/java/com/hyunsolution/dangu/workspace/domain/WorkspaceRepository.java index 84dbf1e..7c7d524 100644 --- a/src/main/java/com/hyunsolution/dangu/workspace/domain/WorkspaceRepository.java +++ b/src/main/java/com/hyunsolution/dangu/workspace/domain/WorkspaceRepository.java @@ -1,10 +1,12 @@ package com.hyunsolution.dangu.workspace.domain; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; public interface WorkspaceRepository extends JpaRepository { + @Modifying @Query(value = "UPDATE Workspace w SET w.isMatched=true WHERE w.id=:workspaceId") void UpdateWorkspaceStatus(Long workspaceId); }