Skip to content

Commit

Permalink
Merge pull request #58 from YAPP-Github/feat/ISSUE-57
Browse files Browse the repository at this point in the history
  • Loading branch information
Seokyeong237 authored Feb 6, 2024
2 parents 2cebe58 + 615e3a0 commit f9dd0c7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/fullcar/core/response/SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum SuccessCode {
GET_NEW_TOKEN_SUCCESS(OK, "토큰 재발급 성공"),
READ_SUCCESS(OK, "조회 성공"),
EMAIL_SENT_SUCCESS(OK, "인증메일 발송 성공"),
LOGOUT_SUCCESS(OK, "로그아웃 성공"),
AVAILABLE_NICKNAME(OK, "사용 가능한 닉네임");

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.fullcar.member.presentation.auth.dto.response.AuthTokenResponseDto;
import com.fullcar.member.presentation.auth.dto.response.SocialInfoResponseDto;
import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -26,6 +28,7 @@ public class AuthServiceProvider {
private final AppleAuthService appleAuthService;
private final JwtTokenProvider jwtTokenProvider;
private final MemberRepository memberRepository;
private final EntityManager entityManager;

@PostConstruct
void initializeAuthServicesMap() {
Expand Down Expand Up @@ -63,4 +66,10 @@ public AuthTokenResponseDto getNewToken(String refreshToken) {
.refreshToken(refreshToken)
.build();
}

@Transactional
public void socialLogout(Member member) {
memberRepository.findByIdAndIsDeletedOrThrow(member.getId(), false).clearRefreshTokenAndDeviceToken();
memberRepository.flush();
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/fullcar/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Member {
@Column(name = "refresh_token")
private String refreshToken;

@Column(name = "device_token", nullable = false)
@Column(name = "device_token")
private String deviceToken;

@Column(name = "created_at")
Expand All @@ -79,4 +79,9 @@ public void saveOnBoardingInfo(Member member) {
this.gender = member.getGender();
this.company = new Company(member.getCompany().getCompanyName(), member.getCompany().getLatitude(), member.getCompany().getLongitude());
}

public void clearRefreshTokenAndDeviceToken() {
this.deviceToken = null;
this.refreshToken = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.fullcar.member.presentation.auth;

import com.fullcar.core.annotation.CurrentMember;
import com.fullcar.core.response.ApiResponse;
import com.fullcar.core.response.SuccessCode;
import com.fullcar.member.application.auth.AuthService;
import com.fullcar.member.application.auth.AuthServiceProvider;
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.presentation.auth.dto.request.AuthRequestDto;
import com.fullcar.member.presentation.auth.dto.request.AuthTokenRequestDto;
import com.fullcar.member.presentation.auth.dto.response.AuthResponseDto;
Expand Down Expand Up @@ -53,4 +55,16 @@ public ApiResponse<AuthResponseDto> socialLogin(@RequestBody AuthRequestDto auth
public ApiResponse<AuthTokenResponseDto> getNewToken(@RequestBody AuthTokenRequestDto authTokenRequestDto) {
return ApiResponse.success(SuccessCode.GET_NEW_TOKEN_SUCCESS, authServiceProvider.getNewToken(authTokenRequestDto.getRefreshToken()));
}

@Operation(summary = "로그아웃 API")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "로그아웃 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content)
})
@PostMapping("/logout")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<Object> socialLogout(@CurrentMember Member member) {
authServiceProvider.socialLogout(member);
return ApiResponse.success(SuccessCode.LOGOUT_SUCCESS);
}
}

0 comments on commit f9dd0c7

Please sign in to comment.