Skip to content
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

[fix] 소셜 로그인 & 회원가입 API 스펙 변경 #84

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.doorip.user.dto.request.UserSignInRequest;
import org.doorip.user.dto.request.UserSignUpRequest;
import org.doorip.user.dto.response.ProfileGetResponse;
import org.doorip.user.dto.response.UserResponse;
import org.doorip.user.dto.response.UserSignUpResponse;
import org.doorip.user.dto.response.UserSignInResponse;
import org.doorip.user.service.UserService;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -41,7 +41,7 @@ public ResponseEntity<ApiResponse<?>> signIn(@RequestHeader(AUTHORIZATION) final
@PostMapping("/signup")
public ResponseEntity<ApiResponse<?>> signUp(@RequestHeader(AUTHORIZATION) final String token,
@RequestBody final UserSignUpRequest request) {
final UserResponse response = userService.signUp(token, request);
final UserSignUpResponse response = userService.signUp(token, request);
return ApiResponseUtil.success(SuccessMessage.CREATED, response);
}

Expand All @@ -60,7 +60,7 @@ public ResponseEntity<ApiResponse<?>> withdraw(@UserId final Long userId) {
@PostMapping("/reissue")
public ResponseEntity<ApiResponse<?>> reissue(@RequestHeader(AUTHORIZATION) final String refreshtoken,
@RequestBody final UserReissueRequest request) {
UserResponse response = userService.reissue(refreshtoken, request);
final UserSignUpResponse response = userService.reissue(refreshtoken, request);
return ApiResponseUtil.success(SuccessMessage.OK, response);
}

Expand All @@ -72,7 +72,7 @@ public ResponseEntity<ApiResponse<?>> getProfile(@UserId final Long userId) {

@PatchMapping("/test")
public ResponseEntity<ApiResponse<?>> updateResult(@UserId final Long userId,
@RequestBody ResultUpdateRequest request) {
@RequestBody final ResultUpdateRequest request) {
userService.updateResult(userId, request);
return ApiResponseUtil.success(SuccessMessage.OK);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.doorip.user.dto.response;

import lombok.AccessLevel;
import lombok.Builder;
import org.doorip.auth.jwt.Token;

@Builder(access = AccessLevel.PRIVATE)
public record UserSignInResponse(
String accessToken,
String refreshToken,
boolean isResult
boolean isResult,
Long userId
) {

public static UserSignInResponse of(Token token, boolean isResult) {
return new UserSignInResponse(
token.accessToken(),
token.refreshToken(),
isResult
);
public static UserSignInResponse of(Token token, boolean isResult, Long userId) {
return UserSignInResponse.builder()
.accessToken(token.accessToken())
.refreshToken(token.refreshToken())
.isResult(isResult)
.userId(userId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.doorip.user.dto.response;

import lombok.AccessLevel;
import lombok.Builder;
import org.doorip.auth.jwt.Token;

@Builder(access = AccessLevel.PRIVATE)
public record UserSignUpResponse(
String accessToken,
String refreshToken,
Long userId
) {
public static UserSignUpResponse of(Token token, Long userId) {
return UserSignUpResponse.builder()
.accessToken(token.accessToken())
.refreshToken(token.refreshToken())
.userId(userId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.doorip.user.dto.request.UserSignInRequest;
import org.doorip.user.dto.request.UserSignUpRequest;
import org.doorip.user.dto.response.ProfileGetResponse;
import org.doorip.user.dto.response.UserResponse;
import org.doorip.user.dto.response.UserSignInResponse;
import org.doorip.user.dto.response.UserSignUpResponse;
import org.doorip.user.repository.RefreshTokenRepository;
import org.doorip.user.repository.UserRepository;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -57,17 +57,17 @@ public UserSignInResponse signIn(String token, UserSignInRequest request) {
boolean isResult = hasResult(findUser);
Token issueToken = jwtProvider.issueToken(findUser.getId());
updateRefreshToken(issueToken.refreshToken(), findUser);
return UserSignInResponse.of(issueToken, isResult);
return UserSignInResponse.of(issueToken, isResult, findUser.getId());
}

public UserResponse signUp(String token, UserSignUpRequest request) {
public UserSignUpResponse signUp(String token, UserSignUpRequest request) {
Platform enumPlatform = getEnumPlatformFromStringPlatform(request.platform());
String platformId = getPlatformId(token, enumPlatform);
validateDuplicateUser(enumPlatform, platformId);
User savedUser = saveUser(request, platformId, enumPlatform);
Token issueToken = jwtProvider.issueToken(savedUser.getId());
updateRefreshToken(issueToken.refreshToken(), savedUser);
return UserResponse.of(issueToken);
return UserSignUpResponse.of(issueToken, savedUser.getId());
}

public void signOut(Long userId) {
Expand All @@ -80,13 +80,13 @@ public void withdraw(Long userId) {
}

@Transactional(noRollbackFor = UnauthorizedException.class)
public UserResponse reissue(String refreshToken, UserReissueRequest request) {
public UserSignUpResponse reissue(String refreshToken, UserReissueRequest request) {
Long userId = request.userId();
validateRefreshToken(refreshToken, userId);
User findUser = getUser(userId);
Token issueToken = jwtProvider.issueToken(userId);
updateRefreshToken(issueToken.refreshToken(), findUser);
return UserResponse.of(issueToken);
return UserSignUpResponse.of(issueToken, findUser.getId());
}

@Transactional(readOnly = true)
Expand All @@ -99,9 +99,9 @@ public void updateResult(Long userId, ResultUpdateRequest request) {
User findUser = getUser(userId);
validateResult(request);
List<MappingIndex> mappedIndex = mappingIndex(request.result());
String stringResult = oneTypeResult(mappedIndex.subList(0,3), "S", "A")
+ oneTypeResult(mappedIndex.subList(3,6), "R", "E")
+ oneTypeResult(mappedIndex.subList(6,9), "P", "I");
String stringResult = oneTypeResult(mappedIndex.subList(0, 3), "S", "A")
+ oneTypeResult(mappedIndex.subList(3, 6), "R", "E")
+ oneTypeResult(mappedIndex.subList(6, 9), "P", "I");

Result result = getEnumResultFromStringResult(stringResult);
findUser.updateResult(result);
Expand Down