Skip to content

Commit

Permalink
refactor: 확장성을 위한 코드 리팩토링
Browse files Browse the repository at this point in the history
- AuthProvider 관련 정보를 AuthService와 AuthController에도 추가
- 공통 메서드 분리
  • Loading branch information
yunhacandy committed Aug 13, 2024
1 parent 33dcc7e commit f796c55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import cotato.growingpain.security.jwt.Token;
import cotato.growingpain.security.jwt.dto.request.ReissueRequest;
import cotato.growingpain.security.jwt.dto.response.ReissueResponse;
import cotato.growingpain.security.oauth.AuthProvider;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class AuthController {
@ResponseStatus(HttpStatus.OK )
public Response<Token> joinAuth(@RequestBody @Valid LoginRequest request) {
log.info("[일반 로그인 컨트롤러]: {}", request.email());
return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(request));
return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(AuthProvider.GENERAL, request));
}

@Operation(summary = "추가 정보 입력", description = "최초 로그인 (회원가입) 시 추가 정보를 입력하는 메소드")
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/cotato/growingpain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class AuthService {
private final BlackListRepository blackListRepository;

@Transactional
public Token createLoginInfo(LoginRequest request) {
public Token createLoginInfo(AuthProvider authProvider, LoginRequest request) {

Optional<Member> existingMember = memberRepository.findByEmail(request.email());

Expand Down Expand Up @@ -72,13 +72,7 @@ public Token createLoginInfo(LoginRequest request) {

log.info("[회원 가입 서비스]: {}", request.email());

Member member = Member.builder()
.password(bCryptPasswordEncoder.encode(request.password()))
.email(request.email())
.memberRole(MemberRole.PENDING)
.authProvider(AuthProvider.GENERAL)
.build();
memberRepository.save(member);
Member member = registerMember(authProvider, request.email(), request.password());

// 회원가입 성공 후 토큰 생성 및 반환
Token token = jwtTokenProvider.createToken(member.getId(), member.getEmail(), MemberRole.PENDING.getDescription());
Expand All @@ -89,6 +83,19 @@ public Token createLoginInfo(LoginRequest request) {
}
}

private Member registerMember(AuthProvider authProvider, String email, String password) {
Member.MemberBuilder memberBuilder = Member.builder()
.email(email)
.authProvider(authProvider)
.memberRole(MemberRole.PENDING);

if (authProvider == AuthProvider.GENERAL) {
memberBuilder.password(bCryptPasswordEncoder.encode(password));
}

return memberRepository.save(memberBuilder.build());
}

@Transactional
public Token completeSignup(CompleteSignupRequest request, String accessToken) {

Expand Down

0 comments on commit f796c55

Please sign in to comment.