-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat #117] 회원 탈퇴 API #118
base: dev
Are you sure you want to change the base?
Changes from all commits
98c5138
16c1b23
7bcd7f9
c1cd7cf
295c46a
e2b0500
5b5c337
c949f46
191cb30
75c67f6
dee41ab
f0c3734
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.dnd.gongmuin.auth.dto.response; | ||
|
||
public record DeleteMemberResponse( | ||
|
||
Long memberId | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.dnd.gongmuin.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
RestTemplate restTemplate = new RestTemplate(); | ||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); | ||
requestFactory.setConnectTimeout(5000); | ||
requestFactory.setReadTimeout(5000); | ||
|
||
restTemplate.setRequestFactory(requestFactory); | ||
|
||
return restTemplate; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.dnd.gongmuin.member.service; | ||
|
||
import java.time.Duration; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -23,6 +25,7 @@ | |
import com.dnd.gongmuin.member.dto.response.QuestionPostsResponse; | ||
import com.dnd.gongmuin.member.exception.MemberErrorCode; | ||
import com.dnd.gongmuin.member.repository.MemberRepository; | ||
import com.dnd.gongmuin.redis.util.RedisUtil; | ||
import com.dnd.gongmuin.security.oauth2.Oauth2Response; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
@@ -31,26 +34,46 @@ | |
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private static final long ACCESS_TOKEN_EXPIRATION = 3600 * 1000; | ||
private final MemberRepository memberRepository; | ||
private final RedisUtil redisUtil; | ||
|
||
public Member saveOrUpdate(Oauth2Response oauth2Response) { | ||
Member member = memberRepository.findBySocialEmail(oauth2Response.createSocialEmail()) | ||
.map(m -> { | ||
m.updateSocialEmail(oauth2Response.createSocialEmail()); | ||
deleteOauthAccessTokenIfExists(m); | ||
saveOauth2AccessToken(oauth2Response, m); | ||
return m; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 두 개 메서드가 각각 무슨 역할인지 궁금합니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleteExistingOauthAccessToken()는 이전 소셜 로그인을 통해 저장되어 있는 Oauth2AccessToken가 존재한다면 지운 다음 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개인적으로 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다 ㅎㅎ 반영하겠습니다! |
||
}) | ||
.orElseGet(() -> createMemberFromOauth2Response(oauth2Response)); | ||
|
||
return memberRepository.save(member); | ||
} | ||
|
||
private void saveOauth2AccessToken(Oauth2Response oauth2Response, Member m) { | ||
redisUtil.setValues( | ||
"AT(oauth):" + m.getSocialEmail(), | ||
oauth2Response.getOauth2AccessToken(), | ||
Duration.ofMillis(ACCESS_TOKEN_EXPIRATION) | ||
); | ||
} | ||
|
||
private void deleteOauthAccessTokenIfExists(Member m) { | ||
if (redisUtil.getValues("AT(oauth2):" + m.getSocialEmail()) != null) { | ||
redisUtil.deleteValues("AT(oauth2):" + m.getSocialEmail()); | ||
} | ||
} | ||
|
||
public Provider parseProviderFromSocialEmail(Member member) { | ||
String socialEmail = member.getSocialEmail(); | ||
return Provider.fromSocialEmail(socialEmail); | ||
} | ||
|
||
private Member createMemberFromOauth2Response(Oauth2Response oauth2Response) { | ||
return Member.of(oauth2Response.getName(), oauth2Response.createSocialEmail(), 10000, "ROLE_GUEST"); | ||
Member member = Member.of(oauth2Response.getName(), oauth2Response.createSocialEmail(), 10000, "ROLE_GUEST"); | ||
saveOauth2AccessToken(oauth2Response, member); | ||
return member; | ||
} | ||
|
||
public Member getMemberBySocialEmail(String socialEmail) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.dnd.gongmuin.security.exception; | ||
|
||
import com.dnd.gongmuin.common.exception.ErrorCode; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum OAuth2ErrorCode implements ErrorCode { | ||
|
||
INVALID_REQUEST("유효하지 않은 탈퇴 요청입니다.", "OAUTH2_001"), | ||
EXPIRED_AUTH_TOKEN("만료된 OAuth2 토큰입니다.", "OAUTH2_002"), | ||
INTERNAL_SERVER_ERROR("OAuth 서버 에러 발생입니다.", "OAUTH2_003"); | ||
private final String message; | ||
private final String code; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ public interface Oauth2Response { | |
|
||
String createSocialEmail(); | ||
|
||
String getOauth2AccessToken(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 설정은 어디에 쓰이나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OAuth2UnlinkService에서 사용하고 있습니다!