Skip to content

Commit

Permalink
feat: 매일 15시 봉사자 이동봉사 가이드 알림 (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed May 19, 2024
1 parent e6404a8 commit 35aee0b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum NotificationType {

// 봉사자
REJECTED("반려 확인"), CONFIRMED("승인 확인"), COMPLETED("봉사 완료"), BADGE("배지 확득"),
GUIDE("이동봉사 시작하기"),

// 모집자
APPLICATION("신청 확인"), CANCELED("봉사 취소"), REVIEW_REGISTERED("후기 확인"), EXPIRED("모집 마감"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.pawwithu.connectdog.domain.notification.entity.NotificationType;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.repository.CustomPostRepository;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.CustomVolunteerRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
Expand All @@ -32,6 +34,7 @@ public class SchedulerService {
private final FcmService fcmService;
private final VolunteerFcmRepository volunteerFcmRepository;
private final IntermediaryFcmRepository intermediaryFcmRepository;
private final CustomVolunteerRepository customVolunteerRepository;

// 매일 00시 - 공고 모집 마감 업데이트, 신청 자동 반려
@Scheduled(cron = "0 0 0 * * *")
Expand Down Expand Up @@ -117,4 +120,21 @@ public void sendCompleteRequestNotification() {
}
}
}

// 매일 15시 - 이동봉사 가이드 알림
@Scheduled(cron = "0 0 15 * * *")
public void sendGuideNotification() {
LocalDate today = LocalDate.now();
LocalDate yesterday = today.minusDays(1);
List<Volunteer> volunteers = customVolunteerRepository.getYesterdaySignUpVolunteers(yesterday);
for (Volunteer volunteer : volunteers) {
VolunteerFcm volunteerFcm = volunteerFcmRepository.findByVolunteerId(volunteer.getId()).orElse(null);
if (volunteerFcm != null) {
fcmService.sendMessageToVolunteer(volunteerFcm.getFcmToken(), volunteer,
volunteer.getProfileImageNum() + "", NotificationType.GUIDE, GUIDE.getTitle(), GUIDE.getBody());
} else {
log.info("----------이동봉사 가이드 알림 전송 실패----------");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pawwithu.connectdog.domain.volunteer.repository;

import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;

import java.time.LocalDate;
import java.util.List;

public interface CustomVolunteerRepository {

List<Volunteer> getYesterdaySignUpVolunteers(LocalDate date);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.pawwithu.connectdog.domain.volunteer.repository.impl;

import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.CustomVolunteerRepository;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

import static com.pawwithu.connectdog.domain.volunteer.entity.QVolunteer.volunteer;

@Repository
@RequiredArgsConstructor
@Slf4j
public class CustomVolunteerRepositoryImpl implements CustomVolunteerRepository {

private final JPAQueryFactory queryFactory;

@Override
public List<Volunteer> getYesterdaySignUpVolunteers(LocalDate date) {
LocalDateTime startOfDay = date.atStartOfDay();
LocalDateTime endOfDay = date.atTime(LocalTime.MAX);
return queryFactory.selectFrom(volunteer)
.where(volunteer.createdDate.between(startOfDay, endOfDay))
.fetch();
}
}

0 comments on commit 35aee0b

Please sign in to comment.