source: Git/Sources/src/main/java/com/wediscussmovies/project/model/Person.java@ 980eeda

main
Last change on this file since 980eeda was 980eeda, checked in by Test <matonikolov77@…>, 22 months ago

Restructuring project

  • Property mode set to 100644
File size: 2.5 KB
Line 
1package com.wediscussmovies.project.model;
2
3import com.wediscussmovies.project.model.relation.MovieActors;
4import com.wediscussmovies.project.model.relation.PersonRates;
5import lombok.Data;
6
7import javax.persistence.*;
8import javax.swing.text.DateFormatter;
9import java.io.Serializable;
10import java.sql.Date;
11import java.time.LocalDate;
12import java.time.format.DateTimeFormatter;
13import java.util.Collection;
14
15@Entity
16@Table(name = "persons", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
17@Data
18public class Person {
19
20 /*
21 ni fale tabela za person koj zanrovi gi ima - ako e potrebno
22 */
23
24 @GeneratedValue(strategy = GenerationType.IDENTITY)
25 @Id
26 @Column(name = "person_id")
27 private int personId;
28 @Basic
29 @Column(name = "name")
30 private String name;
31 @Basic
32 @Column(name = "surname")
33 private String surname;
34 @Basic
35 @Column(name = "type")
36 private Character type;
37 @Basic
38 @Column(name = "date_of_birth")
39 private Date dateOfBirth;
40 @Basic
41 @Column(name = "image_url")
42 private String imageUrl;
43 @Basic
44 @Column(name = "description")
45 private String description;
46 @OneToMany(mappedBy = "person")
47 private Collection<Discussion> discussions;
48 @OneToMany(mappedBy = "person")
49 private Collection<MovieActors> movieActors;
50 @OneToMany(mappedBy = "director")
51 private Collection<Movie> movies;
52 @OneToMany(mappedBy = "person")
53 private Collection<PersonRates> personRates;
54
55
56
57 public Person() {
58
59 }
60
61
62 @Override
63 public boolean equals(Object o) {
64 if (this == o) return true;
65 if (o == null || getClass() != o.getClass()) return false;
66
67 Person that = (Person) o;
68
69 return personId == that.getPersonId();
70 }
71
72 @Override
73 public int hashCode() {
74
75 return personId * 31;
76 }
77
78
79 public String getDateFormatted(){
80 String dob = dateOfBirth.toString();
81 String [] parts = dob.split("-");
82 return parts[2]+"/"+parts[1]+"/"+parts[0];
83 }
84
85
86 public Person(String name, String surname, Character type, Date dateOfBirth, String imageUrl, String description) {
87 this.name = name;
88 this.surname = surname;
89 this.type = type;
90 this.dateOfBirth = dateOfBirth;
91 this.imageUrl = imageUrl;
92 this.description = description;
93 }
94
95 public boolean hasGradeFromUser(User user){
96 for(PersonRates p: personRates){
97 if(p.getUser().getUserId() == user.getUserId())
98 return true;
99 }
100 return false;
101 }
102
103}
Note: See TracBrowser for help on using the repository browser.