refactoring betreft het datum object
All checks were successful
Docker Image CI / build-and-push (push) Successful in 11m23s
Docker Image CI / deploy (push) Successful in 25s
Docker Image CI / notify-failure (push) Has been skipped

This commit is contained in:
2025-05-25 18:05:45 +02:00
parent 69add9d8e3
commit 74bf3526ea
7 changed files with 91 additions and 128 deletions

View File

@@ -3,19 +3,17 @@ package nl.veenm.paypoint.domain;
import jakarta.persistence.*; import jakarta.persistence.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.UUID;
@Entity @Entity
public class Appointment { public class Appointment {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private Long id; private UUID id;
private String title; private String title;
private String description; private String description;
private LocalDateTime startDate; private LocalDateTime startDateTime;
private int startHour; private LocalDateTime endDateTime;
private int startMinute;
private int endHour;
private int endMinute;
private int durationInMinutes; private int durationInMinutes;
@ManyToOne @ManyToOne
@@ -24,27 +22,15 @@ public class Appointment {
@ManyToOne @ManyToOne
private Company company; private Company company;
public Appointment(Long id, String title, String description, LocalDateTime startDate, int startHour, int startMinute, int endHour, int endMinute, int durationInMinutes) {
this.id = id;
this.title = title;
this.description = description;
this.startDate = startDate;
this.startHour = startHour;
this.startMinute = startMinute;
this.endHour = endHour;
this.endMinute = endMinute;
this.durationInMinutes = durationInMinutes;
}
public Appointment() { public Appointment() {
} }
public Long getId() { public UUID getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
@@ -64,44 +50,12 @@ public class Appointment {
this.description = description; this.description = description;
} }
public LocalDateTime getStartDate() { public LocalDateTime getStartDateTime() {
return startDate; return startDateTime;
} }
public void setStartDate(LocalDateTime startDate) { public void setStartDateTime(LocalDateTime startDate) {
this.startDate = startDate; this.startDateTime = startDate;
}
public int getStartHour() {
return startHour;
}
public void setStartHour(int startHour) {
this.startHour = startHour;
}
public int getStartMinute() {
return startMinute;
}
public void setStartMinute(int startMinute) {
this.startMinute = startMinute;
}
public int getEndHour() {
return endHour;
}
public void setEndHour(int endHour) {
this.endHour = endHour;
}
public int getEndMinute() {
return endMinute;
}
public void setEndMinute(int endMinute) {
this.endMinute = endMinute;
} }
public int getDurationInMinutes() { public int getDurationInMinutes() {
@@ -124,6 +78,14 @@ public class Appointment {
return company; return company;
} }
public LocalDateTime getEndDateTime() {
return endDateTime;
}
public void setEndDateTime(LocalDateTime end) {
this.endDateTime = end;
}
public void setCompany(Company company) { public void setCompany(Company company) {
this.company = company; this.company = company;
} }
@@ -134,13 +96,11 @@ public class Appointment {
"id=" + id + "id=" + id +
", title='" + title + '\'' + ", title='" + title + '\'' +
", description='" + description + '\'' + ", description='" + description + '\'' +
", date=" + startDate + ", start=" + startDateTime +
", startHour=" + startHour + ", end=" + endDateTime +
", startMinute=" + startMinute +
", endHour=" + endHour +
", endMinute=" + endMinute +
", durationInMinutes=" + durationInMinutes + ", durationInMinutes=" + durationInMinutes +
", customer=" + customer + ", customer=" + customer +
", company=" + company +
'}'; '}';
} }
} }

View File

@@ -3,25 +3,23 @@ package nl.veenm.paypoint.domain.dto;
import nl.veenm.paypoint.domain.Customer; import nl.veenm.paypoint.domain.Customer;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.UUID;
public class AppointmentDTO { public class AppointmentDTO {
private Long id; private UUID id;
private String title; private String title;
private String description; private String description;
private LocalDateTime startDate; private LocalDateTime startDateTime;
private int startHour; private LocalDateTime endDateTime;
private int startMinute;
private int endHour;
private int endMinute;
private int durationInMinutes; private int durationInMinutes;
private Customer customer; private Customer customer;
private CompanyDTO company; private CompanyDTO company;
public Long getId() { public UUID getId() {
return id; return id;
} }
public void setId(Long id) { public void setId(UUID id) {
this.id = id; this.id = id;
} }
@@ -41,44 +39,20 @@ public class AppointmentDTO {
this.description = description; this.description = description;
} }
public LocalDateTime getStartDate() { public LocalDateTime getStartDateTime() {
return startDate; return startDateTime;
} }
public void setStartDate(LocalDateTime startDate) { public void setStartDateTime(LocalDateTime startDateTime) {
this.startDate = startDate; this.startDateTime = startDateTime;
} }
public int getStartHour() { public LocalDateTime getEndDateTime() {
return startHour; return endDateTime;
} }
public void setStartHour(int startHour) { public void setEndDateTime(LocalDateTime endDateTime) {
this.startHour = startHour; this.endDateTime = endDateTime;
}
public int getStartMinute() {
return startMinute;
}
public void setStartMinute(int startMinute) {
this.startMinute = startMinute;
}
public int getEndHour() {
return endHour;
}
public void setEndHour(int endHour) {
this.endHour = endHour;
}
public int getEndMinute() {
return endMinute;
}
public void setEndMinute(int endMinute) {
this.endMinute = endMinute;
} }
public int getDurationInMinutes() { public int getDurationInMinutes() {

View File

@@ -12,11 +12,8 @@ public class AppointmentMapper {
dto.setId(appointment.getId()); dto.setId(appointment.getId());
dto.setTitle(appointment.getTitle()); dto.setTitle(appointment.getTitle());
dto.setDescription(appointment.getDescription()); dto.setDescription(appointment.getDescription());
dto.setStartDate(appointment.getStartDate()); dto.setStartDateTime(appointment.getStartDateTime());
dto.setStartHour(appointment.getStartHour()); dto.setEndDateTime(appointment.getEndDateTime());
dto.setStartMinute(appointment.getStartMinute());
dto.setEndHour(appointment.getEndHour());
dto.setEndMinute(appointment.getEndMinute());
dto.setDurationInMinutes(appointment.getDurationInMinutes()); dto.setDurationInMinutes(appointment.getDurationInMinutes());
dto.setCustomer(appointment.getCustomer()); dto.setCustomer(appointment.getCustomer());
dto.setCompany(CompanyMapper.toDto(appointment.getCompany())); dto.setCompany(CompanyMapper.toDto(appointment.getCompany()));

View File

@@ -10,6 +10,7 @@ import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID;
@ApplicationScoped @ApplicationScoped
public class AppointmentRepository implements PanacheRepository<Appointment> { public class AppointmentRepository implements PanacheRepository<Appointment> {
@@ -22,12 +23,22 @@ public class AppointmentRepository implements PanacheRepository<Appointment> {
.firstResultOptional(); .firstResultOptional();
} }
public Appointment findByUUID(UUID uuid) {
return find("id = ?1", uuid).firstResult();
}
public List<Appointment> findMostRecentByCompanyId(Company company) { public List<Appointment> findMostRecentByCompanyId(Company company) {
return find("company = ?1", company).list(); return find("company = ?1", company).list();
} }
public List<Appointment> findAppointmentsForCompanies(Set<Long> companyIds, LocalDateTime startDate, LocalDateTime endDate) { public List<Appointment> findAppointmentsForCompaniesForDay(Set<Long> companyIds, LocalDateTime startDate, LocalDateTime endDate) {
return find("SELECT a FROM Appointment a WHERE a.company.id IN :companyIds AND a.startDate BETWEEN :start AND :end", return find("SELECT a FROM Appointment a WHERE a.company.id IN :companyIds AND a.startDateTime BETWEEN :start AND :end",
Parameters.with("companyIds", companyIds).and("start", startDate).and("end", endDate))
.list();
}
public List<Appointment> findAppointmentsForCompaniesForWeek(Set<Long> companyIds, LocalDateTime startDate, LocalDateTime endDate) {
return find("SELECT a FROM Appointment a WHERE a.company.id IN :companyIds AND a.startDateTime BETWEEN :start AND :end",
Parameters.with("companyIds", companyIds).and("start", startDate).and("end", endDate)) Parameters.with("companyIds", companyIds).and("start", startDate).and("end", endDate))
.list(); .list();
} }

View File

@@ -32,11 +32,19 @@ public class AppointmentResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("/date") @Path("/date")
public List<AppointmentDTO> getAppointmentsByDate(@QueryParam("start") String start) { public List<AppointmentDTO> getAppointmentsByDate(@QueryParam("start") String start) {
System.out.println("Getting appointments from " + start);
String user = jwt.getClaim("username"); String user = jwt.getClaim("username");
return appointmentService.getAppointmentsByDate(start, user); return appointmentService.getAppointmentsByDate(start, user);
} }
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/date/week")
public List<AppointmentDTO> getAppointmentsByDateWeek(@QueryParam("start") String start, @QueryParam("end") String end) {
String user = jwt.getClaim("username");
System.out.println("user: " + user);
return appointmentService.getAppointmentsByWeek(start, end, user);
}
//TODO: Deze werkend maken //TODO: Deze werkend maken
// @GET // @GET

View File

@@ -66,7 +66,23 @@ public class AppointmentService {
LocalDateTime startOfDay = date.atStartOfDay(); LocalDateTime startOfDay = date.atStartOfDay();
LocalDateTime endOfDay = date.atTime(23, 59, 59); LocalDateTime endOfDay = date.atTime(23, 59, 59);
List<Appointment> appointmentsForCompanies = appointmentRepository.findAppointmentsForCompanies(companies, startOfDay, endOfDay); List<Appointment> appointmentsForCompanies = appointmentRepository.findAppointmentsForCompaniesForDay(companies, startOfDay, endOfDay);
return appointmentsForCompanies.stream().map(AppointmentMapper::toDto).toList();
}
@Transactional
public List<AppointmentDTO> getAppointmentsByWeek(String start, String end, String username) {
LocalDate startDate = LocalDate.parse(start);
LocalDate endDate = LocalDate.parse(end);
AppUser user = userRepository.findByUsername(username);
AppUserDTO appUserDTO = AppUserMapper.toDTO(user);
Set<Long> companies = appUserDTO.getCompanies().stream().map(UserCompanyDTO::getCompany).map(CompanyDTO::getId).collect(Collectors.toSet());
LocalDateTime startOfStartDay = startDate.atStartOfDay();
LocalDateTime endOfEndDate = endDate.atTime(23, 59, 59);
List<Appointment> appointmentsForCompanies = appointmentRepository.findAppointmentsForCompaniesForWeek(companies, startOfStartDay, endOfEndDate);
System.out.println(appointmentsForCompanies.size());
return appointmentsForCompanies.stream().map(AppointmentMapper::toDto).toList(); return appointmentsForCompanies.stream().map(AppointmentMapper::toDto).toList();
} }
@@ -78,14 +94,11 @@ public class AppointmentService {
@Transactional @Transactional
public AppointmentDTO update(AppointmentDTO appointment) { public AppointmentDTO update(AppointmentDTO appointment) {
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId()); Appointment appointmentToUpdate = appointmentRepository.findByUUID(appointment.getId());
appointmentToUpdate.setTitle(appointment.getTitle()); appointmentToUpdate.setTitle(appointment.getTitle());
appointmentToUpdate.setStartDate(appointment.getStartDate()); appointmentToUpdate.setStartDateTime(appointment.getStartDateTime());
appointmentToUpdate.setEndDateTime(appointment.getEndDateTime());
appointmentToUpdate.setDescription(appointment.getDescription()); 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.setCustomer(appointment.getCustomer());
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes()); appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
appointmentRepository.persist(appointmentToUpdate); appointmentRepository.persist(appointmentToUpdate);

View File

@@ -30,14 +30,14 @@ public class EmailService {
Company company = appointment.getCompany(); Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity()); String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href(); String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl"))); String formattedDate = appointment.getStartDateTime().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()); String formattedHour = String.valueOf(appointment.getStartDateTime().getHour()).length() == 1 ? "0" + appointment.getStartDateTime().getHour() : String.valueOf(appointment.getStartDateTime().getHour());
String formattedMinute = String.valueOf(appointment.getStartMinute()).length() == 1 ? "0" + appointment.getStartMinute() : String.valueOf(appointment.getStartMinute()); String formattedMinute = String.valueOf(appointment.getStartDateTime().getMinute()).length() == 1 ? "0" + appointment.getStartDateTime().getMinute() : String.valueOf(appointment.getStartDateTime().getMinute());
String formattedTime = formattedHour + ":" + formattedMinute; String formattedTime = formattedHour + ":" + formattedMinute;
String formattedEndHour = String.valueOf(appointment.getEndHour()).length() == 1 ? "0" + appointment.getEndHour() : String.valueOf(appointment.getEndHour()); String formattedEndHour = String.valueOf(appointment.getEndDateTime().getHour()).length() == 1 ? "0" + appointment.getEndDateTime().getHour() : String.valueOf(appointment.getEndDateTime().getHour());
String formattedEndMinute = String.valueOf(appointment.getEndMinute()).length() == 1 ? "0" + appointment.getEndMinute() : String.valueOf(appointment.getEndMinute()); String formattedEndMinute = String.valueOf(appointment.getEndDateTime().getMinute()).length() == 1 ? "0" + appointment.getEndDateTime().getMinute() : String.valueOf(appointment.getEndDateTime().getMinute());
String formattedEndTime = formattedEndHour + ":" + formattedEndMinute; String formattedEndTime = formattedEndHour + ":" + formattedEndMinute;
// Bouw de HTML-inhoud van de e-mail // Bouw de HTML-inhoud van de e-mail
@@ -115,8 +115,8 @@ public class EmailService {
String subject = String.format(" Afspraak bevestigd: %s", formattedDate); String subject = String.format(" Afspraak bevestigd: %s", formattedDate);
String recipient = appointment.getCustomer().getEmail(); String recipient = appointment.getCustomer().getEmail();
LocalDateTime date = appointment.getStartDate(); LocalDateTime date = appointment.getStartDateTime();
date = date.withHour(appointment.getStartHour()).withMinute(appointment.getStartMinute()); date = date.withHour(appointment.getStartDateTime().getHour()).withMinute(appointment.getStartDateTime().getMinute());
String dtStamp = date.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")); String dtStamp = date.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
String sender = appointment.getCompany().getName() + " <paypoint@melvanveen.nl>"; String sender = appointment.getCompany().getName() + " <paypoint@melvanveen.nl>";
@@ -130,7 +130,7 @@ public class EmailService {
public void stuurVerwijdering(Appointment appointment) { public void stuurVerwijdering(Appointment appointment) {
Company company = appointment.getCompany(); Company company = appointment.getCompany();
String imageUrl = company.getImg_href(); String imageUrl = company.getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl"))); String formattedDate = appointment.getStartDateTime().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl")));
// Bouw de HTML-inhoud van de e-mail // Bouw de HTML-inhoud van de e-mail
String emailBody = """ String emailBody = """
@@ -211,9 +211,9 @@ public class EmailService {
Company company = appointment.getCompany(); Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity()); String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href(); String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl"))); String formattedDate = appointment.getStartDateTime().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()); String formattedTime = String.format("%s:%s", appointment.getStartDateTime().getHour(), String.valueOf(appointment.getStartDateTime().getMinute()).length() == 1 ? "0" + appointment.getStartDateTime().getMinute() : appointment.getStartDateTime().getMinute());
// Bouw de HTML-inhoud van de e-mail // Bouw de HTML-inhoud van de e-mail
@@ -299,9 +299,9 @@ public class EmailService {
Company company = appointment.getCompany(); Company company = appointment.getCompany();
String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity()); String location = String.format("<br>%s<br>%s %s", company.getAddress(), company.getPostal_code(), company.getCity());
String imageUrl = appointment.getCompany().getImg_href(); String imageUrl = appointment.getCompany().getImg_href();
String formattedDate = appointment.getStartDate().toLocalDate().format(DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.forLanguageTag("nl"))); String formattedDate = appointment.getStartDateTime().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()); String formattedTime = String.format("%s:%s", appointment.getStartDateTime().getHour(), String.valueOf(appointment.getStartDateTime().getMinute()).length() == 1 ? "0" + appointment.getStartDateTime().getMinute() : appointment.getStartDateTime().getMinute());
// Bouw de HTML-inhoud van de e-mail // Bouw de HTML-inhoud van de e-mail