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