-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbsence.java
More file actions
141 lines (114 loc) · 4.03 KB
/
Copy pathAbsence.java
File metadata and controls
141 lines (114 loc) · 4.03 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package ch.fhnw.timerecordingbackend.model;
import ch.fhnw.timerecordingbackend.model.enums.AbsenceStatus;
import ch.fhnw.timerecordingbackend.model.enums.AbsenceType;
import jakarta.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
/**
* Entität Klasse für Abwesenheiten
* @author PD
* Code von anderen Teammitgliedern oder Quellen wird durch einzelne Kommentare deklariert
* @version 1.0
*/
@Entity
@Table(name = "absences")
public class Absence {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(name = "start_date", nullable = false)
private LocalDate startDate;
@Column(name = "end_date", nullable = false)
private LocalDate endDate;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private AbsenceType type;
// Ersetze 'approved' und 'approver' durch 'status' und 'rejectionReason'
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private AbsenceStatus status = AbsenceStatus.PENDING; // Standardwert ist PENDING
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "approver_id")
private User approver;
@Column(name = "created_at")
private LocalDateTime createdAt;
@Column(name = "updated_at")
private LocalDateTime updatedAt;
// Konstruktoren
public Absence() {}
public Absence(User user, LocalDate startDate, LocalDate endDate, AbsenceType type) {
this.user = user;
this.startDate = startDate;
this.endDate = endDate;
this.type = type;
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}
/**
* Abwesenheit genehmigen
* @param approver
*/
public void approve(User approver) {
this.status = AbsenceStatus.APPROVED;
this.approver = approver;
this.updatedAt = LocalDateTime.now();
}
/**
* Abwesenheit ablehnen
*/
public void reject() {
this.status = AbsenceStatus.REJECTED;
this.approver = null;
}
/**
* Zeitstempel aktualisieren
*/
@PreUpdate
public void preUpdate() {
this.updatedAt = LocalDateTime.now();
}
/**
* Anzahl der Abwesenheitstage berechnen
* @return Anzahl der Tage
*/
public long getDurationInDays() {
if (startDate == null || endDate == null) {
return 0;
}
return ChronoUnit.DAYS.between(startDate, endDate) + 1;
}
// Getter und Setter
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public User getUser() { return user; }
public void setUser(User user) { this.user = user; }
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 AbsenceStatus getStatus() { return status; }
public void setStatus(AbsenceStatus status) { this.status = status; }
public User getApprover() { return approver; }
public void setApprover(User approver) { this.approver = approver; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
@Override
public String toString() {
return "Absence{" +
"id=" + id +
", user=" + user +
", startDate=" + startDate +
", endDate=" + endDate +
", type=" + type +
", status=" + status +
'}';
}
}