Skip to content

Commit

Permalink
feature: PR #11 코드 리뷰 반영 (#29)
Browse files Browse the repository at this point in the history
feature: PR #11 코드 리뷰 반영
  • Loading branch information
Lee-Dahyeon authored Nov 6, 2024
2 parents 8504139 + e6f17e6 commit fac7abd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<User, Long> {
public interface ParticipantRepository extends JpaRepository<Participant, Long> {

// 같은 방에 있는 사람들 id(PK) 리스트
@Query(value = "SELECT p.id FROM Participant p WHERE p.workspace.id=:workspaceId")
List<Long> findByVisitorMatch(Long workspaceId);
List<Long> 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Participant> participantOptional =
participantRepository.findByUserIdAndWorkspaceId(id, workspaceId);
participantOptional.get().accept();
// participantRepository.updateByIdAndWorkspace(id, workspaceId);
participantOptional.accept();

// participant테이블에서 roomNumber로 들어온 숫자를 통해 누가 있는지 파악
List<Long> participants = participantRepository.findByVisitorMatch(workspaceId);
List<Long> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<User, Long> {
Optional<User> findByUid(String uid);
}
Original file line number Diff line number Diff line change
@@ -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<Workspace, Long> {

@Modifying
@Query(value = "UPDATE Workspace w SET w.isMatched=true WHERE w.id=:workspaceId")
void UpdateWorkspaceStatus(Long workspaceId);
}

0 comments on commit fac7abd

Please sign in to comment.