Skip to content

Commit

Permalink
test: 알람 테스트4
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmondBreez3 committed Feb 6, 2024
1 parent 007d20a commit 637c5e9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@Getter
public class PopcornReviewResponse {
@Schema(defaultValue = "1", description = "PopcornUser id")
private Long popcornUserId;
@Schema(defaultValue = "1", description = "유저 id")
private Long userId;
@Schema(defaultValue = "닉네임", description = "유저 닉네임")
Expand All @@ -36,7 +38,8 @@ public class PopcornReviewResponse {
private LocalDateTime createdAt;

@Builder
public PopcornReviewResponse(Long userId, String nickName, int profileImgNum, Long popcornId, boolean hasWatched, boolean beforeScreening, boolean afterScreening, String review, boolean hasAgreed, LocalDateTime createdAt) {
public PopcornReviewResponse(Long popcornUserId,Long userId, String nickName, int profileImgNum, Long popcornId, boolean hasWatched, boolean beforeScreening, boolean afterScreening, String review, boolean hasAgreed, LocalDateTime createdAt) {
this.popcornUserId = popcornUserId;
this.userId=userId;
this.nickName=nickName;
this.profileImgNum=profileImgNum;
Expand All @@ -51,6 +54,7 @@ public PopcornReviewResponse(Long userId, String nickName, int profileImgNum, Lo

public static PopcornReviewResponse from(PopcornUser popcornUser) {
return PopcornReviewResponse.builder()
.popcornUserId(popcornUser.getId())
.userId(popcornUser.getUser().getId())
.nickName(popcornUser.getUser().getNickname())
.profileImgNum(popcornUser.getUser().getProfileImgNum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,67 @@ private void notifyReservation() {
}
}

@Scheduled(cron = "0 25 19 * * *")
private void notifyTestReservation() {
LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
LocalDateTime reservationTime = now.plusDays(1);

System.out.println("test");

//userScreening에서 isBookMarked인 것들 중에서 user id, screening id가져와서 List<User> List<Screening>
//screening에서 startDate가져와서 startDate가 내일이면 알람을 보낼 수 있게 짜봐 fcm이랑 스프링 쓰고 있어

List<UserScreening> bookmarkedUserScreenings = userScreeningAdaptor.findByBookMarked();

for (UserScreening userScreening : bookmarkedUserScreenings) {
LocalDateTime screeningStartDate = userScreening.getScreening().getScreeningStartDate();
// @Scheduled(cron = "0 0/1 * * * *")
// private void notifyTestReservation() {
// LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
// LocalDateTime reservationTime = now.plusDays(1);
//
// System.out.println("test");
//
// //userScreening에서 isBookMarked인 것들 중에서 user id, screening id가져와서 List<User> List<Screening>
// //screening에서 startDate가져와서 startDate가 내일이면 알람을 보낼 수 있게 짜봐 fcm이랑 스프링 쓰고 있어
//
// List<UserScreening> bookmarkedUserScreenings = userScreeningAdaptor.findByBookMarked();
//
// for (UserScreening userScreening : bookmarkedUserScreenings) {
// LocalDateTime screeningStartDate = userScreening.getScreening().getScreeningStartDate();
// Long userId = userScreening.getUser().getId();
// // 오늘이 screeningStartDate의 하루 전인 경우 해당 Screening을 가져옴
// if (screeningStartDate.toLocalDate().isEqual(ChronoLocalDate.from(reservationTime)) && checkFcmExists(userId)) {
// NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
// sendNotifications(notificationRequests);
//
// }
// }
// }
//

// 오늘이 screeningStartDate의 하루 전인 경우 해당 Screening을 가져옴
if (screeningStartDate.toLocalDate().isEqual(ChronoLocalDate.from(reservationTime))) {
Long userId = userScreening.getUser().getId();
if (checkFcmExists(userId)) {
NotificationRequest notificationRequests = new NotificationRequest(userScreening.getScreening(), userId, userScreening.getScreening().getTitle());
sendNotifications(notificationRequests);
}
}
}
}
// @Scheduled(cron = "0 0/1 * * * *")
// private void notifyTestReservation() {
// LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
// LocalDateTime reservationTime = now.plusDays(1);
//
// System.out.println("test");
//
// //userScreening에서 isBookMarked인 것들 중에서 user id, screening id가져와서 List<User> List<Screening>
// //screening에서 startDate가져와서 startDate가 내일이면 알람을 보낼 수 있게 짜봐 fcm이랑 스프링 쓰고 있어
// List<User> results = userRepository.findAll();
// for (User users : results) {
// Long userId = users.getId();
// // 오늘이 screeningStartDate의 하루 전인 경우 해당 Screening을 가져옴
// if (checkFcmExists(userId)) {
// NotificationRequest notificationRequests = new NotificationRequest(userId, "test");
// sendNotifications(notificationRequests);
//
// }
// }
// }

private boolean checkFcmExists(Long userId) {
if (fcmTokenAdaptor.findByUserId(userId)){
System.out.println(userId);
if (fcmRepository.findByUserId(userId).isPresent()){
System.out.println("test23 ");
return true;
} else {
System.out.println("false");
return false;
}
}


private void sendNotifications(NotificationRequest requests) {
// FCM을 사용하여 알림을 보내는 로직
System.out.println("test2");
fcmService.sendMessageByToken(requests);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public void execute(Long userId) {
fcmRepository.deleteByUserId(userId);
}

@Transactional
public boolean findByUserId(Long userId) {
return fcmRepository.existsById(userId);
return fcmRepository.existsByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface FcmRepository extends JpaRepository<FCMToken, Long> {


void deleteByUserId(Long userId);

boolean existsByUserId(Long userId);
}

0 comments on commit 637c5e9

Please sign in to comment.