From d4365793a4a0471f3819a94d3ec89439d4982455 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Wed, 21 Aug 2024 16:45:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=91=EB=8B=B5=20DTO=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20#214?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomController.java | 7 +++-- .../ddangkong/facade/room/RoomFacade.java | 10 ++----- .../facade/room/dto/RoomStatusResponse.java | 3 +- .../controller/room/RoomControllerTest.java | 29 +++++++------------ .../room/RoomDocumentationTest.java | 14 ++++----- .../ddangkong/facade/room/RoomFacadeTest.java | 27 ++++++----------- 6 files changed, 33 insertions(+), 57 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index 4b5cd35a9..dca7be01a 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -9,6 +9,7 @@ import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoundFinishedResponse; import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -81,8 +82,8 @@ public void resetRoom(@PathVariable @Positive Long roomId) { roomFacade.resetRoom(roomId); } - @GetMapping("/balances/rooms/{roomId}/status") - public RoomStatusResponse getRoomStatus(@Positive @PathVariable Long roomId) { - return roomFacade.getRoomStatus(roomId); + @GetMapping("/balances/rooms/{uuid}/status") + public RoomStatusResponse getRoomStatus(@NotBlank @PathVariable String uuid) { + return roomFacade.getRoomStatus(uuid); } } diff --git a/backend/src/main/java/ddangkong/facade/room/RoomFacade.java b/backend/src/main/java/ddangkong/facade/room/RoomFacade.java index 1acb69965..85afef126 100644 --- a/backend/src/main/java/ddangkong/facade/room/RoomFacade.java +++ b/backend/src/main/java/ddangkong/facade/room/RoomFacade.java @@ -91,12 +91,8 @@ public void resetRoom(Long roomId) { } @Transactional(readOnly = true) - public RoomStatusResponse getRoomStatus(Long roomId) { - Room room = roomService.getRoom(roomId); - if (!room.isReady()) { - return new RoomStatusResponse(false, true); - } - RoomMembers roomMembers = memberService.findRoomMembers(room); - return new RoomStatusResponse(room.isReady(), !roomMembers.isEmpty()); + public RoomStatusResponse getRoomStatus(String uuid) { + Room room = roomService.getRoomWithLock(uuid); + return new RoomStatusResponse(room.isReady()); } } diff --git a/backend/src/main/java/ddangkong/facade/room/dto/RoomStatusResponse.java b/backend/src/main/java/ddangkong/facade/room/dto/RoomStatusResponse.java index 51270deb9..15e5e3a1c 100644 --- a/backend/src/main/java/ddangkong/facade/room/dto/RoomStatusResponse.java +++ b/backend/src/main/java/ddangkong/facade/room/dto/RoomStatusResponse.java @@ -1,7 +1,6 @@ package ddangkong.facade.room.dto; public record RoomStatusResponse( - boolean isReady, - boolean isActivated + boolean isReady ) { } diff --git a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java index 262da5f95..420cfe33f 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java @@ -85,48 +85,39 @@ class 밸런스_게임_방_정보_조회 { } @Test - void 유저가_있고_대기중인_방_참여_가능_여부_조회() { + void 대기중인_방_참여_가능_여부_조회() { //when & then RoomStatusResponse actual = RestAssured.given() - .pathParam("roomId", 4L) - .when().get("/api/balances/rooms/{roomId}/status") + .pathParam("uuid", "uuid4") + .when().get("/api/balances/rooms/{uuid}/status") .then().contentType(ContentType.JSON).log().all() .statusCode(200) .extract().as(RoomStatusResponse.class); - assertAll( - () -> assertThat(actual.isReady()).isTrue(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isTrue(); } @Test void 게임_진행중인_방_참여_가능_여부_조회() { //when & then RoomStatusResponse actual = RestAssured.given() - .pathParam("roomId", 1L) - .when().get("/api/balances/rooms/{roomId}/status") + .pathParam("uuid", "uuid1") + .when().get("/api/balances/rooms/{uuid}/status") .then().contentType(ContentType.JSON).log().all() .statusCode(200) .extract().as(RoomStatusResponse.class); - assertAll( - () -> assertThat(actual.isReady()).isFalse(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isFalse(); } @Test void 게임_종료된_방_참여_가능_여부_조회() { //when & then RoomStatusResponse actual = RestAssured.given() - .pathParam("roomId", 5L) - .when().get("/api/balances/rooms/{roomId}/status") + .pathParam("uuid", "uuid5") + .when().get("/api/balances/rooms/{uuid}/status") .then().contentType(ContentType.JSON).log().all() .statusCode(200) .extract().as(RoomStatusResponse.class); - assertAll( - () -> assertThat(actual.isReady()).isFalse(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isFalse(); } } diff --git a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java index f31109185..29bf4317a 100644 --- a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java +++ b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java @@ -279,25 +279,23 @@ class 라운드_종료_여부 { @Nested class 방_게임_참여_가능_여부 { - private static final String ENDPOINT = "/api/balances/rooms/{roomId}/status"; + private static final String ENDPOINT = "/api/balances/rooms/{uuid}/status"; @Test void 방에서_게임이_참여_가능_여부를_조회한다() throws Exception { // given - RoomStatusResponse response = new RoomStatusResponse(true, false); - when(roomFacade.getRoomStatus(anyLong())).thenReturn(response); + RoomStatusResponse response = new RoomStatusResponse(true); + when(roomFacade.getRoomStatus(anyString())).thenReturn(response); // when & then - mockMvc.perform(get(ENDPOINT, 1)) + mockMvc.perform(get(ENDPOINT, "488fd79f92a34131bf2a628bd58c5d2c")) .andExpect(status().isOk()) .andDo(document("room/status", pathParameters( - parameterWithName("roomId").description("방 ID") + parameterWithName("uuid").description("방의 UUID") ), responseFields( - fieldWithPath("isReady").description("게임 상태가 READY인지 여부"), - fieldWithPath("isActivated").description("게임이 참여할 수 있는 상태인지 여부. " - + "방에서 멤버들이 전부 나간 경우는 삭제될 방이라고 판단하여 false가 된다.") + fieldWithPath("isReady").description("게임 상태가 READY인지 여부") ) )); } diff --git a/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java b/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java index d304750a1..0722108f4 100644 --- a/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java +++ b/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java @@ -22,8 +22,8 @@ import ddangkong.facade.BaseServiceTest; import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinResponse; -import ddangkong.facade.room.dto.RoomStatusResponse; 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 java.util.List; @@ -170,7 +170,7 @@ class 방_설정_변경 { } @Test - void 준비중이고_유저가_존재하는_방_참여_가능를_조회한다() { + void 준비중인_방에_참여_가능_여부를_조회한다() { // given Room room = roomRepository.save( new Room("uuid", 5, RoomStatus.READY, new RoomSetting(3, 10_000, Category.IF) @@ -178,13 +178,10 @@ class 방_설정_변경 { memberRepository.save(TACAN.master(room)); // when - RoomStatusResponse actual = roomFacade.getRoomStatus(room.getId()); + RoomStatusResponse actual = roomFacade.getRoomStatus(room.getUuid()); // then - assertAll( - () -> assertThat(actual.isReady()).isTrue(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isTrue(); } @Test @@ -196,13 +193,10 @@ class 방_설정_변경 { memberRepository.save(TACAN.master(room)); // when - RoomStatusResponse actual = roomFacade.getRoomStatus(room.getId()); + RoomStatusResponse actual = roomFacade.getRoomStatus(room.getUuid()); // then - assertAll( - () -> assertThat(actual.isReady()).isFalse(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isFalse(); } @Test @@ -214,19 +208,16 @@ class 방_설정_변경 { memberRepository.save(TACAN.master(room)); // when - RoomStatusResponse actual = roomFacade.getRoomStatus(room.getId()); + RoomStatusResponse actual = roomFacade.getRoomStatus(room.getUuid()); // then - assertAll( - () -> assertThat(actual.isReady()).isFalse(), - () -> assertThat(actual.isActivated()).isTrue() - ); + assertThat(actual.isReady()).isFalse(); } @Test void 존재하지_않는_방에_참여_가능_여부를_조회하면_예외가_발생한다() { // when & then - assertThatThrownBy(() -> roomFacade.getRoomStatus(-1L)) + assertThatThrownBy(() -> roomFacade.getRoomStatus("NotExist")) .isInstanceOf(BadRequestException.class) .hasMessage("존재하지 않는 방입니다."); }