Skip to content
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

[HOTFIX] #233 - memberId로 User객체를 잘못 조회했던 문제 해결 #234

Merged
merged 7 commits into from
Oct 6, 2024
10 changes: 5 additions & 5 deletions src/main/java/com/beat/admin/facade/AdminFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ public class AdminFacade {
private final PromotionUseCase promotionUseCase;

public UserFindAllResponse checkMemberAndFindAllUsers(Long memberId) {
memberUseCase.findMemberById(memberId);
memberUseCase.findMemberByMemberId(memberId);
List<Users> users = userUseCase.findAllUsers();
return UserFindAllResponse.from(users);
}

public CarouselPresignedUrlFindAllResponse checkMemberAndIssueAllPresignedUrlsForCarousel(Long memberId,
List<String> carouselImages) {
memberUseCase.findMemberById(memberId);
memberUseCase.findMemberByMemberId(memberId);
Map<String, String> carouselPresignedUrls = fileUseCase.issueAllPresignedUrlsForCarousel(carouselImages);
return CarouselPresignedUrlFindAllResponse.from(carouselPresignedUrls);
}

public BannerPresignedUrlFindResponse checkMemberAndIssuePresignedUrlForBanner(Long memberId, String bannerImage) {
memberUseCase.findMemberById(memberId);
memberUseCase.findMemberByMemberId(memberId);
String bannerPresignedUrl = fileUseCase.issuePresignedUrlForBanner(bannerImage);
return BannerPresignedUrlFindResponse.from(bannerPresignedUrl);
}

public CarouselFindAllResponse checkMemberAndFindAllPromotionsSortedByCarouselNumber(Long memberId) {
memberUseCase.findMemberById(memberId);
memberUseCase.findMemberByMemberId(memberId);
List<Promotion> promotions = adminUsecase.findAllPromotionsSortedByCarouselNumber();
return CarouselFindAllResponse.from(promotions);
}

public CarouselHandleAllResponse checkMemberAndProcessAllPromotionsSortedByCarouselNumber(Long memberId,
CarouselHandleRequest request) {

memberUseCase.findMemberById(memberId);
memberUseCase.findMemberByMemberId(memberId);

List<PromotionModifyRequest> modifyRequests = new ArrayList<>();
List<PromotionGenerateRequest> generateRequests = new ArrayList<>();
Expand Down
62 changes: 32 additions & 30 deletions src/main/java/com/beat/domain/member/application/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import com.beat.domain.user.dao.UserRepository;
import com.beat.domain.user.domain.Users;
import com.beat.global.common.exception.*;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -18,34 +20,34 @@
@Transactional(readOnly = true)
@Service
public class MemberService implements MemberUseCase {
private final UserRepository userRepository;
private final MemberRepository memberRepository;

@Transactional
public void deleteUser(final Long id) {
Users users = userRepository.findById(id)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));

userRepository.delete(users);
}

public boolean checkMemberExistsBySocialIdAndSocialType(final Long socialId, final SocialType socialType) {
return memberRepository.findBySocialTypeAndSocialId(socialId, socialType).isPresent();
}

public Member findMemberBySocialIdAndSocialType(final Long socialId, final SocialType socialType) {
return memberRepository.findBySocialTypeAndSocialId(socialId, socialType)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
}

public Users findUserByMemberId(final Long memberId) {
return userRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
}

@Override
public Member findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
}
private final UserRepository userRepository;
private final MemberRepository memberRepository;

@Override
@Transactional(readOnly = true)
public Member findMemberByMemberId(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
}

@Override
@Transactional(readOnly = true)
public boolean checkMemberExistsBySocialIdAndSocialType(final Long socialId, final SocialType socialType) {
return memberRepository.findBySocialTypeAndSocialId(socialId, socialType).isPresent();
}

@Override
@Transactional(readOnly = true)
public Member findMemberBySocialIdAndSocialType(final Long socialId, final SocialType socialType) {
return memberRepository.findBySocialTypeAndSocialId(socialId, socialType)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));
}

