Skip to content

Commit

Permalink
Merge pull request #96 from YAPP-Github/fix/ISSUE-95
Browse files Browse the repository at this point in the history
fix: separate saving device token API from social login API
  • Loading branch information
Seokyeong237 authored Feb 19, 2024
2 parents e8f329b + dec1256 commit 99121e8
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/fullcar/core/response/SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum SuccessCode {
AVAILABLE_NICKNAME(OK, "사용 가능한 닉네임"),
UPDATE_SUCCESS(OK, "수정 성공"),
CODE_VERIFICATION_SUCCESS(OK, "인증 성공"),
WITHDRAW_SUCCESS(OK, "탈퇴 성공");
WITHDRAW_SUCCESS(OK, "탈퇴 성공"),
SAVE_DEVICE_TOKEN_SUCCESS(OK, "디바이스 토큰 등록 성공");

private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class AppleAuthService {

@Transactional
public SocialInfoResponseDto getMemberInfo(AppleAuthRequestDto appleAuthRequestDto) throws IOException {
String deviceToken = appleAuthRequestDto.getDeviceToken();
String idToken = appleAuthRequestDto.getIdToken();
String appleRefreshToken = requestAppleAuthToken(appleAuthRequestDto.getAuthCode()).getRefreshToken();

Expand All @@ -84,9 +83,9 @@ public SocialInfoResponseDto getMemberInfo(AppleAuthRequestDto appleAuthRequestD
if (memberRepository.existsBySocialId(socialId)) {
Member member = memberRepository.findBySocialId(socialId);
member.saveAppleRefreshToken(appleRefreshToken);
member.loginMember(deviceToken, refreshToken);
member.loginMember(refreshToken);
}
else createMember(socialId, appleRefreshToken, deviceToken, refreshToken);
else createMember(socialId, appleRefreshToken, refreshToken);

return SocialInfoResponseDto.builder()
.socialId(socialId)
Expand All @@ -95,8 +94,8 @@ public SocialInfoResponseDto getMemberInfo(AppleAuthRequestDto appleAuthRequestD
}

// 새로운 멤버 생성
private void createMember(SocialId socialId, String authCode, String deviceToken, String refreshToken) {
Member member = memberMapper.toAppleLoginEntity(socialId, authCode, deviceToken, refreshToken);
private void createMember(SocialId socialId, String authCode, String refreshToken) {
Member member = memberMapper.toAppleLoginEntity(socialId, authCode, refreshToken);
memberRepository.saveAndFlush(member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ public class KakaoAuthService {

@Transactional
public SocialInfoResponseDto getMemberInfo(KakaoAuthRequestDto kakaoAuthRequestDto) {
String deviceToken = kakaoAuthRequestDto.getDeviceToken();
SocialId socialId = socialIdService.generateSocialId(getKakaoData(kakaoAuthRequestDto.getToken()));
String refreshToken = jwtTokenProvider.generateRefreshToken();

if (memberRepository.existsBySocialId(socialId)) memberRepository.findBySocialId(socialId).loginMember(deviceToken, refreshToken);
else createMember(socialId, deviceToken, refreshToken);
if (memberRepository.existsBySocialId(socialId)) memberRepository.findBySocialId(socialId).loginMember(refreshToken);
else createMember(socialId, refreshToken);

return SocialInfoResponseDto.builder()
.socialId(socialId)
Expand Down Expand Up @@ -87,8 +86,8 @@ private static String getKakaoData(String kakaoToken) {
}

// 새로운 멤버 생성
private void createMember(SocialId socialId, String deviceToken, String refreshToken) {
Member member = memberMapper.toKakaoLoginEntity(socialId, deviceToken, refreshToken);
private void createMember(SocialId socialId, String refreshToken) {
Member member = memberMapper.toKakaoLoginEntity(socialId, refreshToken);
memberRepository.saveAndFlush(member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@ public Member toEntity(OnBoardingRequestDto onboardingRequestDto) {
.build();
}

public Member toKakaoLoginEntity(SocialId socialId, String deviceToken, String refreshToken) {
public Member toKakaoLoginEntity(SocialId socialId, String refreshToken) {
return Member.builder()
.id(memberIdService.nextId())
.socialId(socialId)
.deviceToken(deviceToken)
.refreshToken(refreshToken)
.socialType(SocialType.KAKAO)
.build();
}

public Member toAppleLoginEntity(SocialId socialId, String appleRefreshToken, String deviceToken, String refreshToken) {
public Member toAppleLoginEntity(SocialId socialId, String appleRefreshToken, String refreshToken) {
return Member.builder()
.id(memberIdService.nextId())
.socialId(socialId)
.appleRefreshToken(appleRefreshToken)
.deviceToken(deviceToken)
.refreshToken(refreshToken)
.socialType(SocialType.APPLE)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.fullcar.core.exception.CustomException;
import com.fullcar.core.exception.NotFoundException;
import com.fullcar.core.response.ErrorCode;
import com.fullcar.member.application.auth.AppleAuthService;
import com.fullcar.member.application.auth.KakaoAuthService;
import com.fullcar.member.domain.car.CarRepository;
import com.fullcar.member.domain.mail.MailRepository;
import com.fullcar.member.domain.member.*;
import com.fullcar.member.presentation.member.dto.request.DeviceTokenRequestDto;
import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto;
import com.fullcar.member.presentation.member.dto.request.OnBoardingRequestDto;
import com.fullcar.member.presentation.member.dto.response.DeviceTokenResponseDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto;
Expand Down Expand Up @@ -59,4 +57,13 @@ public NicknameResponseDto checkNicknameDuplication(NicknameRequestDto nicknameR
.build();
}
}

@Transactional
public DeviceTokenResponseDto postDeviceToken(Member member, DeviceTokenRequestDto deviceTokenRequestDto) {
memberRepository.saveAndFlush(member.saveDeviceToken(deviceTokenRequestDto));

return DeviceTokenResponseDto.builder()
.deviceToken(deviceTokenRequestDto.getDeviceToken())
.build();
}
}
9 changes: 7 additions & 2 deletions src/main/java/com/fullcar/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fullcar.member.domain.car.CarId;
import com.fullcar.member.domain.auth.SocialId;
import com.fullcar.member.presentation.member.dto.request.DeviceTokenRequestDto;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -74,9 +75,8 @@ public void saveAppleRefreshToken(String appleRefreshToken) {
this.appleRefreshToken = appleRefreshToken;
}

public void loginMember(String deviceToken, String refreshToken) {
public void loginMember(String refreshToken) {
this.isDeleted = false;
this.deviceToken = deviceToken;
this.refreshToken = refreshToken;
}

Expand Down Expand Up @@ -108,4 +108,9 @@ public Member deleted() {
this.gender = null;
return this;
}

public Member saveDeviceToken(DeviceTokenRequestDto deviceTokenRequestDto) {
this.deviceToken = deviceTokenRequestDto.getDeviceToken();
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ public class AppleAuthRequestDto {

@Schema(description = "id_token", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDUyMzQ2NjMsImV4cCI6MTcwNTIzNDg0MywibWVtYmVySWQiOiJjb20uZnVsbGNhci5tZW1iZXIuZG9tYWluLk1lbWJlcklkQDQ5ODRlODM3In0.Qf8uXvaWR9K_pD4jgZlnkFpcx2-zlRKENXJhGXkMGSs")
private String idToken;

@Schema(description = "디바이스 토큰")
private String deviceToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ public class KakaoAuthRequestDto {

@Schema(description = "카카오에서 받은 액세스 토큰", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MDUyMzQ2NjMsImV4cCI6MTcwNTIzNDg0MywibWVtYmVySWQiOiJjb20uZnVsbGNhci5tZW1iZXIuZG9tYWluLk1lbWJlcklkQDQ5ODRlODM3In0.Qf8uXvaWR9K_pD4jgZlnkFpcx2-zlRKENXJhGXkMGSs")
private String token;

@Schema(description = "디바이스 토큰")
private String deviceToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.service.MailService;
import com.fullcar.member.presentation.member.dto.request.*;
import com.fullcar.member.presentation.member.dto.response.DeviceTokenResponseDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import com.fullcar.member.presentation.member.dto.response.OnBoardingResponseDto;
Expand Down Expand Up @@ -84,4 +85,15 @@ public ApiResponse<Object> checkMailAuthenticationCode(@CurrentMember Member mem
mailService.checkMailAuthenticationCode(member, codeRequestDto);
return ApiResponse.success(SuccessCode.CODE_VERIFICATION_SUCCESS);
}

@Operation(summary = "디바이스 토큰 등록 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "디바이스 토큰 등록 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content)
})
@PostMapping("/device-token")
public ApiResponse<DeviceTokenResponseDto> postDeviceToken(@CurrentMember Member member, @RequestBody DeviceTokenRequestDto deviceTokenRequestDto) {
DeviceTokenResponseDto responseDto = memberService.postDeviceToken(member, deviceTokenRequestDto);
return ApiResponse.success(SuccessCode.SAVE_DEVICE_TOKEN_SUCCESS, responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fullcar.member.presentation.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DeviceTokenRequestDto {
@Schema(description = "디바이스 토큰", example = "123")
private String deviceToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fullcar.member.presentation.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DeviceTokenResponseDto {
@Schema(description = "디바이스 토큰", example = "123")
private String deviceToken;
}

0 comments on commit 99121e8

Please sign in to comment.