From 7ae5871ae05af3940363a42eab6a42f5f11736f6 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Fri, 22 Aug 2025 13:52:09 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=9A=8C=EC=9B=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20MemberRepository=EC=99=80=20MemberService?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20ID=EB=A1=9C?= =?UTF-8?q?=20=ED=99=9C=EC=84=B1=ED=99=94=EB=90=9C=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EC=9D=84=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=EC=BF=BC=EB=A6=AC=20=EC=A1=B0=EA=B1=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95.=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EA=B0=9C=EC=84=A0=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EB=8D=94=20=EB=AA=85=ED=99=95=ED=95=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=A0=9C=EA=B3=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/base/member/repository/MemberRepository.java | 4 ++-- .../base/member/repository/MemberRepositoryCustom.java | 5 ++--- .../base/member/repository/MemberRepositoryImpl.java | 8 ++++---- .../domain/base/member/service/MemberServiceImpl.java | 9 ++------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepository.java b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepository.java index 8ca52d6..4ebe31f 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepository.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepository.java @@ -8,7 +8,7 @@ import java.util.Optional; import java.util.List; @Repository -public interface MemberRepository extends JpaRepository { +public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { // 사용자 ID로 회원 조회 (Optional 반환) Optional findByUserId(String userId); @@ -30,4 +30,4 @@ public interface MemberRepository extends JpaRepository { // 활성화된 회원 목록 조회 List findByUseFlagTrue(); -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryCustom.java b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryCustom.java index 49d4ff1..1491b8b 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryCustom.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryCustom.java @@ -14,13 +14,12 @@ import java.util.Optional; public interface MemberRepositoryCustom { /** - * 사용자 ID로 회원을 조회합니다. - * QueryDSL을 사용하여 더 유연한 쿼리 작성이 가능합니다. + * 활성화된 사용자 중에서 사용자 ID로 검색하여 조회합니다. * * @param userId 사용자 ID * @return Optional 회원 정보 (없으면 empty) */ - Optional findByUserIdCustom(String userId); + Optional findActiveMemberByUserId(String userId); /** * 역할(Role)별로 회원 목록을 조회합니다. diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryImpl.java b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryImpl.java index ad918cd..2f1442f 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/repository/MemberRepositoryImpl.java @@ -32,12 +32,12 @@ public class MemberRepositoryImpl implements MemberRepositoryCustom { private final QMember member = QMember.member; @Override - public Optional findByUserIdCustom(String userId) { - // QueryDSL을 사용하여 사용자 ID로 회원을 조회합니다. - // eq() 메서드를 사용하여 정확한 일치 조건을 설정합니다. + public Optional findActiveMemberByUserId(String userId) { + // 활성화된 사용자 중에서 사용자 ID로 검색 Member foundMember = queryFactory .selectFrom(member) - .where(member.userId.eq(userId)) + .where(member.userId.eq(userId) + .and(member.useFlag.eq(true))) .fetchOne(); return Optional.ofNullable(foundMember); diff --git a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java index 66ff530..13d04b3 100644 --- a/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/base/member/service/MemberServiceImpl.java @@ -32,7 +32,7 @@ public class MemberServiceImpl implements MemberService { @Override public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { - Member member = memberRepository.findByUserIdAndUseFlagTrue(id) + Member member = memberRepository.findActiveMemberByUserId(id) .orElseThrow(() -> new UsernameNotFoundException("사용자를 찾을 수 없습니다: " + id)); // MapStruct를 사용하여 Member 엔티티를 MemberDto로 변환 @@ -45,7 +45,7 @@ public class MemberServiceImpl implements MemberService { @Transactional public MemberDto createMember(MemberDto memberDto) { // userId 중복 체크 - if (memberRepository.existsByUserIdAndUseFlagTrue(memberDto.getUserId())) { + if (memberRepository.existsByUserId(memberDto.getUserId())) { throw new ApiException(ApiResponseCode.USER_ID_DUPLICATE); } @@ -73,11 +73,6 @@ public class MemberServiceImpl implements MemberService { .orElseThrow(() -> new ApiException(ApiResponseCode.USER_NOT_FOUND)); memberMapper.updateMemberFromDto(memberDto, member); - - if (memberDto.getPassword() != null && !memberDto.getPassword().isEmpty()) { - member.setPassword(bCryptPasswordEncoder.encode(memberDto.getPassword())); - } - memberRepository.save(member); return 1; }