various functionality added

This commit is contained in:
2025-03-11 23:15:15 +01:00
parent 3f769df850
commit acd957f0da
13 changed files with 188 additions and 42 deletions

View File

@@ -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);
}
}

View File

@@ -4,6 +4,7 @@ import io.quarkus.mailer.Mail;
import io.quarkus.mailer.Mailer;
import jakarta.enterprise.context.ApplicationScoped;
import nl.veenm.paypoint.domain.Appointment;
import nl.veenm.paypoint.domain.Company;
import nl.veenm.paypoint.helper.EmailHelper;
import java.time.LocalDateTime;
@@ -20,9 +21,9 @@ public class EmailService {
}
public void stuurBevestiging(Appointment appointment) {
String location = "<br>Groenestraat 29<br>6681DW Bemmel";
String imageUrl = "https://hairstylingbydaan.nl/assets/img/Logo.png";
Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl")));
String formattedHour = String.valueOf(appointment.getStartHour()).length() == 1 ? "0" + appointment.getStartHour() : String.valueOf(appointment.getStartHour());
@@ -115,15 +116,15 @@ public class EmailService {
mailer.send(Mail.withHtml(recipient, subject, emailBody)
.setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>")
.setReplyTo(company.getEmail())
.addAttachment("afspraak.ics", EmailHelper.getIcs(dtStamp, date.toLocalDate(), formattedTime, formattedEndTime, location).getBytes(), "text/calendar"));
}
public void stuurVerwijdering(Appointment appointment) {
String imageUrl = "https://hairstylingbydaan.nl/assets/img/Logo.png";
Company company = appointment.getCompany();
String imageUrl = company.getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl")));
// Bouw de HTML-inhoud van de e-mail
String emailBody = """
<!DOCTYPE html>
@@ -200,9 +201,9 @@ public class EmailService {
}
public void stuurBewerking(Appointment appointment) {
String location = "<br>Groenestraat 29<br>6681DW Bemmel";
String imageUrl = "https://hairstylingbydaan.nl/assets/img/Logo.png";
Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl")));
String formattedTime = String.format("%s:%s", appointment.getStartHour(), String.valueOf(appointment.getStartMinute()).length() == 1 ? "0" + appointment.getStartMinute() : appointment.getStartMinute());
@@ -284,13 +285,13 @@ public class EmailService {
String subject = String.format(" Afspraak gewijzigd: %s", formattedDate);
String recipient = appointment.getCustomer().getEmail();
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>"));
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom(company.getEmail()));
}
public void stuurHerinnering(Appointment appointment) {
String location = "<br>Groenestraat 29<br>6681DW Bemmel";
String imageUrl = "https://hairstylingbydaan.nl/assets/img/Logo.png";
Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl")));
String formattedTime = String.format("%s:%s", appointment.getStartHour(), String.valueOf(appointment.getStartMinute()).length() == 1 ? "0" + appointment.getStartMinute() : appointment.getStartMinute());
@@ -372,7 +373,7 @@ public class EmailService {
String subject = String.format("Herinnering afspraak: %s", formattedDate);
String recipient = appointment.getCustomer().getEmail();
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>"));
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>").setReplyTo(company.getEmail()));
}
}

View File

@@ -18,6 +18,7 @@ public class TokenService {
.claim("lastName", appUser.getLastName())
.claim("email", appUser.getEmail())
.claim("groups", appUser.getRole())
.claim("company_id", appUser.getCompany().getId())
.sign();
}
}