refactoring betreft het datum object
This commit is contained in:
@@ -3,19 +3,17 @@ package nl.veenm.paypoint.domain;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class Appointment {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private UUID id;
|
||||
private String title;
|
||||
private String description;
|
||||
private LocalDateTime startDate;
|
||||
private int startHour;
|
||||
private int startMinute;
|
||||
private int endHour;
|
||||
private int endMinute;
|
||||
private LocalDateTime startDateTime;
|
||||
private LocalDateTime endDateTime;
|
||||
private int durationInMinutes;
|
||||
|
||||
@ManyToOne
|
||||
@@ -24,27 +22,15 @@ public class Appointment {
|
||||
@ManyToOne
|
||||
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 Long getId() {
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -64,44 +50,12 @@ public class Appointment {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartDate() {
|
||||
return startDate;
|
||||
public LocalDateTime getStartDateTime() {
|
||||
return startDateTime;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDateTime startDate) {
|
||||
this.startDate = 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 void setStartDateTime(LocalDateTime startDate) {
|
||||
this.startDateTime = startDate;
|
||||
}
|
||||
|
||||
public int getDurationInMinutes() {
|
||||
@@ -124,6 +78,14 @@ public class Appointment {
|
||||
return company;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndDateTime() {
|
||||
return endDateTime;
|
||||
}
|
||||
|
||||
public void setEndDateTime(LocalDateTime end) {
|
||||
this.endDateTime = end;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
@@ -134,13 +96,11 @@ public class Appointment {
|
||||
"id=" + id +
|
||||
", title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", date=" + startDate +
|
||||
", startHour=" + startHour +
|
||||
", startMinute=" + startMinute +
|
||||
", endHour=" + endHour +
|
||||
", endMinute=" + endMinute +
|
||||
", start=" + startDateTime +
|
||||
", end=" + endDateTime +
|
||||
", durationInMinutes=" + durationInMinutes +
|
||||
", customer=" + customer +
|
||||
", company=" + company +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,25 +3,23 @@ package nl.veenm.paypoint.domain.dto;
|
||||
import nl.veenm.paypoint.domain.Customer;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AppointmentDTO {
|
||||
private Long id;
|
||||
private UUID id;
|
||||
private String title;
|
||||
private String description;
|
||||
private LocalDateTime startDate;
|
||||
private int startHour;
|
||||
private int startMinute;
|
||||
private int endHour;
|
||||
private int endMinute;
|
||||
private LocalDateTime startDateTime;
|
||||
private LocalDateTime endDateTime;
|
||||
private int durationInMinutes;
|
||||
private Customer customer;
|
||||
private CompanyDTO company;
|
||||
|
||||
public Long getId() {
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -41,44 +39,20 @@ public class AppointmentDTO {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartDate() {
|
||||
return startDate;
|
||||
public LocalDateTime getStartDateTime() {
|
||||
return startDateTime;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDateTime startDate) {
|
||||
this.startDate = startDate;
|
||||
public void setStartDateTime(LocalDateTime startDateTime) {
|
||||
this.startDateTime = startDateTime;
|
||||
}
|
||||
|
||||
public int getStartHour() {
|
||||
return startHour;
|
||||
public LocalDateTime getEndDateTime() {
|
||||
return endDateTime;
|
||||
}
|
||||
|
||||
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 void setEndDateTime(LocalDateTime endDateTime) {
|
||||
this.endDateTime = endDateTime;
|
||||
}
|
||||
|
||||
public int getDurationInMinutes() {
|
||||
|
||||
@@ -12,11 +12,8 @@ public class AppointmentMapper {
|
||||
dto.setId(appointment.getId());
|
||||
dto.setTitle(appointment.getTitle());
|
||||
dto.setDescription(appointment.getDescription());
|
||||
dto.setStartDate(appointment.getStartDate());
|
||||
dto.setStartHour(appointment.getStartHour());
|
||||
dto.setStartMinute(appointment.getStartMinute());
|
||||
dto.setEndHour(appointment.getEndHour());
|
||||
dto.setEndMinute(appointment.getEndMinute());
|
||||
dto.setStartDateTime(appointment.getStartDateTime());
|
||||
dto.setEndDateTime(appointment.getEndDateTime());
|
||||
dto.setDurationInMinutes(appointment.getDurationInMinutes());
|
||||
dto.setCustomer(appointment.getCustomer());
|
||||
dto.setCompany(CompanyMapper.toDto(appointment.getCompany()));
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AppointmentRepository implements PanacheRepository<Appointment> {
|
||||
@@ -22,12 +23,22 @@ public class AppointmentRepository implements PanacheRepository<Appointment> {
|
||||
.firstResultOptional();
|
||||
}
|
||||
|
||||
public Appointment findByUUID(UUID uuid) {
|
||||
return find("id = ?1", uuid).firstResult();
|
||||
}
|
||||
|
||||
public List<Appointment> findMostRecentByCompanyId(Company company) {
|
||||
return find("company = ?1", company).list();
|
||||
}
|
||||
|
||||
public List<Appointment> findAppointmentsForCompanies(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",
|
||||
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.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))
|
||||
.list();
|
||||
}
|
||||
|
||||
@@ -32,11 +32,19 @@ public class AppointmentResource {
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("/date")
|
||||
public List<AppointmentDTO> getAppointmentsByDate(@QueryParam("start") String start) {
|
||||
System.out.println("Getting appointments from " + start);
|
||||
String user = jwt.getClaim("username");
|
||||
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
|
||||
|
||||
// @GET
|
||||
|
||||
@@ -66,7 +66,23 @@ public class AppointmentService {
|
||||
LocalDateTime startOfDay = date.atStartOfDay();
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -78,14 +94,11 @@ public class AppointmentService {
|
||||
|
||||
@Transactional
|
||||
public AppointmentDTO update(AppointmentDTO appointment) {
|
||||
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
|
||||
Appointment appointmentToUpdate = appointmentRepository.findByUUID(appointment.getId());
|
||||
appointmentToUpdate.setTitle(appointment.getTitle());
|
||||
appointmentToUpdate.setStartDate(appointment.getStartDate());
|
||||
appointmentToUpdate.setStartDateTime(appointment.getStartDateTime());
|
||||
appointmentToUpdate.setEndDateTime(appointment.getEndDateTime());
|
||||
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);
|
||||
|
||||
@@ -30,14 +30,14 @@ public class EmailService {
|
||||
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 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 formattedMinute = String.valueOf(appointment.getStartMinute()).length() == 1 ? "0" + appointment.getStartMinute() : String.valueOf(appointment.getStartMinute());
|
||||
String formattedHour = String.valueOf(appointment.getStartDateTime().getHour()).length() == 1 ? "0" + appointment.getStartDateTime().getHour() : String.valueOf(appointment.getStartDateTime().getHour());
|
||||
String formattedMinute = String.valueOf(appointment.getStartDateTime().getMinute()).length() == 1 ? "0" + appointment.getStartDateTime().getMinute() : String.valueOf(appointment.getStartDateTime().getMinute());
|
||||
String formattedTime = formattedHour + ":" + formattedMinute;
|
||||
|
||||
String formattedEndHour = String.valueOf(appointment.getEndHour()).length() == 1 ? "0" + appointment.getEndHour() : String.valueOf(appointment.getEndHour());
|
||||
String formattedEndMinute = String.valueOf(appointment.getEndMinute()).length() == 1 ? "0" + appointment.getEndMinute() : String.valueOf(appointment.getEndMinute());
|
||||
String formattedEndHour = String.valueOf(appointment.getEndDateTime().getHour()).length() == 1 ? "0" + appointment.getEndDateTime().getHour() : String.valueOf(appointment.getEndDateTime().getHour());
|
||||
String formattedEndMinute = String.valueOf(appointment.getEndDateTime().getMinute()).length() == 1 ? "0" + appointment.getEndDateTime().getMinute() : String.valueOf(appointment.getEndDateTime().getMinute());
|
||||
String formattedEndTime = formattedEndHour + ":" + formattedEndMinute;
|
||||
|
||||
// Bouw de HTML-inhoud van de e-mail
|
||||
@@ -115,8 +115,8 @@ public class EmailService {
|
||||
|
||||
String subject = String.format(" Afspraak bevestigd: %s", formattedDate);
|
||||
String recipient = appointment.getCustomer().getEmail();
|
||||
LocalDateTime date = appointment.getStartDate();
|
||||
date = date.withHour(appointment.getStartHour()).withMinute(appointment.getStartMinute());
|
||||
LocalDateTime date = appointment.getStartDateTime();
|
||||
date = date.withHour(appointment.getStartDateTime().getHour()).withMinute(appointment.getStartDateTime().getMinute());
|
||||
|
||||
String dtStamp = date.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
|
||||
String sender = appointment.getCompany().getName() + " <paypoint@melvanveen.nl>";
|
||||
@@ -130,7 +130,7 @@ public class EmailService {
|
||||
public void stuurVerwijdering(Appointment appointment) {
|
||||
Company company = appointment.getCompany();
|
||||
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
|
||||
String emailBody = """
|
||||
@@ -211,9 +211,9 @@ public class EmailService {
|
||||
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 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
|
||||
@@ -299,9 +299,9 @@ public class EmailService {
|
||||
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 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
|
||||
|
||||
Reference in New Issue
Block a user