diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java index ff60340e..0537e65e 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/controller/AuthController.java @@ -18,6 +18,7 @@ import org.swmaestro.repl.gifthub.auth.dto.KakaoDto; import org.swmaestro.repl.gifthub.auth.dto.NaverDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; @@ -259,17 +260,14 @@ public ResponseEntity appleCallback(@RequestBody String code) throws IO @ApiResponse(responseCode = "200", description = "로그인 성공"), @ApiResponse(responseCode = "400(401)", description = "존재하지 않는 사용자") }) - public ResponseEntity signOut(HttpServletRequest request) { + public ResponseEntity signOut(HttpServletRequest request, @RequestBody SignOutDto signOutDto) { String username = jwtProvider.getUsername(jwtProvider.resolveToken(request).substring(7)); - authService.signOut(username); - return new ResponseEntity( + authService.signOut(username, signOutDto); + return ResponseEntity.ok().body( Message.builder() .status(StatusEnum.OK) .message("로그아웃 성공!") .data(null) - .build(), - new HttpJsonHeaders(), - HttpStatus.OK - ); + .build()); } } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java new file mode 100644 index 00000000..625e556a --- /dev/null +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/SignOutDto.java @@ -0,0 +1,23 @@ +package org.swmaestro.repl.gifthub.auth.dto; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) +public class SignOutDto { + private String deviceToken; + + @Builder + public SignOutDto(String deviceToken) { + this.deviceToken = deviceToken; + } +} diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java index d54206a6..d4d6050a 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java @@ -1,11 +1,12 @@ package org.swmaestro.repl.gifthub.auth.service; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; public interface AuthService { TokenDto signIn(SignInDto loginDto); - void signOut(String username); + void signOut(String username, SignOutDto signOutDto); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java index 8d7bd662..595af097 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthServiceImpl.java @@ -3,6 +3,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; import org.swmaestro.repl.gifthub.auth.repository.MemberRepository; @@ -21,6 +22,7 @@ public class AuthServiceImpl implements AuthService { private final JwtProvider jwtProvider; private final RefreshTokenService refreshTokenService; private final NaverService naverService; + private final DeviceTokenService deviceTokenService; public TokenDto signIn(SignInDto loginDto) { Member member = memberRepository.findByUsername(loginDto.getUsername()); @@ -44,11 +46,12 @@ public TokenDto signIn(SignInDto loginDto) { } @Transactional - public void signOut(String username) { + public void signOut(String username, SignOutDto signOutDto) { Member member = memberRepository.findByUsername(username); if (member == null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } refreshTokenService.deleteRefreshToken(username); + deviceTokenService.delete(signOutDto.getDeviceToken()); } } diff --git a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java index ab52d0bd..0c754996 100644 --- a/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java +++ b/src/test/java/org/swmaestro/repl/gifthub/auth/controller/AuthControllerTest.java @@ -20,6 +20,7 @@ import org.swmaestro.repl.gifthub.auth.dto.KakaoDto; import org.swmaestro.repl.gifthub.auth.dto.NaverDto; import org.swmaestro.repl.gifthub.auth.dto.SignInDto; +import org.swmaestro.repl.gifthub.auth.dto.SignOutDto; import org.swmaestro.repl.gifthub.auth.dto.SignUpDto; import org.swmaestro.repl.gifthub.auth.dto.TokenDto; import org.swmaestro.repl.gifthub.auth.entity.Member; @@ -274,11 +275,17 @@ public void signOutTest() throws Exception { String username = "jinlee1703"; String accessToken = "my_awesome_access_token"; + SignOutDto signOutDto = SignOutDto.builder() + .deviceToken("my_awesome_device_token") + .build(); + when(jwtProvider.getUsername(accessToken)).thenReturn(username); when(jwtProvider.resolveToken(any())).thenReturn(accessToken); mockMvc.perform(post("/auth/sign-out") - .header("Authorization", "Bearer " + accessToken)) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(signOutDto))) .andExpect(status().isOk()); }