refactoring

This commit is contained in:
Matthias Engelien
2024-09-15 12:41:39 +02:00
parent c311564ecc
commit cbd6d373bb
5 changed files with 62 additions and 19 deletions

View File

@@ -11,13 +11,16 @@ import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.relational.core.mapping.Column;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@Data
@Accessors(fluent = true, chain = true)
public class Appointment {
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Appointment implements Comparable<Appointment>{
@Id
@EqualsAndHashCode.Include
private Long id;
@Column("GARAGE_ID")
@@ -26,12 +29,15 @@ public class Appointment {
@Column("SERVICE_ID")
private AggregateReference<MDService, Long> serviceId;
@EqualsAndHashCode.Include
private String serviceCode;
private String serviceName;
@EqualsAndHashCode.Include
private Date appointmentTime;
@EqualsAndHashCode.Include
private Integer slot = 1;
private Duration duration = Duration.ZERO;
@@ -45,4 +51,12 @@ public class Appointment {
public LocalDateTime appointmentEnd() {
return this.appointmentStart().plus(this.duration());
}
@Override
public int compareTo(Appointment o) {
if(o == null || o.appointmentTime() == null) return 1;
return this.appointmentTime().compareTo(o.appointmentTime());
}
}

View File

@@ -2,6 +2,7 @@ package de.etecture.ga.model;
import java.time.Duration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.data.annotation.Id;
@@ -40,6 +41,10 @@ public class Garage {
}
return this;
}
public List<Appointment> appointmentsSorted() {
return this.appointments.stream().sorted().toList();
}
public Garage addService(MDService service) {
garageServices.add(createGarageService(service, null));