source: src/main/java/finki/it/terapijamkbackend/spring/services/CleanupService.java

Last change on this file was 743de55, checked in by macagaso <gasoskamarija@…>, 6 weeks ago

Initial commit

  • Property mode set to 100644
File size: 974 bytes
Line 
1package finki.it.terapijamkbackend.spring.services;
2
3import finki.it.terapijamkbackend.spring.repositories.AppointmentRepository;
4import finki.it.terapijamkbackend.spring.repositories.RequestRepository;
5import jakarta.transaction.Transactional;
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.scheduling.annotation.Scheduled;
8import org.springframework.stereotype.Service;
9
10import java.time.LocalDateTime;
11
12@Service
13public class CleanupService {
14 @Autowired
15 private AppointmentRepository appointmentRepository;
16 @Autowired
17 private RequestRepository requestRepository;
18
19 @Scheduled(cron = "0 20 14 * * ?")
20 @Transactional
21 public void cleanupOldAppointmentsAndRequests() {
22 LocalDateTime now = LocalDateTime.now();
23 appointmentRepository.deleteByAppointmentDateBefore(now);
24 requestRepository.deleteByTermBefore(now.minusDays(1));
25 System.out.println("Cleanup completed!");
26 }
27}
Note: See TracBrowser for help on using the repository browser.