@Transactional
public void deleteUser(final Long id) {
Users users = userRepository.findById(id)
.orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND));

userRepository.delete(users);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.beat.domain.member.domain.SocialType;
import com.beat.domain.member.dto.LoginSuccessResponse;
import com.beat.domain.member.exception.MemberErrorCode;
import com.beat.domain.member.port.in.MemberUseCase;
import com.beat.domain.user.domain.Users;
import com.beat.domain.user.port.in.UserUseCase;
import com.beat.global.auth.client.application.KakaoSocialService;
import com.beat.global.auth.client.application.SocialService;
import com.beat.global.auth.client.dto.MemberInfoResponse;
Expand All @@ -22,10 +24,10 @@
@Service
public class SocialLoginService {

private final MemberService memberService;
private final MemberRegistrationService memberRegistrationService;
private final AuthenticationService authenticationService;
private final KakaoSocialService kakaoSocialService;
private final MemberUseCase memberUseCase;

/**
* 소셜 로그인 또는 회원가입을 처리하는 메서드.
Expand Down Expand Up @@ -86,7 +88,9 @@ private LoginSuccessResponse generateLoginResponseFromMemberInfo(final MemberInf
Long memberId = findOrRegisterMember(memberInfoResponse);
log.info("Found or registered member with memberId: {}", memberId);

Users user = memberService.findUserByMemberId(memberId);
Member member = memberUseCase.findMemberByMemberId(memberId);
Users user = member.getUser();

log.info("User role before generating token: {}", user.getRole());

return authenticationService.generateLoginSuccessResponse(memberId, user, memberInfoResponse);
Expand All @@ -100,11 +104,11 @@ private LoginSuccessResponse generateLoginResponseFromMemberInfo(final MemberInf
* @return 등록된 회원 또는 기존 회원의 ID
*/
private Long findOrRegisterMember(final MemberInfoResponse memberInfoResponse) {
boolean memberExists = memberService.checkMemberExistsBySocialIdAndSocialType(memberInfoResponse.socialId(),
boolean memberExists = memberUseCase.checkMemberExistsBySocialIdAndSocialType(memberInfoResponse.socialId(),
memberInfoResponse.socialType());

if (memberExists) {
Member existingMember = memberService.findMemberBySocialIdAndSocialType(memberInfoResponse.socialId(),
Member existingMember = memberUseCase.findMemberBySocialIdAndSocialType(memberInfoResponse.socialId(),
memberInfoResponse.socialType());
log.info("Existing member role: {}", existingMember.getUser().getRole());
return existingMember.getId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.beat.domain.member.port.in;

import com.beat.domain.member.domain.Member;
import com.beat.domain.member.domain.SocialType;

public interface MemberUseCase {
Member findMemberById(Long memberId);
Member findMemberByMemberId(Long memberId);

boolean checkMemberExistsBySocialIdAndSocialType(Long socialId, SocialType socialType);

Member findMemberBySocialIdAndSocialType(Long socialId, SocialType socialType);

void deleteUser(Long id);
}
23 changes: 17 additions & 6 deletions src/main/java/com/beat/domain/user/application/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.beat.domain.user.dao.UserRepository;
import com.beat.domain.user.domain.Users;
import com.beat.domain.user.exception.UserErrorCode;
import com.beat.domain.user.port.in.UserUseCase;
import com.beat.global.common.exception.NotFoundException;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -12,11 +16,18 @@
@Service
@RequiredArgsConstructor
public class UserService implements UserUseCase {
private final UserRepository userRepository;
private final UserRepository userRepository;

@Override
@Transactional(readOnly = true)
public List<Users> findAllUsers() {
return userRepository.findAll();
}

@Override
@Transactional(readOnly = true)
public List<Users> findAllUsers() {
return userRepository.findAll();
}
@Override
@Transactional(readOnly = true)
public Users findUserByUserId(final Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND));
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/beat/domain/user/port/in/UserUseCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface UserUseCase {
List<Users> findAllUsers();

Users findUserByUserId(final Long userId);
}
Loading