Improve model validations

This commit is contained in:
2025-11-05 16:55:45 +01:00
parent a45525aab5
commit 6d1f2e00d9
2 changed files with 38 additions and 19 deletions

View File

@@ -1,13 +1,7 @@
package com.project.back_end.models; package com.project.back_end.models;
import jakarta.persistence.Entity; import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.EnumType; import jakarta.persistence.*;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Future; import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@@ -25,10 +19,12 @@ public class Appointment {
@NotNull @NotNull
@ManyToOne @ManyToOne
@JsonIgnore
private Doctor doctor; private Doctor doctor;
@NotNull @NotNull
@ManyToOne @ManyToOne
@JsonIgnore
private Patient patient; private Patient patient;
@NotNull @NotNull
@@ -76,18 +72,31 @@ public class Appointment {
return status; return status;
} }
@Transient
public LocalDateTime getEndTime() { public LocalDateTime getEndTime() {
return appointmentTime.plusHours(1); return appointmentTime.plusHours(1);
} }
@Transient
public LocalDate getAppointmentDate() { public LocalDate getAppointmentDate() {
return appointmentTime.toLocalDate(); return appointmentTime.toLocalDate();
} }
@Transient
public LocalTime getAppointmentTimeOnly() { public LocalTime getAppointmentTimeOnly() {
return appointmentTime.toLocalTime(); return appointmentTime.toLocalTime();
} }
@Transient
public String getDoctorName() {
return doctor.getName();
}
@Transient
public String getPatientName() {
return patient.getName();
}
public enum Status { public enum Status {
SCHEDULED, SCHEDULED,
COMPLETED, COMPLETED,

View File

@@ -1,5 +1,6 @@
package com.project.back_end.models; package com.project.back_end.models;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@@ -18,6 +19,7 @@ public class Doctor {
@NotNull @NotNull
@OneToOne @OneToOne
@JsonIgnore
private User user; private User user;
@NotNull @NotNull
@@ -30,11 +32,11 @@ public class Doctor {
@NotNull @NotNull
@Email @Email
private String email_address; private String emailAddress;
@NotNull @NotNull
@Pattern(regexp = "^[0-9]{10}$") @Pattern(regexp = "^[0-9]{10}$")
private String phone_number; private String phoneNumber;
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
private List<Appointment> appointments; private List<Appointment> appointments;
@@ -47,8 +49,8 @@ public class Doctor {
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY)
private List<UnavailabilitySchedule> unavailabilitySchedules; private List<UnavailabilitySchedule> unavailabilitySchedules;
@NotNull @NotNull
@JsonIgnore
private Boolean archived; private Boolean archived;
public Doctor() { public Doctor() {
@@ -72,20 +74,28 @@ public class Doctor {
this.specialization = specialization; this.specialization = specialization;
} }
public String getEmail_address() { public String getEmailAddress() {
return email_address; return emailAddress;
} }
public void setEmail_address(String email_address) { public void setEmailAddress(String emailAddress) {
this.email_address = email_address; this.emailAddress = emailAddress;
} }
public String getPhone_number() { public String getPhoneNumber() {
return phone_number; return phoneNumber;
} }
public void setPhone_number(String phone_number) { public String getName() {
this.phone_number = phone_number; return name;
}
public void setName(String name) {
this.name = name;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
} }
public List<Appointment> getAppointments() { public List<Appointment> getAppointments() {