1 | package finki.it.terapijamkbackend.spring.entities;
|
---|
2 |
|
---|
3 | import finki.it.terapijamkbackend.spring.dto.AppointmentInfo;
|
---|
4 | import finki.it.terapijamkbackend.spring.dto.CarriedOutInfo;
|
---|
5 | import lombok.*;
|
---|
6 | import jakarta.persistence.*;
|
---|
7 |
|
---|
8 | import java.time.LocalDate;
|
---|
9 | import java.time.LocalDateTime;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | @Getter
|
---|
14 | @Setter
|
---|
15 | @EqualsAndHashCode
|
---|
16 | @NoArgsConstructor
|
---|
17 | @Entity(name="User")
|
---|
18 | @Table(name="users")
|
---|
19 | public class User {
|
---|
20 |
|
---|
21 | @SequenceGenerator(
|
---|
22 | name="user_sequence",
|
---|
23 | sequenceName = "user_sequence",
|
---|
24 | allocationSize = 1
|
---|
25 | )
|
---|
26 | @Id
|
---|
27 | @GeneratedValue(
|
---|
28 | strategy=GenerationType.SEQUENCE,
|
---|
29 | generator = "user_sequence"
|
---|
30 | )
|
---|
31 | private Long id;
|
---|
32 | private String name;
|
---|
33 | private String surname;
|
---|
34 | private String username;
|
---|
35 | private String password;
|
---|
36 | private LocalDate dateBirth;
|
---|
37 | private String phone;
|
---|
38 | private boolean locked;
|
---|
39 |
|
---|
40 | @ElementCollection
|
---|
41 | @CollectionTable(name = "user_appointment_dates", joinColumns = @JoinColumn(name = "user_id"))
|
---|
42 | @Column(name = "appointment_date")
|
---|
43 | private List<AppointmentInfo> dates;
|
---|
44 | @ElementCollection
|
---|
45 | @CollectionTable(name = "user_carriedOut_dates", joinColumns = @JoinColumn(name = "user_id"))
|
---|
46 | @Column(name = "carriedOut_date")
|
---|
47 | private List<CarriedOutInfo> carriedOut;
|
---|
48 |
|
---|
49 | @Enumerated(EnumType.STRING)
|
---|
50 | private UserRole userRole;
|
---|
51 |
|
---|
52 | public User(String name,String surname,String username,String password,String age,String phone){
|
---|
53 | this.name=name;
|
---|
54 | this.surname=surname;
|
---|
55 | this.username=username;
|
---|
56 | this.password=password;
|
---|
57 | LocalDate temp=LocalDate.parse(age);
|
---|
58 | dateBirth=temp;
|
---|
59 | this.phone=phone;
|
---|
60 | locked=false;
|
---|
61 | userRole=UserRole.USER;
|
---|
62 | dates=new ArrayList<>();
|
---|
63 | carriedOut=new ArrayList<>();
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public String toString() {
|
---|
68 | return username+" "+name+" "+surname;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public void setAppointmentTerms(String term,String additionalInfo,String status){
|
---|
72 | LocalDateTime localDateTime=LocalDateTime.parse(term);
|
---|
73 | AppointmentInfoStatus temp=AppointmentInfoStatus.valueOf(status);
|
---|
74 | AppointmentInfo appointmentInfo=new AppointmentInfo(localDateTime,additionalInfo,temp);
|
---|
75 | dates.add(appointmentInfo);
|
---|
76 | }
|
---|
77 | public void setCarriedOut(String term,String additionalInfo,String adminNote,String status){
|
---|
78 | LocalDateTime localDateTime=LocalDateTime.parse(term);
|
---|
79 | AppointmentInfoStatus temp=AppointmentInfoStatus.valueOf(status);
|
---|
80 | CarriedOutInfo carriedOutInfo=new CarriedOutInfo(localDateTime,additionalInfo,adminNote,temp);
|
---|
81 | carriedOut.add(carriedOutInfo);
|
---|
82 | }
|
---|
83 | }
|
---|