Skip to content

Commit 7cceaae

Browse files
committed
fix: 탈퇴 유저 알림 및 FCM 처리 차단
1 parent 1359104 commit 7cceaae

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/com/semosan/api/domain/notification/service/FcmTokenService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.semosan.api.domain.notification.entity.FcmToken;
66
import com.semosan.api.domain.notification.repository.FcmTokenRepository;
77
import com.semosan.api.domain.user.enums.user.DeviceType;
8+
import com.semosan.api.domain.user.service.UserReader;
89
import lombok.RequiredArgsConstructor;
910
import lombok.extern.slf4j.Slf4j;
1011
import org.springframework.stereotype.Service;
@@ -16,13 +17,15 @@
1617
public class FcmTokenService {
1718

1819
private final FcmTokenRepository fcmTokenRepository;
20+
private final UserReader userReader;
1921

2022
/**
2123
* 토큰 등록
2224
* 같은 토큰이 이미 있으면 (다른 유저로 로그인 등) 소유자/디바이스 갱신
2325
*/
2426
@Transactional
2527
public void register(Long userId, String token, DeviceType deviceType) {
28+
userReader.findActiveUserById(userId);
2629
fcmTokenRepository.findByToken(token).ifPresentOrElse(
2730
existing -> existing.reassignTo(userId, deviceType),
2831
() -> fcmTokenRepository.save(FcmToken.create(userId, token, deviceType))
@@ -35,6 +38,7 @@ public void register(Long userId, String token, DeviceType deviceType) {
3538
*/
3639
@Transactional
3740
public void delete(Long userId, String token) {
41+
userReader.findActiveUserById(userId);
3842
fcmTokenRepository.findByToken(token).ifPresent(fcmToken -> {
3943
if (!fcmToken.getUserId().equals(userId)) {
4044
throw new GeneralException(ErrorStatus.FORBIDDEN);

src/main/java/com/semosan/api/domain/notification/service/NotificationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class NotificationService {
4343
*/
4444
@Transactional
4545
public void send(Long receiverId, NotificationType type, Map<String, Object> params) {
46-
if (!userRepository.existsById(receiverId)) {
46+
if (!userRepository.existsByIdAndDeletedFalse(receiverId)) {
4747
throw new GeneralException(ErrorStatus.USER_NOT_FOUND);
4848
}
4949

src/main/java/com/semosan/api/domain/user/repository/UserRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
1313
Optional<User> findByIdAndDeletedFalse(Long id);
1414

1515
boolean existsByNicknameAndDeletedFalse(String nickname);
16+
17+
boolean existsByIdAndDeletedFalse(Long id);
1618
}

0 commit comments

Comments
 (0)