diff --git a/backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/FcmToken.java b/backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/SellerFcmToken.java similarity index 92% rename from backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/FcmToken.java rename to backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/SellerFcmToken.java index 9e730f3c..2e7f8238 100644 --- a/backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/FcmToken.java +++ b/backend/product/src/main/java/org/samtuap/inong/domain/notification/entity/SellerFcmToken.java @@ -13,7 +13,7 @@ @NoArgsConstructor @Getter @Entity -public class FcmToken extends BaseEntity { +public class SellerFcmToken extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; diff --git a/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/FcmTokenRepository.java b/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/FcmTokenRepository.java deleted file mode 100644 index f115b50b..00000000 --- a/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/FcmTokenRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.samtuap.inong.domain.notification.repository; - -import org.samtuap.inong.domain.notification.entity.FcmToken; -import org.samtuap.inong.domain.seller.entity.Seller; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; -import java.util.Optional; - -public interface FcmTokenRepository extends JpaRepository { - List findAllBySeller(Seller seller); - - Optional findByToken(String token); - - Optional findBySellerAndToken(Seller seller, String fcmToken); -} diff --git a/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/SellerFcmTokenRepository.java b/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/SellerFcmTokenRepository.java new file mode 100644 index 00000000..78eb3d13 --- /dev/null +++ b/backend/product/src/main/java/org/samtuap/inong/domain/notification/repository/SellerFcmTokenRepository.java @@ -0,0 +1,16 @@ +package org.samtuap.inong.domain.notification.repository; + +import org.samtuap.inong.domain.notification.entity.SellerFcmToken; +import org.samtuap.inong.domain.seller.entity.Seller; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface SellerFcmTokenRepository extends JpaRepository { + List findAllBySeller(Seller seller); + + Optional findByToken(String token); + + Optional findBySellerAndToken(Seller seller, String fcmToken); +} diff --git a/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java b/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java index 39c78c4f..00128fde 100644 --- a/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java +++ b/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/FcmService.java @@ -14,9 +14,9 @@ import org.samtuap.inong.domain.notification.dto.FcmTokenSaveRequest; import org.samtuap.inong.domain.notification.dto.KafkaNotificationRequest; import org.samtuap.inong.domain.notification.dto.NotificationIssueRequest; -import org.samtuap.inong.domain.notification.entity.FcmToken; +import org.samtuap.inong.domain.notification.entity.SellerFcmToken; import org.samtuap.inong.domain.notification.entity.SellerNotification; -import org.samtuap.inong.domain.notification.repository.FcmTokenRepository; +import org.samtuap.inong.domain.notification.repository.SellerFcmTokenRepository; import org.samtuap.inong.domain.notification.repository.SellerNotificationRepository; import org.samtuap.inong.domain.seller.entity.Seller; import org.samtuap.inong.domain.seller.repository.SellerRepository; @@ -34,24 +34,24 @@ @Service public class FcmService { private final SellerRepository sellerRepository; - private final FcmTokenRepository fcmTokenRepository; + private final SellerFcmTokenRepository sellerFcmTokenRepository; private final FarmRepository farmRepository; private final SellerNotificationRepository sellerNotificationRepository; @Transactional public void saveFcmToken(Long memberId, FcmTokenSaveRequest fcmTokenSaveRequest) { Seller seller = sellerRepository.findByIdOrThrow(memberId); - Optional fcmTokenOpt = fcmTokenRepository.findByToken(fcmTokenSaveRequest.fcmToken()); + Optional fcmTokenOpt = sellerFcmTokenRepository.findByToken(fcmTokenSaveRequest.fcmToken()); if(fcmTokenOpt.isPresent()) { // 이미 저장돼 있는 경우 return; } - FcmToken fcmToken = FcmToken.builder() + SellerFcmToken fcmToken = SellerFcmToken.builder() .token(fcmTokenSaveRequest.fcmToken()) .seller(seller).build(); - fcmTokenRepository.save(fcmToken); + sellerFcmTokenRepository.save(fcmToken); } public void issueNotice(NotificationIssueRequest notiRequest) { @@ -62,10 +62,8 @@ public void issueNotice(NotificationIssueRequest notiRequest) { } protected void issueMessage(Long sellerId, String title, String content, String url) { - - log.info("line 66 >>> issueMessage, {}, {}, {}, {}", sellerId, title, content, url); Seller seller = sellerRepository.findByIdOrThrow(sellerId); - List fcmTokens = fcmTokenRepository.findAllBySeller(seller); + List fcmTokens = sellerFcmTokenRepository.findAllBySeller(seller); SellerNotification noti = SellerNotification.builder() .title(title) @@ -77,7 +75,7 @@ protected void issueMessage(Long sellerId, String title, String content, String sellerNotificationRepository.save(noti); - for (FcmToken fcmToken : fcmTokens) { + for (SellerFcmToken fcmToken : fcmTokens) { String token = fcmToken.getToken(); if(token == null || token.isEmpty()) { @@ -127,11 +125,11 @@ public void consumeIssueNotification(String message /*listen 하면 스트링 @Transactional public void deleteFcmToken(String fcmToken, Long sellerId) { Seller seller = sellerRepository.findByIdOrThrow(sellerId); - Optional fcmTokenOpt = fcmTokenRepository.findBySellerAndToken(seller, fcmToken); + Optional fcmTokenOpt = sellerFcmTokenRepository.findBySellerAndToken(seller, fcmToken); if(fcmTokenOpt.isPresent()) { - FcmToken token = fcmTokenOpt.get(); - fcmTokenRepository.delete(token); + SellerFcmToken token = fcmTokenOpt.get(); + sellerFcmTokenRepository.delete(token); } } } diff --git a/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/NotificationService.java b/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/NotificationService.java index a1b3817d..714139dd 100644 --- a/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/NotificationService.java +++ b/backend/product/src/main/java/org/samtuap/inong/domain/notification/service/NotificationService.java @@ -54,7 +54,7 @@ public void notifyTodayDelivery() { Long todayCount = orderFeign.getDeliveryCountByFarmId(farm.getId(), LocalDate.now().toString()); Long tomorrowCount = orderFeign.getDeliveryCountByFarmId(farm.getId(), LocalDate.now().plusDays(1).toString()); - if(todayCount == 0L || tomorrowCount == 0L) { + if(todayCount == 0L && tomorrowCount == 0L) { continue; }