Skip to content

Commit

Permalink
merge: develop branch와 merge #246
Browse files Browse the repository at this point in the history
  • Loading branch information
leegwichan committed Aug 23, 2024
2 parents 8c576e8 + 927da49 commit 0187e4a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

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")
Optional<Room> findByUuidWithLock(String uuid);

List<Room> findAllByLastModifiedAtBefore(LocalDateTime lastModifiedAt);

Optional<Room> findByUuid(String uuid);
}
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,5 +647,14 @@ class 방에_참여_가능_여부 {
// then
assertThat(actual.isJoinable()).isFalse();
}

@Test
void 존재하지_않는_방에_참여할_수_없다() {
// when
RoomStatusResponse actual = roomFacade.getRoomStatus("NotExistUuid");

// then
assertThat(actual.isJoinable()).isFalse();
}
}
}
20 changes: 13 additions & 7 deletions frontend/src/apis/room.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import fetcher from './fetcher';

import { API_URL } from '@/constants/url';
import {
RoomInfo,
CreateOrEnterRoomResponse,
Category,
RoomSetting,
RoomSettingApply,
} from '@/types/room';
import { RoomInfo, CreateOrEnterRoomResponse, Category, RoomSettingApply } from '@/types/room';


interface CategoryResponse {
categories: Category[];
Expand Down Expand Up @@ -131,3 +126,14 @@ export const exitRoom = async (roomId: number, memberId: number) => {
url: API_URL.deleteRoom(roomId, memberId),
});
};

// 방 참여여부 확인
export const isJoinableRoom = async (roomUuid: string): Promise<{ isJoinable: boolean }> => {
const res = await fetcher.get({
url: API_URL.isJoinableRoom(roomUuid),
});

const data = await res.json();

return data;
};
2 changes: 2 additions & 0 deletions frontend/src/constants/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const API_URL = {
applyRoomSetting: (roomId: number) => `${BASE_URL}/api/balances/rooms/${roomId}`,
deleteRoom: (roomId: number, memberId: number) =>
`${BASE_URL}/api/balances/rooms/${roomId}/members/${memberId}`,
isJoinableRoom: (roomUuid: string) => `${BASE_URL}/api/balances/rooms/${roomUuid}/status`,
};

type API_URL_KEYS = keyof typeof API_URL;
Expand All @@ -46,6 +47,7 @@ export const MOCK_API_URL: Record<API_URL_KEYS, string> = {
categoryList: `${BASE_URL}/api/balances/categories`,
applyRoomSetting: `${BASE_URL}/api/balances/rooms/:roomId`,
deleteRoom: `${BASE_URL}/api/balances/rooms/:roomId/members/:memberId`,
isJoinableRoom: `${BASE_URL}/api/balances/rooms/:roomUuid/status`,
};

export const INVITE_URL = (roomUuid: string) => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/mocks/handlers/roomHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const enterRoomHandler = () => {
return HttpResponse.json(ENTER_ROOM_RESPONSE, { status: 201 });
};

const isJoinableRoomHandler = () => {
return HttpResponse.json({ isJoinable: false }, { status: 200 });
};

export const roomHandler = [
http.get(MOCK_API_URL.getRoomInfo, getRoomInfoHandler),
http.post(MOCK_API_URL.room, createRoomHandler),
Expand All @@ -65,4 +69,5 @@ export const roomHandler = [
http.get(MOCK_API_URL.categoryList, getCategoryListHandler),
http.patch(MOCK_API_URL.applyRoomSetting, applyRoomSettingHandler),
http.delete(MOCK_API_URL.deleteRoom, deleteRoomHandler),
http.get(MOCK_API_URL.isJoinableRoom, isJoinableRoomHandler),
];
18 changes: 18 additions & 0 deletions frontend/src/pages/NicknamePage/NicknamePage.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ export const nicknameInput = css`
background-color: ${Theme.color.gray200};
outline: none;
`;
export const noVoteTextContainer = css`
display: flex;
flex-direction: column;
align-items: center;
`;

export const noVoteText = css`
display: flex;
justify-content: center;
align-items: center;
height: 8vh;
${Theme.typography.headline3}
`;

export const angryImage = css`
width: 16rem;
height: 14rem;
`;
22 changes: 21 additions & 1 deletion frontend/src/pages/NicknamePage/NicknamePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

import { useQuery } from '@tanstack/react-query';
import { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import { useRecoilState, useRecoilValue } from 'recoil';
Expand All @@ -8,9 +10,14 @@ import {
nicknameInput,
profileWrapper,
profileImg,
noVoteTextContainer,
noVoteText,
angryImage,
} from './NicknamePage.styled';
import { useMakeOrEnterRoom } from './useMakeOrEnterRoom';

import { isJoinableRoom } from '@/apis/room';
import AngryDdangkong from '@/assets/images/angryDdangkong.png';
import SillyDdangkong from '@/assets/images/sillyDdangkong.png';
import AlertModal from '@/components/common/AlertModal/AlertModal';
import Button from '@/components/common/Button/Button';
Expand All @@ -26,11 +33,24 @@ const NicknamePage = () => {
const { roomUuid } = useParams();
const [, setRoomUuidState] = useRecoilState(roomUuidState);

const { data } = useQuery({
queryKey: ['isJoinable', roomUuid],
queryFn: async () => isJoinableRoom(roomUuid || ''),
});

useEffect(() => {
if (roomUuid) {
setRoomUuidState(roomUuid);
}
}, []);
}, [roomUuid, setRoomUuidState]);

if (roomUuid && !data?.isJoinable)
return (
<div css={noVoteTextContainer}>
<img src={AngryDdangkong} alt="화난 땅콩" css={angryImage} />
<span css={noVoteText}>잘못된 링크에 접속했어요 :{`)`}</span>
</div>
);

return (
<Content>
Expand Down

0 comments on commit 0187e4a

Please sign in to comment.