Skip to content

Commit

Permalink
feat: 쿠키를 통한 유저 정보 조회 API 변경 #357
Browse files Browse the repository at this point in the history
  • Loading branch information
jhon3242 committed Oct 22, 2024
1 parent 8c395c1 commit 553358e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
12 changes: 6 additions & 6 deletions backend/src/docs/asciidoc/room.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ include::{snippets}/room/join/response-cookies.adoc[]

'''

=== 방 재참여
=== 사용자 정보 조회

==== curl

include::{snippets}/room/rejoin/curl-request.adoc[]
include::{snippets}/room/member/curl-request.adoc[]

==== request

include::{snippets}/room/rejoin/http-request.adoc[]
include::{snippets}/room/member/http-request.adoc[]

request cookies

include::{snippets}/room/rejoin/request-cookies.adoc[]
include::{snippets}/room/member/request-cookies.adoc[]

==== response

include::{snippets}/room/rejoin/http-response.adoc[]
include::{snippets}/room/member/http-response.adoc[]

response fields

include::{snippets}/room/join/response-fields.adoc[]
include::{snippets}/room/member/response-fields.adoc[]

'''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ddangkong.facade.room.dto.RoomInfoResponse;
import ddangkong.facade.room.dto.RoomJoinRequest;
import ddangkong.facade.room.dto.RoomJoinResponse;
import ddangkong.facade.room.dto.RoomMemberResponse;
import ddangkong.facade.room.dto.RoomSettingRequest;
import ddangkong.facade.room.dto.RoomStatusResponse;
import ddangkong.facade.room.dto.RoundFinishedResponse;
Expand Down Expand Up @@ -47,9 +48,9 @@ public RoomJoinResponse createRoom(@Valid @RequestBody RoomJoinRequest request,
return roomJoinResponse;
}

