-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbsenceRequest.java
More file actions
90 lines (71 loc) · 2.91 KB
/
Copy pathAbsenceRequest.java
File metadata and controls
90 lines (71 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package ch.fhnw.timerecordingbackend.dto.absence;
import ch.fhnw.timerecordingbackend.model.enums.AbsenceType;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
/**
* DTO Anfragen zum erstellen und aktualisieren von Abwesenheiten
* @author PD
* Code von anderen Teammitgliedern oder Quellen wird durch einzelne Kommentare deklariert
* @version 1.0
* Quelle: https://medium.com/paysafe-bulgaria/springboot-dto-validation-good-practices-and-breakdown-fee69277b3b0
*/
public class AbsenceRequest {
@NotNull(message = "Startdatum ist erforderlich")
private LocalDate startDate;
@NotNull(message = "Enddatum ist erforderlich")
private LocalDate endDate;
@NotNull(message = "Abwesenheitstyp ist erforderlich")
private AbsenceType type;
@Size(max = 1000, message = "Kommentar darf maximal 1000 Zeichen lang sein")
private String comment; // NEU! Optionales Kommentar-Feld
// Konstruktoren
public AbsenceRequest() {}
public AbsenceRequest(LocalDate startDate, LocalDate endDate, AbsenceType type) {
this.startDate = startDate;
this.endDate = endDate;
this.type = type;
}
public AbsenceRequest(LocalDate startDate, LocalDate endDate, AbsenceType type, String comment) {
this.startDate = startDate;
this.endDate = endDate;
this.type = type;
this.comment = comment;
}
// Getter und Setter
public LocalDate getStartDate() { return startDate; }
public void setStartDate(LocalDate startDate) { this.startDate = startDate; }
public LocalDate getEndDate() { return endDate; }
public void setEndDate(LocalDate endDate) { this.endDate = endDate; }
public AbsenceType getType() { return type; }
public void setType(AbsenceType type) { this.type = type; }
public String getComment() { return comment; }
public void setComment(String comment) { this.comment = comment; }
// Validierungsmethoden
public boolean isValidDateRange() {
if (startDate == null || endDate == null) {
return false;
}
return !endDate.isBefore(startDate);
}
public long getDurationInDays() {
if (startDate == null || endDate == null) {
return 0;
}
return java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1;
}
public boolean hasComment() {
return comment != null && !comment.trim().isEmpty();
}
@Override
public String toString() {
return "AbsenceRequest{" +
"startDate=" + startDate +
", endDate=" + endDate +
", type=" + type +
", comment='" + (comment != null ? comment.substring(0, Math.min(comment.length(), 50)) + "..." : "null") + '\'' +
", duration=" + getDurationInDays() + " days" +
'}';
}
}