source: src/main/java/com/example/rezevirajmasa/demo/service/ReservationSchedulerService.java@ 8ca35dc

main
Last change on this file since 8ca35dc was 8ca35dc, checked in by Aleksandar Panovski <apano77@…>, 4 months ago

Done with stupid timeslots

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package com.example.rezevirajmasa.demo.service;
2
3import com.example.rezevirajmasa.demo.model.Reservation;
4import com.example.rezevirajmasa.demo.repository.ReservationRepository;
5import org.springframework.scheduling.annotation.Scheduled;
6import org.springframework.stereotype.Service;
7
8import java.time.LocalDateTime;
9import java.util.List;
10
11@Service
12public class ReservationSchedulerService {
13
14 private final ReservationRepository reservationRepository;
15 private final ReservationHistoryService reservationHistoryService;
16
17 public ReservationSchedulerService(
18 ReservationRepository reservationRepository,
19 ReservationHistoryService reservationHistoryService) {
20 this.reservationRepository = reservationRepository;
21 this.reservationHistoryService = reservationHistoryService;
22 }
23
24 @Scheduled(cron = "0 0 0 * * ?")
25 public void archivePastReservations() {
26 LocalDateTime now = LocalDateTime.now();
27 List<Reservation> pastReservations = reservationRepository.findAllByCheckInTimeBefore(now);
28
29 for (Reservation reservation : pastReservations) {
30 reservationHistoryService.moveReservationToHistory(reservation, "Past", null);
31 reservationRepository.delete(reservation);
32 }
33 }
34}
Note: See TracBrowser for help on using the repository browser.