Ignore:
Timestamp:
03/03/24 20:25:20 (15 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
3ba01da
Parents:
e35d0e9
Message:

RetaurantServiceImpl problemi
isAvailable od tableEntity...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/rezevirajmasa/demo/bootstrap/TimeSlotManagementService.java

    re35d0e9 ra7d40aa  
    7979        return checkIns;
    8080    }
     81
     82    @PreDestroy
     83    public void cleanUpTimeSlots() {
     84        // Define the cutoff date (yesterday)
     85        LocalDate cutoffDate = LocalDate.now().minusDays(1);
     86
     87        // Iterate through all tables and remove unused time slots older than the cutoff date
     88        Iterable<TableEntity> tableEntities = tableRepository.findAll();
     89        for (TableEntity tableEntity : tableEntities) {
     90            // Remove unused time slots older than the cutoff date
     91            removeUnusedTimeSlots(tableEntity, cutoffDate);
     92            tableRepository.save(tableEntity);
     93        }
     94    }
     95
     96    private void removeUnusedTimeSlots(TableEntity tableEntity, LocalDate cutoffDate) {
     97        // Get all time slots for the table
     98        List<LocalDateTime> timeSlots = tableEntity.getTimeSlots();
     99
     100        // Remove unused time slots older than the cutoff date
     101        timeSlots.removeIf(timeSlot -> timeSlot.toLocalDate().isBefore(cutoffDate));
     102    }
    81103}
Note: See TracChangeset for help on using the changeset viewer.