various functionality added
This commit is contained in:
@@ -5,11 +5,12 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import nl.veenm.paypoint.domain.Appointment;
|
||||
import nl.veenm.paypoint.domain.Company;
|
||||
import nl.veenm.paypoint.repository.AppointmentRepository;
|
||||
import nl.veenm.paypoint.repository.CompanyRepository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApplicationScoped
|
||||
@@ -17,16 +18,14 @@ public class AppointmentService {
|
||||
@Inject
|
||||
AppointmentRepository appointmentRepository;
|
||||
|
||||
@Inject
|
||||
CompanyRepository companyRepository;
|
||||
|
||||
@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
|
||||
@@ -35,20 +34,22 @@ public class AppointmentService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void add(Appointment appointment) {
|
||||
// appointment.setStartDate(appointment.getStartDate().plusDays(1));
|
||||
public void add(Appointment appointment, Long companyId) {
|
||||
Company company = companyRepository.findById(companyId);
|
||||
appointment.setCompany(company);
|
||||
appointmentRepository.persist(appointment);
|
||||
emailService.stuurBevestiging(appointment);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Appointment> getAppointmentsByDate(String start) {
|
||||
public List<Appointment> getAppointmentsByDate(String start, Long companyId) {
|
||||
LocalDate date = LocalDate.parse(start);
|
||||
Company company = companyRepository.findById(companyId);
|
||||
|
||||
LocalDateTime startOfDay = date.atStartOfDay(); // 00:00:00
|
||||
LocalDateTime endOfDay = date.atTime(23, 59, 59); // 23:59:59
|
||||
LocalDateTime startOfDay = date.atStartOfDay();
|
||||
LocalDateTime endOfDay = date.atTime(23, 59, 59);
|
||||
|
||||
return appointmentRepository.find("startDate BETWEEN ?1 AND ?2", startOfDay, endOfDay).list();
|
||||
return appointmentRepository.find("startDate BETWEEN ?1 AND ?2 AND company = ?3", startOfDay, endOfDay, company).list();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -79,7 +80,7 @@ public class AppointmentService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Scheduled(cron = "0 0 0 * * ?")
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void sendReminder() {
|
||||
LocalDate date = LocalDate.now();
|
||||
date = date.plusDays(1);
|
||||
@@ -99,4 +100,8 @@ public class AppointmentService {
|
||||
return appointmentRepository.findMostRecentByUserId(userId).orElse(null);
|
||||
}
|
||||
|
||||
public List<Appointment> getAppointmentsByCompany(Long companyId) {
|
||||
Company company = companyRepository.findById(companyId);
|
||||
return appointmentRepository.findMostRecentByCompanyId(company);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user