Skip to content

Commit cc9e6d7

Browse files
committed
Modified
1 parent df0e23f commit cc9e6d7

File tree

11 files changed

+521
-257
lines changed

11 files changed

+521
-257
lines changed

app/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.idea/compiler.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.idea/misc.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,60 @@
11
package com.project.back_end.models;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import jakarta.persistence.*;
5+
import jakarta.validation.constraints.NotNull;
6+
7+
@Entity
8+
@Table(name = "admins")
39
public class Admin {
410

5-
// @Entity annotation:
6-
// - Marks the class as a JPA entity, which means it represents a table in the database.
7-
// - It is required for persistence frameworks like Hibernate to map the class to a database table.
8-
9-
// 1. 'id' field:
10-
// - Type: private Long
11-
// - Description:
12-
// - Represents the unique identifier for the Admin entity.
13-
// - This field is auto-generated by the database using @GeneratedValue with strategy GenerationType.IDENTITY.
14-
// - It is the primary key of the entity, identified by @Id annotation.
15-
16-
// 2. 'username' field:
17-
// - Type: private String
18-
// - Description:
19-
// - Represents the username of the admin.
20-
// - Used to log into the system.
21-
// - @NotNull validation ensures that this field cannot be null when creating or updating an Admin.
22-
23-
// 3. 'password' field:
24-
// - Type: private String
25-
// - Description:
26-
// - Represents the password of the admin for authentication.
27-
// - The field is marked with @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) to prevent the password from being exposed in JSON responses.
28-
// - @NotNull validation ensures the password cannot be null when creating or updating an Admin.
29-
30-
// 4. Constructor(s):
31-
// - A no-argument constructor is implicitly provided, required by JPA for entity creation.
32-
// - A parameterized constructor can be added as needed.
33-
34-
// 5. Getters and Setters:
35-
// - Standard getter and setter methods are provided for accessing and modifying the fields.
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.IDENTITY)
13+
private Long id;
14+
15+
@NotNull(message = "Username cannot be null")
16+
@Column(nullable = false, unique = true)
17+
private String username;
18+
19+
@NotNull(message = "Password cannot be null")
20+
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
21+
@Column(nullable = false)
22+
private String password;
23+
24+
// Default constructor required by JPA
25+
public Admin() {
26+
}
27+
28+
// Parameterized constructor for convenience
29+
public Admin(String username, String password) {
30+
this.username = username;
31+
this.password = password;
32+
}
33+
34+
// Getters and Setters
3635

36+
public Long getId() {
37+
return id;
38+
}
39+
40+
public void setId(Long id) {
41+
this.id = id;
42+
}
43+
44+
public String getUsername() {
45+
return username;
46+
}
47+
48+
public void setUsername(String username) {
49+
this.username = username;
50+
}
51+
52+
public String getPassword() {
53+
return password;
54+
}
55+
56+
public void setPassword(String password) {
57+
this.password = password;
58+
}
3759
}
60+
Lines changed: 102 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,109 @@
11
package com.project.back_end.models;
22

