add notification cleanup task

This commit is contained in:
2026-01-13 17:04:17 +01:00
parent bc3dd9b59b
commit 521a4ba957
5 changed files with 64 additions and 0 deletions
@@ -12,6 +12,7 @@ import SuMoC.backend.trend.dto.TrendDetectionDTO;
import SuMoC.backend.trend.services.StatTableUpdateService;
import SuMoC.backend.user.models.User;
import SuMoC.backend.user.repository.UserRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
@@ -123,6 +124,27 @@ public class DevController {
}
}
@Operation(description = "Tests the method cleaning old notifications from the database.")
@GetMapping("/test-clean-old-notifications")
public void testCleanOldNotifications() throws JsonProcessingException, InterruptedException {
User user = userRepository.findByEmail("user1@email.com").orElseThrow();
Notification notification = Notification.builder()
.type(NotificationType.TREND)
.data(objectMapper.writeValueAsString(TrendDetectionDTO.mockTrendDetectionDTO()))
.user(user)
.earliestTimeOfDayToSend(LocalTime.now())
.createdAt(LocalDateTime.now().minusDays(60))
.status(NotificationStatus.SENT)
.build();
notificationRepository.save(notification);
Thread.sleep(5000);
scheduledTasks.scheduleCleanUpOldNotifications();
}
@GetMapping("/test-meteo")
public void testMeteoClient() {
try {