Skip to content

Commit

Permalink
Merge pull request #100 from YAPP-Github/develop
Browse files Browse the repository at this point in the history
fix: Resolve conflicts.
  • Loading branch information
Park-Young-Hun authored Feb 20, 2024
2 parents a89d467 + 96846a4 commit 8438b2e
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/fullcar/core/response/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public enum ErrorCode {
CANNOT_CLOSE_CARPOOL(BAD_REQUEST, "카풀마감 권한이 없습니다."),
CANNOT_DELETE_CARPOOL(BAD_REQUEST, "카풀삭제 권한이 없습니다."),
INVALID_FORM_STATE(BAD_REQUEST, "유효하지 않은 신청서 상태입니다."),
EXISTED_CODE_IN_MAIL(BAD_REQUEST, "이미 인증번호를 보냈습니다."),
NOT_MATCHED_CODE(BAD_REQUEST, "인증번호가 일치하지 않습니다."),
ALREADY_CLOSED(BAD_REQUEST, "이미 마감된 카풀입니다."),
CANNOT_DELETE_OPEN_CARPOOL(BAD_REQUEST, "모집중인 카풀은 삭제할 수 없습니다."),
Expand Down
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 All @@ -99,11 +98,11 @@ public void revoke(Member member) {
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.set("Authorization", "KakaoAK " + adminKey);

MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("target_id_type", "user_id");
map.add("target_id", member.getSocialId().toString());
map.add("target_id", Long.valueOf(member.getSocialId().getSocialId()));

HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(map, headers);

try {
restTemplate.exchange(
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 @@ -41,7 +39,7 @@ public Member findByMemberId(MemberId memberId) {
public OnBoardingResponseDto registerOnBoarding(Member member, OnBoardingRequestDto onboardingRequestDto) {
Member updatedMember = findByMemberId(member.getId()).saveOnBoardingInfo(memberMapper.toEntity(onboardingRequestDto));
memberRepository.saveAndFlush(updatedMember);
return memberMapper.toOnBoardingDto(member);
return memberMapper.toOnBoardingDto(updatedMember);
}

@Transactional(readOnly = true)
Expand All @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/fullcar/member/domain/auth/SocialId.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;


import static lombok.AccessLevel.PROTECTED;

@Embeddable
@Getter
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor
public class SocialId {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/fullcar/member/domain/mail/Mail.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public class Mail {
private MemberId memberId;

private Integer code;

public void updateEmailCode(Integer code) {
this.code = code;
}
}
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;
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/fullcar/member/infra/MailClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Random;

@Service
//@Component
@RequiredArgsConstructor
public class MailClient implements MailService {
private final BlacklistRepository blacklistRepository;
Expand All @@ -41,10 +42,13 @@ public void sendMail(Member member, EmailRequestDto emailRequestDto) {
String emailDomain = email.substring(email.lastIndexOf("@")+1);
blacklistRepository.findByEmailThrow(emailDomain);

if (mailRepository.findByMemberId(member.getId()) != null) {
throw new CustomException(ErrorCode.EXISTED_CODE_IN_MAIL);
Mail mail = mailRepository.findByMemberId(member.getId());
if (mail != null) {
mail.updateEmailCode(authNum);
}
else {
mailRepository.saveAndFlush(mailMapper.toEntity(member, authNum));
}
mailRepository.saveAndFlush(mailMapper.toEntity(member, authNum));

EmailMessage emailMessage = mailMapper.toMessageEntity(emailRequestDto);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
Expand Down
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 8438b2e

Please sign in to comment.