@GetMapping("/balances/rooms/rejoin")
public RoomJoinResponse rejoinRoom(@CookieValue(name = "${cookie.rejoin-key}") String cookieValue) {
return roomFacade.rejoinRoom(rejoinCookieEncryptor.getDecodedCookieValue(cookieValue));
@GetMapping("/balances/rooms/member")
public RoomMemberResponse getRoomMemberInfo(@CookieValue(name = "${cookie.rejoin-key}") String cookieValue) {
return roomFacade.getRoomMemberInfo(rejoinCookieEncryptor.getDecodedCookieValue(cookieValue));
}

@Polling
Expand Down
5 changes: 3 additions & 2 deletions backend/src/main/java/ddangkong/facade/room/RoomFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ddangkong.facade.room.dto.InitialRoomResponse;
import ddangkong.facade.room.dto.RoomInfoResponse;
import ddangkong.facade.room.dto.RoomJoinResponse;
import ddangkong.facade.room.dto.RoomMemberResponse;
import ddangkong.facade.room.dto.RoomSettingRequest;
import ddangkong.facade.room.dto.RoomStatusResponse;
import ddangkong.facade.room.dto.RoundFinishedResponse;
Expand Down Expand Up @@ -53,10 +54,10 @@ public RoomJoinResponse joinRoom(String nickname, String uuid) {
}

@Transactional(readOnly = true)
public RoomJoinResponse rejoinRoom(Long memberId) {
public RoomMemberResponse getRoomMemberInfo(Long memberId) {
Member member = memberService.getMemberById(memberId);
Room room = member.getRoom();
return new RoomJoinResponse(room.getId(), room.getUuid(), new MemberResponse(member));
return new RoomMemberResponse(room.getId(), room.getUuid(), new MemberResponse(member));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ddangkong.facade.room.dto;

import ddangkong.facade.room.member.dto.MemberResponse;

public record RoomMemberResponse(
Long roomId,
String roomUuid,
MemberResponse member
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class 쿠키 {
}

@Test
void 쿠키를_통해_방에_재참여___있다() {
void 쿠키를_통해_사용자_정보를_조회___있다() {
// given
RoomJoinRequest body = new RoomJoinRequest("참가자");
String cookie = RestAssured.given().log().all()
Expand All @@ -362,7 +362,7 @@ class 쿠키 {
RoomJoinResponse roomJoinResponse = RestAssured.given().log().all()
.contentType(ContentType.JSON)
.cookie("test_cookie", cookie)
.when().get("/api/balances/rooms/rejoin")
.when().get("/api/balances/rooms/member")
.then().contentType(ContentType.JSON).log().all()
.statusCode(200)
.extract().as(RoomJoinResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import ddangkong.facade.room.dto.RoomInfoResponse;
import ddangkong.facade.room.dto.RoomJoinRequest;
import ddangkong.facade.room.dto.RoomJoinResponse;
import ddangkong.facade.room.dto.RoomMemberResponse;
import ddangkong.facade.room.dto.RoomSettingRequest;
import ddangkong.facade.room.dto.RoomSettingResponse;
import ddangkong.facade.room.dto.RoomStatusResponse;
Expand Down Expand Up @@ -218,24 +219,24 @@ class 방_참여 {
}

@Nested
class _재참여 {
class 사용자_정보_조회 {

private static final String ENDPOINT = "/api/balances/rooms/rejoin";
private static final String ENDPOINT = "/api/balances/rooms/member";

@Test
void 방에_재참여하여_유저_정보를_조회한다() throws Exception {
void 사용자_정보를_조회한다() throws Exception {
// given
RoomJoinResponse response = new RoomJoinResponse(1L, "488fd79f92a34131bf2a628bd58c5d2c",
RoomMemberResponse response = new RoomMemberResponse(1L, "488fd79f92a34131bf2a628bd58c5d2c",
new MemberResponse(2L, "타콩", false));
when(roomFacade.rejoinRoom(anyLong())).thenReturn(response);
when(roomFacade.getRoomMemberInfo(anyLong())).thenReturn(response);

//when & then
mockMvc.perform(get(ENDPOINT)
.contentType(MediaType.APPLICATION_JSON)
.cookie(new Cookie("test_cookie", "oNnHwjSR1G4E5L8Mute61w=="))
)
.andExpect(status().isOk())
.andDo(document("room/rejoin",
.andDo(document("room/member",
requestCookies(
cookieWithName("test_cookie").description("사용자 인증에 필요한 쿠키(쿠키의 키 값은 UUID로 예측할 수 없는 값이 들어감)")
),
Expand Down
11 changes: 6 additions & 5 deletions backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import ddangkong.facade.room.dto.InitialRoomResponse;
import ddangkong.facade.room.dto.RoomInfoResponse;
import ddangkong.facade.room.dto.RoomJoinResponse;
import ddangkong.facade.room.dto.RoomMemberResponse;
import ddangkong.facade.room.dto.RoomSettingRequest;
import ddangkong.facade.room.dto.RoomStatusResponse;
import ddangkong.facade.room.dto.RoundFinishedResponse;
Expand Down Expand Up @@ -126,18 +127,18 @@ class 방_참여 {
}

@Nested
class _재참여 {
class 사용자_정보_조회 {

@Test
void 이전_방에_재참여한다() {
void 사용자_정보를_조회한다() {
// given
String nickname = "나는참가자";
String uuid = "uuid4";
MemberResponse expectedMemberResponse = new MemberResponse(14L, nickname, false);
roomFacade.joinRoom(nickname, uuid);

// when
RoomJoinResponse actual = roomFacade.rejoinRoom(14L);
RoomMemberResponse actual = roomFacade.getRoomMemberInfo(14L);

// then
assertAll(
Expand All @@ -148,12 +149,12 @@ class 방_재참여 {
}

@Test
void 존재하지_않는_아이디로_방에_재참여할__없다() {
void 존재하지_않는_아이디로_사용자_정보를_조회할__없다() {
// given
Long notExistMemberId = 0L;

// when & then
assertThatThrownBy(() -> roomFacade.rejoinRoom(notExistMemberId))
assertThatThrownBy(() -> roomFacade.getRoomMemberInfo(notExistMemberId))
.isExactlyInstanceOf(InvalidMemberIdException.class);
}
}
Expand Down

0 comments on commit 553358e

Please sign in to comment.