Skip to content

Commit

Permalink
Merge pull request #242 from TeamDilly/develop
Browse files Browse the repository at this point in the history
v1.5.1
  • Loading branch information
leeeeeyeon authored Jul 2, 2024
2 parents 89e42df + b558360 commit cea0446
Show file tree
Hide file tree
Showing 65 changed files with 1,001 additions and 378 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/packy-cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v3

- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle & Upload Image to ECR
run: ./gradlew -Pdev clean jib

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/packy-cd-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v3

- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle & Upload Image to ECR
run: ./gradlew -Pprod clean jib

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/packy-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Gradle Caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Run build with Gradle Wrapper
run: ./gradlew clean build --parallel

Expand Down
2 changes: 1 addition & 1 deletion db.vuerd.json
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@
{
"id": "d6d41908-171e-4016-883a-8d62102243b0",
"identification": false,
"relationshipType": "OneN",
"relationshipType": "OneOnly",
"startRelationshipType": "Dash",
"start": {
"tableId": "67c2763b-46ef-4967-821e-206a52e3c32c",
Expand Down
2 changes: 1 addition & 1 deletion packy-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
implementation 'org.bouncycastle:bcprov-jdk15on:1.69'
implementation 'org.bouncycastle:bcpkix-jdk14:1.72'

// test code
// junit
testImplementation('org.junit-pioneer:junit-pioneer:2.2.0')
}

Expand Down
111 changes: 21 additions & 90 deletions packy-api/src/main/java/com/dilly/auth/application/AuthService.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
package com.dilly.auth.application;

import static com.dilly.member.domain.Provider.APPLE;
import static com.dilly.member.domain.Provider.KAKAO;
import static com.dilly.member.domain.Provider.TEST;

import com.dilly.admin.adaptor.AdminGiftBoxReader;
import com.dilly.auth.adaptor.AppleAccountReader;
import com.dilly.auth.adaptor.AppleAccountWriter;
import com.dilly.auth.adaptor.KakaoAccountReader;
import com.dilly.auth.adaptor.KakaoAccountWriter;
import com.dilly.auth.domain.AppleAccount;
import com.dilly.auth.domain.KakaoAccount;
import com.dilly.auth.application.strategy.AuthActionProvider;
import com.dilly.auth.application.strategy.AuthStrategy;
import com.dilly.auth.dto.request.SignupRequest;
import com.dilly.auth.dto.response.SignInResponse;
import com.dilly.auth.model.AppleAccountInfo;
import com.dilly.auth.model.AppleToken;
import com.dilly.auth.model.KakaoResource;
import com.dilly.exception.ErrorCode;
import com.dilly.exception.UnsupportedException;
import com.dilly.gift.adaptor.ReceiverWriter;
import com.dilly.gift.domain.giftbox.GiftBox;
import com.dilly.gift.domain.giftbox.admin.AdminGiftBox;
Expand All @@ -29,7 +16,6 @@
import com.dilly.jwt.adaptor.JwtWriter;
import com.dilly.jwt.dto.JwtResponse;
import com.dilly.member.adaptor.MemberReader;
import com.dilly.member.adaptor.MemberWriter;
import com.dilly.member.adaptor.ProfileImageReader;
import com.dilly.member.domain.Member;
import com.dilly.member.domain.ProfileImage;
Expand All @@ -47,86 +33,44 @@
@Slf4j
public class AuthService {

private final AuthActionProvider authActionProvider;

private final JwtService jwtService;
private final KakaoService kakaoService;
private final AppleService appleService;

private final MemberReader memberReader;
private final MemberWriter memberWriter;
private final ProfileImageReader profileImageReader;
private final KakaoAccountReader kakaoAccountReader;
private final KakaoAccountWriter kakaoAccountWriter;
private final AppleAccountReader appleAccountReader;
private final AppleAccountWriter appleAccountWriter;
private final JwtReader jwtReader;
private final JwtWriter jwtWriter;
private final AdminGiftBoxReader adminGiftBoxReader;
private final ReceiverWriter receiverWriter;

public JwtResponse signUp(String providerAccessToken, SignupRequest signupRequest) {
Provider provider;
ProfileImage profileImage = profileImageReader.findById(signupRequest.profileImg());

Member member = null;
switch (signupRequest.provider()) {
case "kakao" -> {
provider = KAKAO;
KakaoResource kakaoResource = kakaoService.getKaKaoAccount(providerAccessToken);
kakaoAccountReader.isKakaoAccountPresent(kakaoResource.getId());

member = memberWriter.save(signupRequest.toEntity(provider, profileImage));
kakaoAccountWriter.save(kakaoResource.toEntity(member));
}

case "apple" -> {
provider = APPLE;
AppleToken appleToken = appleService.getAppleToken(providerAccessToken);
AppleAccountInfo appleAccountInfo = appleService.getAppleAccountInfo(appleToken.idToken());
appleAccountReader.isAppleAccountPresent(appleAccountInfo.sub());

member = memberWriter.save(signupRequest.toEntity(provider, profileImage));
appleAccountWriter.save(AppleAccount.builder()
.id(appleAccountInfo.sub())
.member(member)
.refreshToken(appleToken.refreshToken())
.build()
);
}

case "test" -> {
provider = TEST;
member = memberWriter.save(signupRequest.toEntity(provider, profileImage));
}

default -> throw new UnsupportedException(ErrorCode.UNSUPPORTED_LOGIN_TYPE);
}
Provider provider = Provider.valueOf(signupRequest.provider().toUpperCase());
final AuthStrategy authStrategy = authActionProvider.getStrategy(provider);
Member member = authStrategy.signUp(providerAccessToken, signupRequest, profileImage);

sendOnboardingGiftBox(member);

return jwtService.issueJwt(member);
}

private void sendOnboardingGiftBox(Member member) {
Optional<AdminGiftBox> adminGiftBox = adminGiftBoxReader.findByAdminType(
AdminType.ONBOARDING);

if (adminGiftBox.isPresent()) {
GiftBox onboardingGiftBox = adminGiftBox.get().getGiftBox();
receiverWriter.save(member, onboardingGiftBox);
}

return jwtService.issueJwt(member);
}

public SignInResponse signIn(String provider, String providerAccessToken) {
Optional<Member> member;
switch (provider) {
case "kakao" -> {
KakaoResource kakaoResource = kakaoService.getKaKaoAccount(providerAccessToken);
member = kakaoAccountReader.getMemberById(kakaoResource.getId());
}

case "apple" -> {
// identityToken을 받아 회원 정보 조회
AppleAccountInfo appleAccountInfo = appleService.getAppleAccountInfo(
providerAccessToken);
member = appleAccountReader.getMemberById(appleAccountInfo.sub());
}

default -> throw new UnsupportedException(ErrorCode.UNSUPPORTED_LOGIN_TYPE);
}
Provider providerType = Provider.valueOf(provider.toUpperCase());
final AuthStrategy authStrategy = authActionProvider.getStrategy(providerType);

Optional<Member> member = authStrategy.signIn(providerAccessToken);

SignInResponse signInResponse;
if (member.isEmpty()) {
Expand All @@ -144,21 +88,8 @@ public String withdraw() {
Long memberId = SecurityUtil.getMemberId();
Member member = memberReader.findById(memberId);

switch (member.getProvider()) {
case KAKAO -> {
KakaoAccount kakaoAccount = kakaoAccountReader.findByMember(member);
kakaoService.unlinkKakaoAccount(kakaoAccount);
kakaoAccountWriter.delete(kakaoAccount);
}

case APPLE -> {
AppleAccount appleAccount = appleAccountReader.findByMember(member);
appleService.revokeAppleAccount(appleAccount);
appleAccountWriter.delete(appleAccount);
}

default -> throw new UnsupportedException(ErrorCode.UNSUPPORTED_LOGIN_TYPE);
}
final AuthStrategy authStrategy = authActionProvider.getStrategy(member.getProvider());
authStrategy.withdraw(member);

RefreshToken refreshToken = jwtReader.findByMember(member);
jwtWriter.delete(refreshToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.dilly.auth.application.strategy;

import com.dilly.auth.adaptor.AppleAccountReader;
import com.dilly.auth.adaptor.AppleAccountWriter;
import com.dilly.auth.application.AppleService;
import com.dilly.auth.domain.AppleAccount;
import com.dilly.auth.dto.request.SignupRequest;
import com.dilly.auth.model.AppleAccountInfo;
import com.dilly.auth.model.AppleToken;
import com.dilly.member.adaptor.MemberWriter;
import com.dilly.member.domain.Member;
import com.dilly.member.domain.ProfileImage;
import com.dilly.member.domain.Provider;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class AppleStrategy implements AuthStrategy {

private final AppleService appleService;

private final MemberWriter memberWriter;
private final AppleAccountReader appleAccountReader;
private final AppleAccountWriter appleAccountWriter;

@Override
public Member signUp(String providerAccessToken, SignupRequest signupRequest, ProfileImage profileImage) {
AppleToken appleToken = appleService.getAppleToken(providerAccessToken);
AppleAccountInfo appleAccountInfo = appleService.getAppleAccountInfo(appleToken.idToken());
appleAccountReader.isAppleAccountPresent(appleAccountInfo.sub());

Member member = memberWriter.save(signupRequest.toMember(Provider.APPLE, profileImage));
appleAccountWriter.save(AppleAccount.builder()
.id(appleAccountInfo.sub())
.member(member)
.refreshToken(appleToken.refreshToken())
.build()
);

return member;
}

@Override
public Optional<Member> signIn(String providerAccessToken) {
AppleAccountInfo appleAccountInfo = appleService.getAppleAccountInfo(
providerAccessToken);

return appleAccountReader.getMemberById(appleAccountInfo.sub());
}

@Override
public void withdraw(Member member) {
AppleAccount appleAccount = appleAccountReader.findByMember(member);

appleService.revokeAppleAccount(appleAccount);
appleAccountWriter.delete(appleAccount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dilly.auth.application.strategy;

import com.dilly.member.domain.Provider;
import java.util.EnumMap;
import java.util.Map;
import org.springframework.stereotype.Component;

@Component
public class AuthActionProvider {

private final Map<Provider, AuthStrategy> authActions;

public AuthActionProvider(
final KakaoStrategy kakaoStrategy,
final AppleStrategy appleStrategy,
final TestStrategy testStrategy
) {
this.authActions = new EnumMap<>(Provider.class);
this.authActions.put(Provider.KAKAO, kakaoStrategy);
this.authActions.put(Provider.APPLE, appleStrategy);
this.authActions.put(Provider.TEST, testStrategy);
}

public AuthStrategy getStrategy(Provider provider) {
return authActions.get(provider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dilly.auth.application.strategy;

import com.dilly.auth.dto.request.SignupRequest;
import com.dilly.member.domain.Member;
import com.dilly.member.domain.ProfileImage;
import java.util.Optional;

public interface AuthStrategy {

Member signUp(String providerAccessToken, SignupRequest signupRequest, ProfileImage profileImage);
Optional<Member> signIn(String providerAccessToken);
void withdraw(Member member);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.dilly.auth.application.strategy;

import com.dilly.auth.adaptor.KakaoAccountReader;
import com.dilly.auth.adaptor.KakaoAccountWriter;
import com.dilly.auth.application.KakaoService;
import com.dilly.auth.domain.KakaoAccount;
import com.dilly.auth.dto.request.SignupRequest;
import com.dilly.auth.model.KakaoResource;
import com.dilly.member.adaptor.MemberWriter;
import com.dilly.member.domain.Member;
import com.dilly.member.domain.ProfileImage;
import com.dilly.member.domain.Provider;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class KakaoStrategy implements AuthStrategy {

private final KakaoService kakaoService;

private final MemberWriter memberWriter;
private final KakaoAccountReader kakaoAccountReader;
private final KakaoAccountWriter kakaoAccountWriter;

@Override
public Member signUp(String providerAccessToken, SignupRequest signupRequest, ProfileImage profileImage) {

KakaoResource kakaoResource = kakaoService.getKaKaoAccount(providerAccessToken);
kakaoAccountReader.isKakaoAccountPresent(kakaoResource.getId());

Member member = memberWriter.save(signupRequest.toMember(Provider.KAKAO, profileImage));
kakaoAccountWriter.save(kakaoResource.toMember(member));

return member;
}

@Override
public Optional<Member> signIn(String providerAccessToken) {
KakaoResource kakaoResource = kakaoService.getKaKaoAccount(providerAccessToken);

return kakaoAccountReader.getMemberById(kakaoResource.getId());
}

@Override
public void withdraw(Member member) {
KakaoAccount kakaoAccount = kakaoAccountReader.findByMember(member);

kakaoService.unlinkKakaoAccount(kakaoAccount);
kakaoAccountWriter.delete(kakaoAccount);
}
}
Loading

0 comments on commit cea0446

Please sign in to comment.