initial commit

This commit is contained in:
2025-03-04 21:21:35 +01:00
commit 882bc0f26b
34 changed files with 2442 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
package nl.veenm.paypoint.service;
import io.quarkus.scheduler.Scheduled;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import nl.veenm.paypoint.domain.Appointment;
import nl.veenm.paypoint.repository.AppointmentRepository;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class AppointmentService {
@Inject
AppointmentRepository appointmentRepository;
@Inject
EmailService emailService;
private List<Appointment> appointments;
public AppointmentService() {
LocalDateTime now = LocalDateTime.now();
appointments = new ArrayList<>();
appointments.add(new Appointment(1L, "Knippen Mel", "", now, 12, 0, 13, 0, 60));
appointments.add(new Appointment(2L, "Knippen Mel", "", now, 14, 0, 15, 0, 60));
}
@Transactional
public List<Appointment> getAllAppointments() {
return appointmentRepository.listAll();
}
@Transactional
public void add(Appointment appointment) {
// appointment.setStartDate(appointment.getStartDate().plusDays(1));
appointmentRepository.persist(appointment);
emailService.stuurBevestiging(appointment);
}
@Transactional
public List<Appointment> getAppointmentsByDate(String start) {
LocalDate date = LocalDate.parse(start);
LocalDateTime startOfDay = date.atStartOfDay(); // 00:00:00
LocalDateTime endOfDay = date.atTime(23, 59, 59); // 23:59:59
return appointmentRepository.find("startDate BETWEEN ?1 AND ?2", startOfDay, endOfDay).list();
}
@Transactional
public void delete(Long id) {
emailService.stuurVerwijdering(appointmentRepository.findById(id));
appointmentRepository.deleteById(id);
}
@Transactional
public void update(Appointment appointment) {
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
appointmentToUpdate.setTitle(appointment.getTitle());
appointmentToUpdate.setStartDate(appointment.getStartDate());
appointmentToUpdate.setDescription(appointment.getDescription());
appointmentToUpdate.setStartHour(appointment.getStartHour());
appointmentToUpdate.setStartMinute(appointment.getStartMinute());
appointmentToUpdate.setEndHour(appointment.getEndHour());
appointmentToUpdate.setEndMinute(appointment.getEndMinute());
appointmentToUpdate.setCustomer(appointment.getCustomer());
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
appointmentRepository.persist(appointmentToUpdate);
emailService.stuurBewerking(appointmentToUpdate);
}
@Transactional
public Appointment getAppointment(Long id) {
return appointmentRepository.findById(id);
}
@Transactional
@Scheduled(cron = "0 0 0 * * ?")
public void sendReminder() {
LocalDate date = LocalDate.now();
date = date.plusDays(1);
LocalDateTime startOfDay = date.atStartOfDay(); // 00:00:00
LocalDateTime endOfDay = date.atTime(23, 59, 59); // 23:59:59
List<Appointment> allAppointments = appointmentRepository.find("date BETWEEN ?1 AND ?2", startOfDay, endOfDay).list();
allAppointments.forEach(appointment -> {
emailService.stuurHerinnering(appointment);
});
}
public Appointment getMostRecentByUserId(Long userId) {
return appointmentRepository.findMostRecentByUserId(userId).orElse(null);
}
}