Skip to content

Commit

Permalink
refactor: 필요없는 service 제거 (auth)
Browse files Browse the repository at this point in the history
  • Loading branch information
suw0n committed Aug 21, 2024
1 parent ce75855 commit a058b1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ResponseData<LoginRes>> 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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

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

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

Expand All @@ -11,8 +12,6 @@

public interface MemberRepository extends JpaRepository<Member, String> {

Optional<Member> findById(String id);

Optional<Member> findByIdAndPw(String id, String pw);

List<Member> findByCreatedAtAfter(LocalDateTime createdAt);
Expand All @@ -26,4 +25,9 @@ public interface MemberRepository extends JpaRepository<Member, String> {

List<Member> findByNameContains(String name);

default Member getById(String id) {
return findById(id)
.orElseThrow(MemberNotFoundException::new);
}

}

0 comments on commit a058b1f

Please sign in to comment.