Skip to content

Commit

Permalink
chore : 잘못된 예외 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JiwonKKang committed Nov 5, 2024
1 parent 9ce7f80 commit a95277e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public Response<Void> login(

@PostMapping("/oauth/sign-up")
public Response<Void> signUp(@RequestBody SignUpRequest request, HttpServletResponse response) {
JwtTokens jwtTokens =
authService.signUp(
request.oAuthTokens(),
request.deviceToken(),
request.toAddressWithCoordinate());
JwtTokens jwtTokens = authService.signUp(request.oAuthTokens(), request.deviceToken());
JwtTokenizer.setInHeader(response, jwtTokens.accessToken(), jwtTokens.refreshToken());
return Response.success("회원가입 성공");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
import core.startup.mealtoktok.domain.user.Address;
import core.startup.mealtoktok.domain.user.AddressWithCoordinate;

public record SignUpRequest(
OAuthTokens oAuthTokens, String deviceToken, AddressInfoRequest addressInfoRequest) {
public record SignUpRequest(OAuthTokens oAuthTokens, String deviceToken) {

public record AddressInfoRequest(Address address, Double latitude, Double longitude) {

public AddressWithCoordinate toAddressWithCoordinate() {
return AddressWithCoordinate.of(address, latitude, longitude);
}
}

public AddressWithCoordinate toAddressWithCoordinate() {
return addressInfoRequest.toAddressWithCoordinate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static UserId extractTargetUser(String token) {
throw InvalidTokenException.EXCEPTION;
}
}
;

@Override
public JwtTokens generate(UserId userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Tag(name = "회원 API")
public interface UserApiDocs {

@Operation
@Operation(summary = "회원 정보 조회")
Response<UserResponse> getUser(Long userId);

@Operation(summary = "내 정보 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ public class AuthService {

public boolean canRegistered(String idToken) {
OAuthInfo oAuthInfo = oAuthAuthenticator.authenticate(idToken);
return !userValidator.isAlreadyRegistered(oAuthInfo);
return userValidator.isNotRegistered(oAuthInfo);
}

public JwtTokens signUp(
OAuthTokens oAuthTokens,
String deviceToken,
AddressWithCoordinate addressWithCoordinate) {
public JwtTokens signUp(OAuthTokens oAuthTokens, String deviceToken) {
OAuthInfo oAuthInfo = oAuthAuthenticator.authenticate(oAuthTokens.idToken());
UserProfile userProfile = oAuthClient.getUserProfile(oAuthTokens.accessToken());
userValidator.validate(oAuthInfo);
Expand All @@ -50,12 +47,6 @@ public String getKakaoOAuthUrl() {

public JwtTokens getCredentialTest(String code) {
OAuthTokens authToken = oAuthClient.auth(CLIENT_ID, REDIRECT_URL, code);
return signUp(
authToken,
"deviceTokenTest",
AddressWithCoordinate.of(
Address.of("충청북도 청주시 서원구 충대로 1", "충청북도 청주시 흥덕구 853-18"),
4536.629,
127.456));
return signUp(authToken, "deviceTokenTest");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class UserValidator {

private final UserRepository userRepository;

public boolean isAlreadyRegistered(OAuthInfo oAuthInfo) {
return userRepository.existsByOAuthInfo(oAuthInfo);
public boolean isNotRegistered(OAuthInfo oAuthInfo) {
return !userRepository.existsByOAuthInfo(oAuthInfo);
}

public void validate(OAuthInfo oAuthInfo) {
if (isAlreadyRegistered(oAuthInfo)) {
if (isNotRegistered(oAuthInfo)) {
throw AlreadyRegisteredUserException.EXCEPTION;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public MealDelivery findByOrdererAndDeliveryState(
return mealDeliveryJpaRepository
.findByOrdererAndDeliveryState(recipient, deliveryState)
.map(MealDeliveryEntity::toDomain)
.orElseThrow(() -> OrderNotFoundException.EXCEPTION);
.orElseThrow(() -> MealDeliveryNotFoundException.EXCEPTION);
}

@Override
Expand All @@ -81,7 +81,7 @@ public MealDelivery findByDeliveryStateAndTime(
return mealDeliveryJpaRepository
.findByOrdererAndDeliveryStateAndTime(recipient, deliveryState, startTime, endTime)
.map(MealDeliveryEntity::toDomain)
.orElseThrow(() -> OrderNotFoundException.EXCEPTION);
.orElseThrow(() -> MealDeliveryNotFoundException.EXCEPTION);
}

@Override
Expand Down

0 comments on commit a95277e

Please sign in to comment.