Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rver into develop
  • Loading branch information
H-Yeji committed Nov 5, 2024
2 parents 8578884 + a23dd78 commit 470f3f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<SellerFcmToken, Long> {
List<SellerFcmToken> findAllBySeller(Seller seller);

Optional<SellerFcmToken> findByToken(String token);

Optional<SellerFcmToken> findBySellerAndToken(Seller seller, String fcmToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<FcmToken> fcmTokenOpt = fcmTokenRepository.findByToken(fcmTokenSaveRequest.fcmToken());
Optional<SellerFcmToken> 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) {
Expand All @@ -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<FcmToken> fcmTokens = fcmTokenRepository.findAllBySeller(seller);
List<SellerFcmToken> fcmTokens = sellerFcmTokenRepository.findAllBySeller(seller);

SellerNotification noti = SellerNotification.builder()
.title(title)
Expand All @@ -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()) {
Expand Down Expand Up @@ -127,11 +125,11 @@ public void consumeIssueNotification(String message /*listen 하면 스트링
@Transactional
public void deleteFcmToken(String fcmToken, Long sellerId) {
Seller seller = sellerRepository.findByIdOrThrow(sellerId);
Optional<FcmToken> fcmTokenOpt = fcmTokenRepository.findBySellerAndToken(seller, fcmToken);
Optional<SellerFcmToken> fcmTokenOpt = sellerFcmTokenRepository.findBySellerAndToken(seller, fcmToken);

if(fcmTokenOpt.isPresent()) {
FcmToken token = fcmTokenOpt.get();
fcmTokenRepository.delete(token);
SellerFcmToken token = fcmTokenOpt.get();
sellerFcmTokenRepository.delete(token);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 470f3f9

Please sign in to comment.