-een gebruiker kan meerdere bedrijven hebben -manier van afspraken maken veranderd in de backend ivm meerdere bedrijven gebruiker -bedrijven van een gebruiker zijn op te roepen -gebruikers zijn aan een bestaand bedrijf te koppelen via een REST call -email is aangepast op bedrijf en gebruiker
115 lines
3.9 KiB
Java
115 lines
3.9 KiB
Java
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.AppUser;
|
|
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 nl.veenm.paypoint.repository.UserRepository;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
@ApplicationScoped
|
|
public class AppointmentService {
|
|
@Inject
|
|
AppointmentRepository appointmentRepository;
|
|
|
|
@Inject
|
|
UserRepository userRepository;
|
|
|
|
@Inject
|
|
CompanyRepository companyRepository;
|
|
|
|
@Inject
|
|
EmailService emailService;
|
|
|
|
|
|
public AppointmentService() {
|
|
}
|
|
|
|
@Transactional
|
|
public List<Appointment> getAllAppointments() {
|
|
return appointmentRepository.listAll();
|
|
}
|
|
|
|
@Transactional
|
|
public Appointment add(Appointment appointment, Long companyId, String username) {
|
|
Company company = companyRepository.findById(companyId);
|
|
AppUser user = userRepository.findByUsername(username);
|
|
appointment.setCompany(company);
|
|
appointmentRepository.persist(appointment);
|
|
emailService.stuurBevestiging(appointment, user);
|
|
return appointment;
|
|
}
|
|
|
|
@Transactional
|
|
public List<Appointment> getAppointmentsByDate(String start, String username) {
|
|
LocalDate date = LocalDate.parse(start);
|
|
AppUser user = userRepository.findByUsername(username);
|
|
|
|
|
|
LocalDateTime startOfDay = date.atStartOfDay();
|
|
LocalDateTime endOfDay = date.atTime(23, 59, 59);
|
|
|
|
return appointmentRepository.findAppointmentsForCompanies(user.getCompanies(), startOfDay, endOfDay);
|
|
}
|
|
|
|
@Transactional
|
|
public void delete(Long id) {
|
|
emailService.stuurVerwijdering(appointmentRepository.findById(id));
|
|
appointmentRepository.deleteById(id);
|
|
}
|
|
|
|
@Transactional
|
|
public Appointment 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);
|
|
return appointmentToUpdate;
|
|
}
|
|
|
|
@Transactional
|
|
public Appointment getAppointment(Long id) {
|
|
return appointmentRepository.findById(id);
|
|
}
|
|
|
|
@Transactional
|
|
@Scheduled(cron = "0 0 1 * * ?")
|
|
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(emailService::stuurHerinnering);
|
|
}
|
|
|
|
public Appointment getMostRecentByUserId(Long userId) {
|
|
return appointmentRepository.findMostRecentByUserId(userId).orElse(null);
|
|
}
|
|
|
|
public List<Appointment> getAppointmentsByCompany(Long companyId) {
|
|
Company company = companyRepository.findById(companyId);
|
|
return appointmentRepository.findMostRecentByCompanyId(company);
|
|
}
|
|
}
|