Skip to content

Commit

Permalink
refactor: 탈퇴 시 fcm token 데이터 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
char-yb committed Oct 16, 2024
1 parent 41ecda6 commit c487b2d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.depromeet.stonebed.domain.auth.dto.response.SocialClientResponse;
import com.depromeet.stonebed.domain.auth.dto.response.TokenPairResponse;
import com.depromeet.stonebed.domain.fcm.dao.FcmNotificationRepository;
import com.depromeet.stonebed.domain.fcm.dao.FcmTokenRepository;
import com.depromeet.stonebed.domain.member.dao.MemberRepository;
import com.depromeet.stonebed.domain.member.domain.Member;
import com.depromeet.stonebed.domain.member.domain.MemberRole;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class AuthService {
private final MemberRepository memberRepository;
private final MissionRecordRepository missionRecordRepository;
private final MissionRecordBoostRepository missionRecordBoostRepository;
private final FcmTokenRepository fcmTokenRepository;

private final AppleClient appleClient;
private final KakaoClient kakaoClient;
Expand Down Expand Up @@ -179,5 +181,6 @@ private void withdrawMemberRelationByMemberId(List<Long> recordIds, Long memberI
missionRecordBoostRepository.deleteAllByMember(recordIds);
missionRecordRepository.deleteAllByMember(memberId);
fcmNotificationRepository.deleteAllByMember(memberId);
fcmTokenRepository.deleteAllByMember(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void sendAndNotifications(
Long sourceId,
Long targetId,
FcmNotificationType notificationType) {
List<List<String>> batches = createBatches(tokens, BATCH_SIZE);
List<List<String>> batches = createBatches(tokens);

String deepLink = FcmNotification.generateDeepLink(notificationType, targetId, null);

Expand All @@ -295,13 +295,18 @@ public void sendAndNotifications(
notificationRepository.saveAll(notifications);
}

private List<List<String>> createBatches(List<String> tokens, int batchSize) {
return IntStream.range(0, (tokens.size() + batchSize - 1) / batchSize)
private List<List<String>> createBatches(List<String> tokens) {
return IntStream.range(
0,
(tokens.size() + FcmNotificationService.BATCH_SIZE - 1)
/ FcmNotificationService.BATCH_SIZE)
.mapToObj(
i ->
tokens.subList(
i * batchSize,
Math.min(tokens.size(), (i + 1) * batchSize)))
i * FcmNotificationService.BATCH_SIZE,
Math.min(
tokens.size(),
(i + 1) * FcmNotificationService.BATCH_SIZE)))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface FcmTokenRepository
extends JpaRepository<FcmToken, Long>, FcmTokenRepositoryCustom {
Expand All @@ -19,4 +21,9 @@ public interface FcmTokenRepository
List<FcmToken> findAllByUpdatedAtBefore(LocalDateTime cutoffDate);

void deleteByToken(String token);

// Delete
@Modifying
@Query("DELETE FROM FcmToken ft WHERE ft.member.id = :memberId")
void deleteAllByMember(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.depromeet.stonebed.domain.auth.dto.response.AuthTokenResponse;
import com.depromeet.stonebed.domain.auth.dto.response.TokenPairResponse;
import com.depromeet.stonebed.domain.fcm.dao.FcmNotificationRepository;
import com.depromeet.stonebed.domain.fcm.dao.FcmTokenRepository;
import com.depromeet.stonebed.domain.member.dao.MemberRepository;
import com.depromeet.stonebed.domain.member.domain.Member;
import com.depromeet.stonebed.domain.member.domain.MemberRole;
Expand Down Expand Up @@ -38,6 +39,7 @@ class AuthServiceTest extends FixtureMonkeySetUp {
@Mock private FcmNotificationRepository fcmNotificationRepository;
@Mock private MissionRecordRepository missionRecordRepository;
@Mock private MissionRecordBoostRepository missionRecordBoostRepository;
@Mock private FcmTokenRepository fcmTokenRepository;

@Mock private MemberUtil memberUtil;

Expand Down

0 comments on commit c487b2d

Please sign in to comment.