Skip to content

Commit

Permalink
refactor : 애플 로그인, 구글로그인 API 리팩터링
Browse files Browse the repository at this point in the history
  • Loading branch information
1000kkannoo committed Aug 18, 2024
1 parent 09d3bdf commit c08abef
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 302 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmc15.backend.domain.account.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "apple")
@Getter
@Setter
public class AppleSettings {
private String authUrl;
private String teamId;
private String redirectUrl;
private String clientId;
private String keyId;
private String keyPath;
private String privateKey;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmc15.backend.domain.account.config;


import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "google")
@Getter
@Setter
public class GoogleSettings {
private String clientId;
private String clientSecret;
private String redirectUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmc15.backend.domain.account.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "oauth")
@Getter
@Setter
public class OAuthSettings {
private String password;
private String nonEncryptionPassword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public CustomResponseEntity<AccountResponse.OAuthConnection> socialLogin(
return CustomResponseEntity.success(accountService.socialLogin(platform, code));
}

/**
* @param request
* @apiNote 회원가입 API / 현재 사용되지 않음
*/
@PostMapping("/account")
public CustomResponseEntity<AccountResponse.Connection> accountRegister(
@RequestBody @Valid final AccountRequest.Register request
) {
return CustomResponseEntity.success(accountService.accountRegister(request));
}

/**
* @return success
* @apiNote 랜덤 닉네임 생성 API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.io.IOException;

import static cmc15.backend.domain.account.entity.Platform.APPLE;

@RestController
@RequiredArgsConstructor
public class AppleController {
Expand All @@ -21,7 +23,7 @@ public class AppleController {
* @apiNote 애플 로그인 API
*/
@PostMapping("/apple/token")
public void appleLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect(accountService.appleLogin(request.getParameter("code")));
public void appleLogin2(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect(accountService.socialLogin(APPLE, request.getParameter("code")).getRedirectUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import cmc15.backend.domain.account.entity.Account;
import cmc15.backend.domain.account.entity.AccountInsurance;
import cmc15.backend.domain.account.entity.InsuranceType;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.*;
import static lombok.AccessLevel.PRIVATE;

public class AccountResponse {
Expand All @@ -16,29 +18,36 @@ public class AccountResponse {
@NoArgsConstructor(access = PRIVATE)
@Getter
@Builder
@JsonInclude(NON_NULL)
public static class OAuthConnection {
private Long accountId;
private String atk;
private String rtk;
private Boolean isRegister;
private String nickname;
private String redirectUrl;

public static OAuthConnection to(Account account, Boolean isRegister, String atk, String rtk) {
String nickname;
if (account.getNickName() == null) {
nickname = "null";
} else {
nickname = account.getNickName();
}
public static OAuthConnection to(Account account, String atk, String rtk) {
return OAuthConnection.builder()
.accountId(account.getAccountId())
.atk(atk)
.rtk(rtk)
.nickname(getNickname(account))
.build();
}

public static OAuthConnection toRedirect(Account account, String atk, String rtk, String redirectUrl) {
return OAuthConnection.builder()
.accountId(account.getAccountId())
.isRegister(isRegister)
.atk(atk)
.rtk(rtk)
.nickname(nickname)
.nickname(getNickname(account))
.redirectUrl(redirectUrl)
.build();
}

private static String getNickname(Account account) {
return account.getNickName() == null ? "null" : account.getNickName();
}
}

@AllArgsConstructor(access = PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmc15.backend.domain.account.service;
package cmc15.backend.domain.account.response;

import lombok.Getter;

@Getter
public class AppleIdTokenPayload {
public class AppleLoginResponse {

private String sub;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmc15.backend.domain.account.service;
package cmc15.backend.domain.account.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
Expand Down
Loading

0 comments on commit c08abef

Please sign in to comment.