Skip to content

Commit

Permalink
merge: 방 참여 가능 조회 API 수정 #246
Browse files Browse the repository at this point in the history
  • Loading branch information
leegwichan authored Aug 23, 2024
2 parents 927da49 + 0187e4a commit 90175bb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public interface RoomRepository extends JpaRepository<Room, Long> {

Optional<Room> findByUuid(String uuid);

@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints(@QueryHint(name = "jakarta.persistence.lock.timeout", value = "5000"))
@Query("SELECT r FROM Room r WHERE r.uuid = :uuid")
Expand Down
9 changes: 7 additions & 2 deletions backend/src/main/java/ddangkong/facade/room/RoomFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import ddangkong.domain.room.member.RoomMembers;
import ddangkong.facade.room.dto.InitialRoomResponse;
import ddangkong.facade.room.dto.RoomInfoResponse;
import ddangkong.facade.room.dto.RoomStatusResponse;
import ddangkong.facade.room.dto.RoomJoinResponse;
import ddangkong.facade.room.dto.RoomSettingRequest;
import ddangkong.facade.room.dto.RoomStatusResponse;
import ddangkong.facade.room.dto.RoundFinishedResponse;
import ddangkong.facade.room.member.dto.MemberResponse;
import ddangkong.service.balance.content.BalanceContentService;
Expand All @@ -18,6 +18,7 @@
import ddangkong.service.room.member.MemberService;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -144,7 +145,11 @@ private void delete(Room room) {

@Transactional(readOnly = true)
public RoomStatusResponse getRoomStatus(String uuid) {
Room room = roomService.getRoomWithLock(uuid);
Optional<Room> roomOptional = roomService.getRoom(uuid);
if (roomOptional.isEmpty()) {
return new RoomStatusResponse(false);
}
Room room = roomOptional.get();
return new RoomStatusResponse(room.isGameReady());
}

Expand Down
6 changes: 6 additions & 0 deletions backend/src/main/java/ddangkong/service/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ddangkong.exception.room.NotFoundRoomException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -33,6 +34,11 @@ public Room getRoomWithLock(String uuid) {
.orElseThrow(NotFoundRoomException::new);
}

@Transactional(readOnly = true)
public Optional<Room> getRoom(String uuid) {
return roomRepository.findByUuid(uuid);
}

@Transactional(readOnly = true)
public List<Room> findRoomsBefore(LocalDateTime modifiedAt) {
return roomRepository.findAllByLastModifiedAtBefore(modifiedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ private void startRound(RoomContent roomContent, int timeLimit) {
public void deleteRoomContents(Room room) {
List<RoomContent> roomContents = roomContentRepository.findAllByRoom(room);
roomContentRepository.deleteAllInBatch(roomContents);

if (room.getTotalRound() != roomContents.size()) {
log.error("방의 총 라운드와 방 컨텐츠 개수가 일치하지 않습니다. roomId: {}, totalRound: {}, roomContent 개수: {}",
room.getId(), room.getTotalRound(), roomContents.size());
}
}

@Transactional(readOnly = true)
Expand Down
10 changes: 6 additions & 4 deletions backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,12 @@ class 방에_참여_가능_여부 {
}

@Test
void 존재하지_않는_방에_참여_가능_여부를_조회하면_예외가_발생한다() {
// when & then
assertThatThrownBy(() -> roomFacade.getRoomStatus("NotExist"))
.isExactlyInstanceOf(NotFoundRoomException.class);
void 존재하지_않는_방에_참여할_수_없다() {
// when
RoomStatusResponse actual = roomFacade.getRoomStatus("NotExistUuid");

// then
assertThat(actual.isJoinable()).isFalse();
}
}
}
1 change: 1 addition & 0 deletions frontend/src/apis/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fetcher from './fetcher';
import { API_URL } from '@/constants/url';
import { RoomInfo, CreateOrEnterRoomResponse, Category, RoomSettingApply } from '@/types/room';


interface CategoryResponse {
categories: Category[];
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/NicknamePage/NicknamePage.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const nicknameInput = css`
background-color: ${Theme.color.gray200};
outline: none;
`;

export const noVoteTextContainer = css`
display: flex;
flex-direction: column;
Expand All @@ -62,4 +61,4 @@ export const noVoteText = css`
export const angryImage = css`
width: 16rem;
height: 14rem;
`;
`;
1 change: 1 addition & 0 deletions frontend/src/pages/NicknamePage/NicknamePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { useQuery } from '@tanstack/react-query';
import { useEffect } from 'react';
import { useParams } from 'react-router-dom';
Expand Down

0 comments on commit 90175bb

Please sign in to comment.