Skip to content

Commit

Permalink
Merge branch 'bug/#12-server-error' of https://github.com/nar0ng/9th-…
Browse files Browse the repository at this point in the history
…Growing-Pain-BE into bug/#12-server-error
  • Loading branch information
nar0ng committed Aug 14, 2024
2 parents 24e85b6 + 93de210 commit 842efc5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
S3_BUCKET_NAME: growing-pain-bucket
CODE_DEPLOY_APPLICATION_NAME: growing-pain-deploy
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: growing-pain-group
RESOURCE_PATH: ./src/main/resources/application.yml
RESOURCE_PATH: ./src/main/resources/application-dev.yml

permissions:
id-token: write
Expand Down Expand Up @@ -76,4 +76,4 @@ jobs:
--deployment-config-name CodeDeployDefault.AllAtOnce \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.zip
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.zip
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 @@ -38,14 +39,13 @@ public class AuthController {

private final AuthService authService;

@Operation(summary = "회원가입", description = "회원가입 및 로그인을 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@PostMapping("/join")
@Operation(summary = "일반 로그인", description = "회원가입 및 로그인을 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Token.class)))
@PostMapping("/login/general")
@ResponseStatus(HttpStatus.OK )
public Response<?> joinAuth(@RequestBody @Valid LoginRequest request) {
log.info("[회원 가입 컨트롤러]: {}", request.email());
Token token = authService.createLoginInfo(request);
return Response.createSuccess("회원가입 및 로그인 완료", token);
public Response<Token> joinAuth(@RequestBody @Valid LoginRequest request) {
log.info("[일반 로그인 컨트롤러]: {}", request.email());
return Response.createSuccess("회원가입 및 로그인 완료", authService.createLoginInfo(AuthProvider.GENERAL, request));
}

@Operation(summary = "추가 정보 입력", description = "최초 로그인 (회원가입) 시 추가 정보를 입력하는 메소드")
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/cotato/growingpain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -41,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 All @@ -67,16 +68,11 @@ public Token createLoginInfo(LoginRequest request) {
else {
// 신규 회원일 경우 회원가입 처리
validateService.checkPasswordPattern(request.password());
validateService.checkDuplicateEmail(request.email());
//validateService.checkDuplicateEmail(request.email());

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

Member member = Member.builder()
.password(bCryptPasswordEncoder.encode(request.password()))
.email(request.email())
.memberRole(MemberRole.PENDING)
.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 @@ -87,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 All @@ -101,6 +110,7 @@ public Token completeSignup(CompleteSignupRequest request, String accessToken) {
if(member.getMemberRole() == MemberRole.PENDING){
// 필드를 개별적으로 업데이트
member.updateMemberInfo(request.name(), request.field(), request.belong(),request.job());
//validateService.checkDuplicateNickName(request.name());
member.updateRole(MemberRole.MEMBER);
memberRepository.save(member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cotato.growingpain.post.domain.entity.PostSave;
import cotato.growingpain.replycomment.domain.entity.ReplyComment;
import cotato.growingpain.replycomment.domain.entity.ReplyCommentLike;
import cotato.growingpain.security.oauth.AuthProvider;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -74,8 +75,9 @@ public class Member extends BaseTimeEntity {
@Column(name = "oauth_id")
private String oauth2Id;

// @Column(name = "auth_provider")
// private AuthProvider authProvider;
@Column(name = "auth_provider")
@Enumerated(EnumType.STRING)
private AuthProvider authProvider;

@Column(name = "education_background")
private String educationBackground;
Expand Down Expand Up @@ -139,14 +141,12 @@ public class Member extends BaseTimeEntity {
private List<JobPost> jobPosts = new ArrayList<>();

@Builder
public Member(String email, String password, MemberRole memberRole, String name, String field, String belong, String profileImageUrl) {
public Member(String email, String password, String oauth2Id, AuthProvider authProvider, MemberRole memberRole) {
this.email = email;
this.password = password;
this.oauth2Id = oauth2Id;
this.authProvider = authProvider;
this.memberRole = memberRole;
this.name = name;
this.field = field;
this.belong = belong;
this.profileImageUrl = profileImageUrl;
}

public void updatePassword(String newPassword) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cotato/growingpain/security/oauth/AuthProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cotato.growingpain.security.oauth;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum AuthProvider {
GENERAL("일반 로그인"),
KAKAO("카카오 소셜 로그인"),
GOOGLE("구글 소셜 로그인");

private final String 분description;
}
1 change: 0 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ jwt:
# discord:
# webhook-uri: ${DISCORD_WEBHOOK_URI}
# config: classpath:logback-test.xml

0 comments on commit 842efc5

Please sign in to comment.