Skip to content

Commit

Permalink
feat: 응답 DTO 변경 #214
Browse files Browse the repository at this point in the history
  • Loading branch information
jhon3242 committed Aug 21, 2024
1 parent 8df0bde commit d436579
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
10 changes: 3 additions & 7 deletions backend/src/main/java/ddangkong/facade/room/RoomFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ddangkong.facade.room.dto;

public record RoomStatusResponse(
boolean isReady,
boolean isActivated
boolean isReady
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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인지 여부")
)
));
}
Expand Down
27 changes: 9 additions & 18 deletions backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -170,21 +170,18 @@ class 방_설정_변경 {
}

@Test
void 준비중이고_유저가_존재하는__참여_가능를_조회한다() {
void 준비중인_방에_참여_가_여부를_조회한다() {
// given
Room room = roomRepository.save(
new Room("uuid", 5, RoomStatus.READY, new RoomSetting(3, 10_000, Category.IF)
));
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
Expand All @@ -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
Expand All @@ -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("존재하지 않는 방입니다.");
}
Expand Down

0 comments on commit d436579

Please sign in to comment.