3+
import jakarta.persistence.*;
4+
import jakarta.validation.constraints.Future;
5+
import jakarta.validation.constraints.NotNull;
6+
7+
import java.time.LocalDate;
8+
import java.time.LocalDateTime;
9+
import java.time.LocalTime;
10+
11+
@Entity
12+
@Table(name = "appointments")
313
public class Appointment {
414

5-
// @Entity annotation:
6-
// - Marks the class as a JPA entity, meaning it represents a table in the database.
7-
// - Required for persistence frameworks (e.g., Hibernate) to map the class to a database table.
8-
9-
// 1. 'id' field:
10-
// - Type: private Long
11-
// - Description:
12-
// - Represents the unique identifier for each appointment.
13-
// - The @Id annotation marks it as the primary key.
14-
// - The @GeneratedValue(strategy = GenerationType.IDENTITY) annotation auto-generates the ID value when a new record is inserted into the database.
15-
16-
// 2. 'doctor' field:
17-
// - Type: private Doctor
18-
// - Description:
19-
// - Represents the doctor assigned to this appointment.
20-
// - The @ManyToOne annotation defines the relationship, indicating many appointments can be linked to one doctor.
21-
// - The @NotNull annotation ensures that an appointment must be associated with a doctor when created.
22-
23-
// 3. 'patient' field:
24-
// - Type: private Patient
25-
// - Description:
26-
// - Represents the patient assigned to this appointment.
27-
// - The @ManyToOne annotation defines the relationship, indicating many appointments can be linked to one patient.
28-
// - The @NotNull annotation ensures that an appointment must be associated with a patient when created.
29-
30-
// 4. 'appointmentTime' field:
31-
// - Type: private LocalDateTime
32-
// - Description:
33-
// - Represents the date and time when the appointment is scheduled to occur.
34-
// - The @Future annotation ensures that the appointment time is always in the future when the appointment is created.
35-
// - It uses LocalDateTime, which includes both the date and time for the appointment.
36-
37-
// 5. 'status' field:
38-
// - Type: private int
39-
// - Description:
40-
// - Represents the current status of the appointment. It is an integer where:
41-
// - 0 means the appointment is scheduled.
42-
// - 1 means the appointment has been completed.
43-
// - The @NotNull annotation ensures that the status field is not null.
44-
45-
// 6. 'getEndTime' method:
46-
// - Type: private LocalDateTime
47-
// - Description:
48-
// - This method is a transient field (not persisted in the database).
49-
// - It calculates the end time of the appointment by adding one hour to the start time (appointmentTime).
50-
// - It is used to get an estimated appointment end time for display purposes.
51-
52-
// 7. 'getAppointmentDate' method:
53-
// - Type: private LocalDate
54-
// - Description:
55-
// - This method extracts only the date part from the appointmentTime field.
56-
// - It returns a LocalDate object representing just the date (without the time) of the scheduled appointment.
57-
58-
// 8. 'getAppointmentTimeOnly' method:
59-
// - Type: private LocalTime
60-
// - Description:
61-
// - This method extracts only the time part from the appointmentTime field.
62-
// - It returns a LocalTime object representing just the time (without the date) of the scheduled appointment.
63-
64-
// 9. Constructor(s):
65-
// - A no-argument constructor is implicitly provided by JPA for entity creation.
66-
// - A parameterized constructor can be added as needed to initialize fields.
67-
68-
// 10. Getters and Setters:
69-
// - Standard getter and setter methods are provided for accessing and modifying the fields: id, doctor, patient, appointmentTime, status, etc.
15+
@Id
16+
@GeneratedValue(strategy = GenerationType.IDENTITY)
17+
private Long id;
18+
19+
@NotNull(message = "Doctor must be assigned")
20+
@ManyToOne(fetch = FetchType.LAZY)
21+
@JoinColumn(name = "doctor_id", nullable = false)
22+
private Doctor doctor;
23+
24+
@NotNull(message = "Patient must be assigned")
25+
@ManyToOne(fetch = FetchType.LAZY)
26+
@JoinColumn(name = "patient_id", nullable = false)
27+
private Patient patient;
28+
29+
@NotNull(message = "Appointment time must be provided")
30+
@Future(message = "Appointment time must be in the future")
31+
@Column(name = "appointment_time", nullable = false)
32+
private LocalDateTime appointmentTime;
33+
34+
@NotNull(message = "Status is required")
35+
@Column(nullable = false)
36+
private Integer status; // 0 = scheduled, 1 = completed
37+
38+
// Default constructor required by JPA
39+
public Appointment() {
40+
}
41+
42+
// Parameterized constructor
43+
public Appointment(Doctor doctor, Patient patient, LocalDateTime appointmentTime, Integer status) {
44+
this.doctor = doctor;
45+
this.patient = patient;
46+
this.appointmentTime = appointmentTime;
47+
this.status = status;
48+
}
49+
50+
// Transient method: end time is not stored in DB
51+
@Transient
52+
public LocalDateTime getEndTime() {
53+
return appointmentTime.plusHours(1);
54+
}
55+
56+
@Transient
57+
public LocalDate getAppointmentDate() {
58+
return appointmentTime.toLocalDate();
59+
}
60+
61+
@Transient
62+
public LocalTime getAppointmentTimeOnly() {
63+
return appointmentTime.toLocalTime();
64+
}
7065

66+
// Getters and Setters
67+
68+
public Long getId() {
69+
return id;
70+
}
71+
72+
public void setId(Long id) {
73+
this.id = id;
74+
}
75+
76+
public Doctor getDoctor() {
77+
return doctor;
78+
}
79+
80+
public void setDoctor(Doctor doctor) {
81+
this.doctor = doctor;
82+
}
83+
84+
public Patient getPatient() {
85+
return patient;
86+
}
87+
88+
public void setPatient(Patient patient) {
89+
this.patient = patient;
90+
}
91+
92+
public LocalDateTime getAppointmentTime() {
93+
return appointmentTime;
94+
}
95+
96+
public void setAppointmentTime(LocalDateTime appointmentTime) {
97+
this.appointmentTime = appointmentTime;
98+
}
99+
100+
public Integer getStatus() {
101+
return status;
102+
}
103+
104+
public void setStatus(Integer status) {
105+
this.status = status;
106+
}
71107
}
72108

109+

0 commit comments

Comments
 (0)