diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/application/AuthUseCase.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/application/AuthUseCase.java index a0f33531..1bcdb054 100644 --- a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/application/AuthUseCase.java +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/application/AuthUseCase.java @@ -3,7 +3,7 @@ import b1nd.dodam.domain.rds.member.entity.Member; import b1nd.dodam.domain.rds.member.exception.DeactivateMemberException; import b1nd.dodam.domain.rds.member.exception.WrongPasswordException; -import b1nd.dodam.domain.rds.member.service.MemberService; +import b1nd.dodam.domain.rds.member.repository.MemberRepository; import b1nd.dodam.restapi.auth.application.data.req.LoginReq; import b1nd.dodam.restapi.support.data.ResponseData; import b1nd.dodam.restapi.support.encrypt.Sha512PasswordEncoder; @@ -21,27 +21,26 @@ @Component public class AuthUseCase { - private final MemberService memberService; + private final MemberRepository memberRepository; private final DodamTokenClient tokenClient; private final Executor executor; - public AuthUseCase(MemberService memberService, + public AuthUseCase(MemberRepository memberRepository, DodamTokenClient tokenClient, @Qualifier("asyncExecutor") Executor executor) { - this.memberService = memberService; + this.memberRepository = memberRepository; this.tokenClient = tokenClient; this.executor = executor; } public CompletableFuture> login(LoginReq req) { - Member member = memberService.getMemberBy(req.id()); + Member member = memberRepository.getById(req.id()); if(!member.isCorrectPw(Sha512PasswordEncoder.encode(req.pw()))) { throw new WrongPasswordException(); } if(!member.isActive()) { throw new DeactivateMemberException(); } - return CompletableFuture.supplyAsync(() -> member, executor) .thenCompose(m -> tokenClient.issueTokens(member.getId(), member.getRole().getNumber())) .thenApply(tokens -> new LoginRes(member, tokens.accessToken(), tokens.refreshToken())) diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/BroadcastMemberFilter.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/BroadcastMemberFilter.java index 9476c7b6..6d6b1b0b 100644 --- a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/BroadcastMemberFilter.java +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/BroadcastMemberFilter.java @@ -3,7 +3,7 @@ import b1nd.dodam.core.exception.global.GlobalExceptionCode; import b1nd.dodam.domain.rds.member.entity.Member; import b1nd.dodam.domain.rds.member.enumeration.MemberRole; -import b1nd.dodam.domain.rds.member.service.MemberService; +import b1nd.dodam.domain.rds.member.repository.BroadcastClubMemberRepository; import b1nd.dodam.restapi.auth.infrastructure.security.support.MemberAuthenticationHolder; import b1nd.dodam.restapi.support.exception.ErrorResponseSender; import jakarta.servlet.FilterChain; @@ -23,7 +23,7 @@ @RequiredArgsConstructor public class BroadcastMemberFilter extends OncePerRequestFilter { - private final MemberService memberService; + private final BroadcastClubMemberRepository broadcastClubMemberRepository; private final MemberAuthenticationHolder memberAuthenticationHolder; private final ErrorResponseSender errorResponseSender; @@ -84,7 +84,7 @@ private boolean needsBroadcastClubMemberCheck(String uri, String method) { } private boolean isNotBroadcastClubMemberAndAdmin(Member member) { - return !MemberRole.ADMIN.equals(member.getRole()) && !memberService.checkBroadcastClubMember(member); + return !MemberRole.ADMIN.equals(member.getRole()) && !broadcastClubMemberRepository.existsByMember(member); } } diff --git a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/TokenFilter.java b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/TokenFilter.java index e794c810..f88ad5f3 100644 --- a/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/TokenFilter.java +++ b/dodam-application/dodam-rest-api/src/main/java/b1nd/dodam/restapi/auth/infrastructure/security/filter/TokenFilter.java @@ -1,6 +1,6 @@ package b1nd.dodam.restapi.auth.infrastructure.security.filter; -import b1nd.dodam.domain.rds.member.service.MemberService; +import b1nd.dodam.domain.rds.member.repository.MemberRepository; import b1nd.dodam.restapi.auth.infrastructure.security.MemberDetails; import b1nd.dodam.restapi.auth.infrastructure.security.support.TokenExtractor; import b1nd.dodam.token.client.DodamTokenClient; @@ -23,8 +23,8 @@ public class TokenFilter extends OncePerRequestFilter { private static final String TOKEN_TYPE = "Bearer"; + private final MemberRepository memberRepository; private final DodamTokenClient tokenClient; - private final MemberService memberService; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { @@ -48,7 +48,7 @@ private Authentication createAuthentication(String token) { private MemberDetails getMemberDetails(String token) { String id = tokenClient.getMemberIdByToken(token); - return new MemberDetails(memberService.getMemberBy(id)); + return new MemberDetails(memberRepository.getById(id)); } } diff --git a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/repository/MemberRepository.java b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/repository/MemberRepository.java index 464c92c2..ed8ff3b8 100644 --- a/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/repository/MemberRepository.java +++ b/dodam-system-domain/dodam-domain-rds/src/main/java/b1nd/dodam/domain/rds/member/repository/MemberRepository.java @@ -2,6 +2,7 @@ import b1nd.dodam.domain.rds.member.entity.Member; import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus; +import b1nd.dodam.domain.rds.member.exception.MemberNotFoundException; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -11,8 +12,6 @@ public interface MemberRepository extends JpaRepository { - Optional findById(String id); - Optional findByIdAndPw(String id, String pw); List findByCreatedAtAfter(LocalDateTime createdAt); @@ -26,4 +25,9 @@ public interface MemberRepository extends JpaRepository { List findByNameContains(String name); + default Member getById(String id) { + return findById(id) + .orElseThrow(MemberNotFoundException::new); + } + }