Skip to content

Commit

Permalink
[Weekly/11/Refactor/TokenResponse] token response에 사용자 아이디, 타입 반환하도록 …
Browse files Browse the repository at this point in the history
…반영 (#139)
  • Loading branch information
lja3723 committed Nov 15, 2024
1 parent a1c3cfd commit cdf57ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public ResponseEntity<ApiResponseBody<TokenResponse>> testCreateToken(
}

private TokenResponse createToken(MemberIdentifier identifier) {
return TokenResponse.from(jwtService.createAccessToken(identifier.id(), identifier.type()));
String accessToken = jwtService.createAccessToken(identifier.id(), identifier.type());
return TokenResponse.of(accessToken, identifier.id(), identifier.type());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.ktc2.cokaen.wouldyouin.auth.api.dto;

import lombok.Builder;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Builder
public record SocialTokenResponse(Boolean isWelcomeMember, String token) {
public record SocialTokenResponse(Boolean isWelcomeMember, String token, Long memberId, MemberType memberType) {

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.ktc2.cokaen.wouldyouin.auth.api.dto;

import lombok.Builder;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Builder
public record TokenResponse(String token) {
public record TokenResponse(String token, Long memberId, MemberType memberType) {

public static TokenResponse from(String token) {
public static TokenResponse of(String token, Long memberId, MemberType memberType) {
return TokenResponse.builder()
.token(token)
.memberId(memberId)
.memberType(memberType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public class AuthService {
@Transactional
public TokenResponse localSignup(LocalSignupRequest request) {
baseMemberService.checkUniqueEmailOrThrow(request.getEmail());
return TokenResponse.from(createToken(hostService.createHost(request)));
MemberResponse response = hostService.createHost(request);
return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType());
}

@Transactional(readOnly = true)
public TokenResponse localLogin(LocalLoginRequest request) {
return TokenResponse.from(createToken(hostService.getMemberResponseBy(request)));
MemberResponse response = hostService.getMemberResponseBy(request);
return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType());
}

@Transactional
Expand All @@ -55,13 +57,17 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) {
return SocialTokenResponse.builder()
.isWelcomeMember(false)
.token(createToken(id))
.memberId(id.id())
.memberType(id.type())
.build();
}
// 소셜 계정이지만 아직 추가 정보 기입이 되지 않은 경우
else {
return SocialTokenResponse.builder()
.isWelcomeMember(true)
.token(createToken(id))
.memberId(id.id())
.memberType(id.type())
.build();
}
}
Expand All @@ -78,12 +84,15 @@ public SocialTokenResponse socialLogin(AccountType accountType, String code) {
return SocialTokenResponse.builder()
.isWelcomeMember(true)
.token(createToken(welcomeMemberResponse))
.memberId(welcomeMemberResponse.getMemberId())
.memberType(welcomeMemberResponse.getMemberType())
.build();
}

@Transactional
public TokenResponse acceptAdditionalInfo(Long welcomeMemberId, MemberAdditionalInfoRequest request) {
return TokenResponse.from(createToken(memberService.updateWelcomeMember(welcomeMemberId, request)));
MemberResponse response = memberService.updateWelcomeMember(welcomeMemberId, request);
return TokenResponse.of(createToken(response), response.getMemberId(), response.getMemberType());
}

private String createToken(MemberIdentifier identifier) {
Expand Down

0 comments on commit cdf57ab

Please sign in to comment.