From b849637d5f617fa45b0e532feacf4782d2c68dcc Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 10:46:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20Owner=20logout=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/jwt/service/RefreshTokenService.java | 5 +++++ .../catchtable/owner/controller/OwnerController.java | 8 ++++++++ .../com/prgrms/catchtable/owner/service/OwnerService.java | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java index d505ed88..212a8460 100644 --- a/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java +++ b/src/main/java/com/prgrms/catchtable/jwt/service/RefreshTokenService.java @@ -40,4 +40,9 @@ public RefreshToken getRefreshTokenByToken(String refreshToken) { return refreshTokenRepository.findRefreshTokenByToken(refreshToken) .orElseThrow(() -> new NotFoundCustomException(NOT_FOUND_REFRESH_TOKEN)); } + + @Transactional + public void deleteRefreshToken(String email){ + refreshTokenRepository.deleteRefreshTokenByEmail(email); + } } diff --git a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java index a8e781df..5cafb006 100644 --- a/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java +++ b/src/main/java/com/prgrms/catchtable/owner/controller/OwnerController.java @@ -1,6 +1,8 @@ package com.prgrms.catchtable.owner.controller; +import com.prgrms.catchtable.common.login.LogIn; import com.prgrms.catchtable.jwt.token.Token; +import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; import com.prgrms.catchtable.owner.dto.response.JoinOwnerResponse; @@ -36,4 +38,10 @@ public ResponseEntity login(@Valid @RequestBody LoginOwnerRequest loginOw return ResponseEntity.ok(responseToken); } + @PostMapping("/logout") + public ResponseEntity logout(@LogIn Owner owner){ + ownerService.logout(owner.getEmail()); + return ResponseEntity.ok("logout"); + } + } diff --git a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java index 3998044c..425dd3b9 100644 --- a/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java +++ b/src/main/java/com/prgrms/catchtable/owner/service/OwnerService.java @@ -65,6 +65,11 @@ public Token loginOwner(LoginOwnerRequest loginRequest) { return createTotalToken(loginOwner.getEmail()); } + @Transactional + public void logout(String email){ + refreshTokenService.deleteRefreshToken(email); + } + private void validatePassword(LoginOwnerRequest loginRequest, Owner loginOwner) { if (!passwordEncoder.matches(loginRequest.password(), loginOwner.getPassword())) { throw new BadRequestCustomException(INVALID_EMAIL_OR_PASSWORD); From 75a13624b067d1519bc7ff4731088990afbbdbbf Mon Sep 17 00:00:00 2001 From: kkangh00n Date: Wed, 17 Jan 2024 10:58:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20Owner=20logout=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/owner/service/OwnerServiceTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java index 0758a08b..35ed75c3 100644 --- a/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/owner/service/OwnerServiceTest.java @@ -4,6 +4,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.Role; @@ -91,6 +93,17 @@ void loginSuccess() { assertThat(ownerService.loginOwner(loginOwnerRequest)).isEqualTo(token); } + @Test + @DisplayName("로그아웃이 성공하면, RefreshToken을 삭제한다.") + void logoutSuccess() { + //when + ownerService.logout(email); + + //then + verify(refreshTokenService, times(1)).deleteRefreshToken(any()); + + } + @Test @DisplayName("해당 이메일의 유저가 존재하지 않으면 로그인을 실패한다") void loginFailureId() {