Skip to content
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 @@ -53,7 +53,7 @@ public ApplicationContext fetchPayments(Function<List<Long>, List<PaymentJpaEnti
List<Long> examApplicationIds = this.examApplications.stream()
.map(ExamApplicationJpaEntity::getId).toList();
Map<Long, PaymentJpaEntity> newPaymentMap = fetcher.apply(examApplicationIds).stream()
.filter(payment -> payment.getPaymentStatus() == PaymentStatus.DONE)
.filter(payment -> payment.getPaymentStatus().equals(PaymentStatus.DONE))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using .equals() to compare enums can introduce a NullPointerException if payment.getPaymentStatus() is null. Using == is null-safe and the idiomatic way to compare enums in Java.

Suggested change
.filter(payment -> payment.getPaymentStatus().equals(PaymentStatus.DONE))
.filter(payment -> payment.getPaymentStatus() == PaymentStatus.DONE)

.collect(Collectors.toMap(
PaymentJpaEntity::getExamApplicationId,
Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ public List<ApplicationResponse> getApplications(Long userId) {
.fetchPayments(paymentJpaRepository::findByExamApplicationIdIn)
.assemble();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation can be more concise using the Optional API, avoiding the intermediate user variable and clarifying the data flow.

        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);
}
}
Expand Down
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
Expand Up @@ -116,7 +116,11 @@ public enum ErrorCode {
BANNER_DELETE_FAILURE(HttpStatus.CONFLICT, "배너를 삭제하는 것에 실패하였습니다."),
EXCEL_DATA_EMPTY(HttpStatus.NOT_FOUND, "엑셀 데이터가 없습니다."),
EXCEL_DOWNLOAD_FAILURE(HttpStatus.CONFLICT, "엑셀 다운로드 중 문제가 발생했습니다."),
CACHE_UPDATE_FAIL(HttpStatus.CONFLICT, "캐시 업데이트에 실패하였습니다.");
CACHE_UPDATE_FAIL(HttpStatus.CONFLICT, "캐시 업데이트에 실패하였습니다."),

// ID 찾기 관련
NOT_FOUND_LOGIN_ID(HttpStatus.NOT_FOUND, "해당 아이디를 찾을 수 없습니다.");

private final HttpStatus status;
private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import life.mosu.mosuserver.global.util.ApiResponseWrapper;
import life.mosu.mosuserver.presentation.user.dto.ChangePasswordRequest;
import life.mosu.mosuserver.presentation.user.dto.ChangePasswordResponse;
import life.mosu.mosuserver.presentation.user.dto.FindIdRequest;
import life.mosu.mosuserver.presentation.user.dto.FindIdResponse;
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.http.HttpStatus;
Expand All @@ -25,11 +25,13 @@ public class MyUserController implements MyUserControllerDocs {
private final MyUserService myUserService;

@PostMapping("/find-id")
public ResponseEntity<ApiResponseWrapper<FindIdResponse>> findId(
@RequestBody @Valid FindIdRequest request
public ResponseEntity<ApiResponseWrapper<FindLoginIdResponse>> findLoginId(
@RequestBody @Valid FindLoginIdRequest request
) {
FindLoginIdResponse response = myUserService.findLoginId(request);

return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "아이디 찾기 요청 성공", null));
return ResponseEntity.ok(
ApiResponseWrapper.success(HttpStatus.OK, "아이디 찾기 요청 성공", response));
}

@PostMapping("/find-password")
Expand Down
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;
Expand All @@ -21,7 +22,7 @@ public class UserController implements UserControllerDocs {

@GetMapping("/customer-key")
public ResponseEntity<ApiResponseWrapper<CustomerKeyResponse>> getCustomerKey(
@RequestParam Long userId
@UserId final Long userId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The change from @RequestParam to @UserId is a good refactoring, but it's out of scope for the "Find ID" feature. Submit refactorings in a separate PR for easier reviews and a cleaner commit history. This also applies to UserControllerDocs.java.

) {
String customerKey = userService.getCustomerKey(userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
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;
Expand All @@ -25,7 +26,7 @@ public interface UserControllerDocs {
@ApiResponse(responseCode = "500", description = "서버 내부 오류")
})
public ResponseEntity<ApiResponseWrapper<CustomerKeyResponse>> getCustomerKey(
@RequestParam Long userId
@UserId final Long userId
);

@Operation(summary = "로그인 ID 중복 확인", description = "회원가입 시 사용할 로그인 ID의 중복 여부를 확인합니다.")
Expand Down

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);
}
}