Skip to content

Commit

Permalink
Merge pull request #111 from dev-hooon/feat/#110
Browse files Browse the repository at this point in the history
feat : Owner logout 기능 구현
  • Loading branch information
kkangh00n authored Jan 17, 2024
2 parents ba2aff4 + 75a1362 commit 46bdd9e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,4 +38,10 @@ public ResponseEntity<Token> login(@Valid @RequestBody LoginOwnerRequest loginOw
return ResponseEntity.ok(responseToken);
}

@PostMapping("/logout")
public ResponseEntity<String> logout(@LogIn Owner owner){
ownerService.logout(owner.getEmail());
return ResponseEntity.ok("logout");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 46bdd9e

Please sign in to comment.