-
Notifications
You must be signed in to change notification settings - Fork 2
MOSU-138 feat: ID 찾기 기능 구현 #139
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,13 @@ | |
| import life.mosu.mosuserver.global.exception.ErrorCode; | ||
| import life.mosu.mosuserver.presentation.user.dto.ChangePasswordRequest; | ||
| import life.mosu.mosuserver.presentation.user.dto.ChangePasswordResponse; | ||
| import life.mosu.mosuserver.presentation.user.dto.FindLoginIdRequest; | ||
| import life.mosu.mosuserver.presentation.user.dto.FindLoginIdResponse; | ||
| import life.mosu.mosuserver.presentation.user.dto.FindPasswordRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Propagation; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
|
|
@@ -31,12 +34,23 @@ public ChangePasswordResponse changePassword(Long userId, ChangePasswordRequest | |
| return ChangePasswordResponse.from(Boolean.TRUE); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) | ||
| public FindLoginIdResponse findLoginId(FindLoginIdRequest request) { | ||
| UserJpaEntity user = userJpaRepository.findByNameAndPhoneNumber(request.name(), | ||
| request.phoneNumber()) | ||
| .orElseThrow(() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_LOGIN_ID)); | ||
|
|
||
| return FindLoginIdResponse.from(user.getLoginId()); | ||
|
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation can be more concise using the return userJpaRepository.findByNameAndPhoneNumber(request.name(),
request.phoneNumber())
.map(UserJpaEntity::getLoginId)
.map(FindLoginIdResponse::from)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_LOGIN_ID)); |
||
|
|
||
| } | ||
|
|
||
| @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) | ||
| public void findPassword(Long userId, FindPasswordRequest request) { | ||
| UserJpaEntity user = userJpaRepository.findById(userId) | ||
| .orElseThrow(() -> new CustomRuntimeException(ErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| if (user.getName() != request.name() || user.getLoginId() != request.loginId()) { | ||
| if (!user.getName().equals(request.name()) || !user.getLoginId() | ||
| .equals(request.loginId())) { | ||
| throw new CustomRuntimeException(ErrorCode.USER_INFO_INVALID); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| package life.mosu.mosuserver.domain.user; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface UserJpaRepository extends JpaRepository<UserJpaEntity, Long> { | ||
|
|
||
| Optional<UserJpaEntity> findByLoginId(String loginId); | ||
|
|
||
| boolean existsByLoginId(String loginId); | ||
|
|
||
|
|
||
| Optional<UserJpaEntity> findByNameAndPhoneNumber(String name, String phoneNumber); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package life.mosu.mosuserver.presentation.user; | ||
|
|
||
| import life.mosu.mosuserver.application.user.UserService; | ||
| import life.mosu.mosuserver.global.annotation.UserId; | ||
| import life.mosu.mosuserver.global.util.ApiResponseWrapper; | ||
| import life.mosu.mosuserver.presentation.user.dto.CustomerKeyResponse; | ||
| import life.mosu.mosuserver.presentation.user.dto.IsLoginIdAvailableResponse; | ||
|
|
@@ -21,7 +22,7 @@ public class UserController implements UserControllerDocs { | |
|
|
||
| @GetMapping("/customer-key") | ||
| public ResponseEntity<ApiResponseWrapper<CustomerKeyResponse>> getCustomerKey( | ||
| @RequestParam Long userId | ||
| @UserId final Long userId | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) { | ||
| String customerKey = userService.getCustomerKey(userId); | ||
|
|
||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package life.mosu.mosuserver.presentation.user.dto; | ||
|
|
||
| import life.mosu.mosuserver.global.annotation.PhoneNumberPattern; | ||
|
|
||
| public record FindLoginIdRequest( | ||
| String name, | ||
| @PhoneNumberPattern | ||
| String phoneNumber | ||
| ) { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package life.mosu.mosuserver.presentation.user.dto; | ||
|
|
||
| public record FindLoginIdResponse( | ||
| String loginId | ||
| ) { | ||
|
|
||
| public static FindLoginIdResponse from(String loginId) { | ||
| return new FindLoginIdResponse(loginId); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
.equals()to compare enums can introduce aNullPointerExceptionifpayment.getPaymentStatus()isnull. Using==is null-safe and the idiomatic way to compare enums in Java.