Skip to content

Commit

Permalink
Merge pull request #67 from Na-o-man/fix/#66/change-check-registratio…
Browse files Browse the repository at this point in the history
…n-logic

[FIX] 회원가입 여부 판별하는 로직 변경, buid.gradle 간소화
  • Loading branch information
bflykky authored Aug 6, 2024
2 parents 77a85bd + 229b952 commit 7fd2ca6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 54 deletions.
24 changes: 9 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ configurations {
compileOnly {
extendsFrom annotationProcessor
}

configureEach {
exclude group: 'commons-logging', module: 'commons-logging'
}
}

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url 'https://repo.spring.io/milestone' }
}

ext {
set('springAiVersion', "1.0.0-M1")
maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
Expand All @@ -39,13 +40,12 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.5'
implementation 'commons-io:commons-io:2.6'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// GPT 프롬프트
implementation platform("org.springframework.ai:spring-ai-bom:1.0.0-SNAPSHOT")
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'
// implementation 'io.github.flashvayne:chatgpt-spring-boot-starter:1.0.4'

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
Expand All @@ -61,9 +61,9 @@ dependencies {
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

//firebase
// firebase
implementation 'com.google.firebase:firebase-admin:8.1.0'
//조사 처르를 쉽게 하기 위한 라이브러리
// 조사 처르를 쉽게 하기 위한 라이브러리
implementation 'com.github.josa-moa:josa-moa:1.0.3'

// AWS
Expand All @@ -72,16 +72,10 @@ dependencies {
implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

//elasticsearch
// elasticsearch
implementation 'org.springframework.data:spring-data-elasticsearch:'
}

dependencyManagement {
imports {
mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}"
}
}

tasks.named('test') {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ public ResultResponse<LoginInfo> login(@Valid @RequestBody LoginRequest request)
}

@GetMapping("/check-registration")
@Operation(summary = "회원가입 여부 조회 API", description = "이메일을 통해, 해당 이메일을 가진 회원의 가입 여부를 조회하는 API입니다.")
@Parameters(value = {
@Parameter(name = "email", description = "회원가입 여부를 확인할 이메일을 입력해 주세요.")
})
public ResultResponse<CheckMemberRegistration> checkSignup(@RequestParam("email") @Valid @Email String email) {
return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(email));
@Operation(summary = "회원가입 여부 조회 API", description = "authId와 플랫폼명을 통해, 해당 정보와 일치하는 회원의 가입 여부를 조회하는 API입니다.")
public ResultResponse<CheckMemberRegistration> checkSignup(@Valid @RequestBody LoginRequest request) {
return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String email);
Optional<Member> findByAuthIdAndSocialType(String authId, SocialType socialType);
Boolean existsByEmail(String email);
Boolean existsBySocialTypeAndAuthId(SocialType socialType, String authId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import com.umc.naoman.domain.member.entity.SocialType;

public interface MemberService {
Member findMember(Long memberId);
Member findMember(String email);
Member findMember(String authId, SocialType socialType);
CheckMemberRegistration checkRegistration(String email);
LoginInfo signup(SignupRequest request);
LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request);
LoginInfo signup(SignupRequest request);
LoginInfo login(LoginRequest request);
CheckMemberRegistration checkRegistration(LoginRequest request);
MemberInfo getMyInfo(Member member);
Member findMember(Long memberId);
Member findMember(SocialType socialType, String authId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,6 @@ public class MemberServiceImpl implements MemberService {
@Value("${jwt.refresh-token-validity-in-seconds}")
private Long REFRESH_TOKEN_VALIDITY_IN_SECONDS;

@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID));
}

@Override
public Member findMember(String email) {
return memberRepository.findByEmail(email)
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_EMAIL));
}

@Override
public Member findMember(String authId, SocialType socialType) {
return memberRepository.findByAuthIdAndSocialType(authId, socialType)
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE));
}

@Override
public CheckMemberRegistration checkRegistration(String email) {
boolean isRegistered = memberRepository.existsByEmail(email);
return new CheckMemberRegistration(isRegistered);
}

@Override
@Transactional
public LoginInfo signup(SignupRequest request) {
Expand Down Expand Up @@ -90,7 +66,7 @@ public LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request) {

@Override
public LoginInfo login(LoginRequest request) {
Member member = findMember(request.getAuthId(), request.getSocialType());
Member member = findMember(request.getSocialType(), request.getAuthId());

Long memberId = member.getId();
String email = member.getEmail();
Expand All @@ -102,8 +78,27 @@ public LoginInfo login(LoginRequest request) {
return memberConverter.toLoginInfo(memberId, accessToken, refreshToken);
}

@Override
public CheckMemberRegistration checkRegistration(LoginRequest request) {
boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId());
return new CheckMemberRegistration(isRegistered);
}

@Override
public MemberInfo getMyInfo(Member member) {
return memberConverter.toMemberInfo(member);
}

@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID));
}

@Override
public Member findMember(SocialType socialType, String authId) {
return memberRepository.findByAuthIdAndSocialType(authId, socialType)
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal();

try { // 이미 회원가입된 회원인 경우
Member member = memberService.findMember(oAuth2User.getEmail());
Member member = memberService.findMember(oAuth2User.getProvider(), oAuth2User.getAuthId());
handleExistingMemberLogin(request, response, oAuth2User, member);
} catch (BusinessException e) { // 회원가입되어 있지 않은 경우
handleMemberSignup(request, response, oAuth2User.getOAuthAttribute());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.naoman.global.security.model;

import com.umc.naoman.domain.member.entity.SocialType;
import com.umc.naoman.global.security.attribute.OAuthAttribute;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
Expand All @@ -20,7 +21,11 @@ public OAuthAttribute getOAuthAttribute() {
return oAuthAttribute;
}

public String getEmail() {
return this.oAuthAttribute.getEmail();
public SocialType getProvider() {
return this.oAuthAttribute.getProvider();
}

public String getAuthId() {
return this.oAuthAttribute.getAuthId();
}
}

0 comments on commit 7fd2ca6

Please sign in to comment.