Skip to content

Commit

Permalink
feat: 탈퇴 기능 컨트롤러 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ503 committed Feb 4, 2024
1 parent a1926ac commit 0b506e6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import com.backend.blooming.authentication.presentation.anotaion.Authenticated;
import com.backend.blooming.authentication.presentation.argumentresolver.AuthenticatedUser;
import com.backend.blooming.authentication.presentation.dto.LogoutRequest;
import com.backend.blooming.authentication.presentation.dto.WithdrawRequest;
import com.backend.blooming.authentication.presentation.dto.request.ReissueAccessTokenRequest;
import com.backend.blooming.authentication.presentation.dto.response.LoginInformationResponse;
import com.backend.blooming.authentication.presentation.dto.response.SocialLoginRequest;
import com.backend.blooming.authentication.presentation.dto.response.TokenResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -60,4 +62,15 @@ public ResponseEntity<Void> logout(
return ResponseEntity.noContent()
.build();
}

@DeleteMapping(headers = "X-API-VERSION=1")
public ResponseEntity<Void> withdraw(
@Authenticated final AuthenticatedUser authenticatedUser,
@RequestBody final WithdrawRequest withdrawRequest
) {
authenticationService.withdraw(authenticatedUser.userId(), withdrawRequest.refreshToken());

return ResponseEntity.noContent()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.backend.blooming.authentication.presentation.dto;

public record WithdrawRequest(String refreshToken) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.mockito.BDDMockito.willDoNothing;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
Expand Down Expand Up @@ -227,11 +228,38 @@ class AuthenticationControllerTest extends AuthenticationControllerTestFixture {
headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰")
),
requestFields(
fieldWithPath("refreshToken").type(JsonFieldType.STRING)
.description("서비스 refresh token"),
fieldWithPath("refreshToken").type(JsonFieldType.STRING).description("서비스 refresh token"),
fieldWithPath("deviceToken").type(JsonFieldType.STRING).description("서비스 device token")
)
)
);
}

@Test
void 탈퇴를_수행한다() throws Exception {
// given
given(tokenProvider.parseToken(TokenType.ACCESS, 소셜_액세스_토큰)).willReturn(사용자_토큰_정보);
given(userRepository.existsByIdAndDeletedIsFalse(사용자_아이디)).willReturn(true);
willDoNothing().given(authenticationService).withdraw(사용자_아이디, 서비스_refresh_token);

// when & then
mockMvc.perform(delete("/auth")
.header("X-API-VERSION", 1)
.header(HttpHeaders.AUTHORIZATION, 소셜_액세스_토큰)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(탈퇴_정보_요청))
).andExpectAll(
status().isNoContent()
).andDo(print()).andDo(
restDocs.document(
requestHeaders(
headerWithName("X-API-VERSION").description("요청 버전"),
headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰")
),
requestFields(
fieldWithPath("refreshToken").type(JsonFieldType.STRING).description("서비스 refresh token")
)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.backend.blooming.authentication.infrastructure.jwt.dto.AuthClaims;
import com.backend.blooming.authentication.infrastructure.oauth.OAuthType;
import com.backend.blooming.authentication.presentation.dto.LogoutRequest;
import com.backend.blooming.authentication.presentation.dto.WithdrawRequest;
import com.backend.blooming.authentication.presentation.dto.request.ReissueAccessTokenRequest;
import com.backend.blooming.authentication.presentation.dto.response.SocialLoginRequest;

Expand Down Expand Up @@ -36,4 +37,5 @@ public class AuthenticationControllerTestFixture {
protected AuthClaims 사용자_토큰_정보 = new AuthClaims(사용자_아이디);
protected LogoutRequest 로그아웃_정보_요청 = new LogoutRequest(서비스_refresh_token, 디바이스_토큰);
protected LogoutDto 로그아웃_정보_dto = new LogoutDto(서비스_refresh_token, 디바이스_토큰);
protected WithdrawRequest 탈퇴_정보_요청 = new WithdrawRequest(서비스_refresh_token);
}

0 comments on commit 0b506e6

Please sign in to comment.