Skip to content

Commit

Permalink
fix: 없는 member_id로 차단 시도 시 예외 처리 (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
penrose15 committed Sep 7, 2024
1 parent 8c48045 commit 307b505
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface MemberUseCase {
Member createMemberBy(SocialMemberCommand command);

MemberIdAndNickname findIdAndNicknameById(Long memberId);

boolean existsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface MemberPersistencePort {
Optional<Member> updateProfileImageUrl(Long memberId, String profileImageUrl);

Optional<MemberIdAndNickname> findIdAndNicknameById(Long memberId);

boolean existsByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public MemberIdAndNickname findIdAndNicknameById(Long memberId) {
.orElseThrow(() -> new NotFoundException(MemberErrorType.NOT_FOUND));
}

@Override
public boolean existsByMemberId(Long memberId) {
return memberPersistencePort.existsByMemberId(memberId);
}

@Override
public Member update(UpdateMemberCommand command) {
if (command.nickname() != null && command.nickname().isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ public Optional<MemberIdAndNickname> findIdAndNicknameById(Long memberId) {
return findById(memberId)
.map(item -> new MemberIdAndNickname(item.getId(), item.getNickname()));
}

@Override
public boolean existsByMemberId(Long memberId) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public Optional<MemberIdAndNickname> findIdAndNicknameById(Long memberId) {
new MemberIdAndNickname(result.get(0, Long.class), result.get(1, String.class)));
}

@Override
public boolean existsByMemberId(Long memberId) {
return !queryFactory
.select(member.id)
.from(member)
.where(member.id.eq(memberId))
.fetch()
.isEmpty();
}

@Override
public Optional<Member> updateGender(Long memberId, MemberGender gender) {
return memberJpaRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.depromeet.blacklist.port.in.usecase.BlacklistQueryUseCase;
import com.depromeet.exception.BadRequestException;
import com.depromeet.friend.port.in.command.DeleteFollowCommand;
import com.depromeet.member.port.in.usecase.MemberUseCase;
import com.depromeet.type.blacklist.BlacklistErrorType;
import com.depromeet.type.member.MemberErrorType;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
Expand All @@ -19,6 +21,7 @@
@RequiredArgsConstructor
public class BlacklistFacade {
private final ApplicationEventPublisher eventPublisher;
private final MemberUseCase memberUseCase;
private final BlacklistQueryUseCase blacklistQueryUseCase;
private final BlacklistCommandUseCase blacklistCommandUseCase;

Expand All @@ -30,7 +33,9 @@ public void blackMember(Long memberId, BlackMemberRequest request) {
if (memberId.equals(blackMemberId)) {
throw new BadRequestException(BlacklistErrorType.CANNOT_BLACK_MYSELF);
}

if (!memberUseCase.existsByMemberId(blackMemberId)) {
throw new BadRequestException(MemberErrorType.NOT_FOUND);
}
boolean isAlreadyBlacked = blacklistQueryUseCase.checkBlackMember(memberId, blackMemberId);
if (isAlreadyBlacked) {
throw new BadRequestException(BlacklistErrorType.ALREADY_BLACKED);
Expand Down

0 comments on commit 307b505

Please sign in to comment.