1 | package com.wediscussmovies.project.model;
|
---|
2 |
|
---|
3 | import lombok.Data;
|
---|
4 |
|
---|
5 | import javax.persistence.*;
|
---|
6 | import java.sql.Date;
|
---|
7 | import java.util.Comparator;
|
---|
8 | import java.util.List;
|
---|
9 | @Data
|
---|
10 | @Entity
|
---|
11 | @Table (name="movies")
|
---|
12 | public class Movie {
|
---|
13 | @Id
|
---|
14 | @GeneratedValue
|
---|
15 | @Column(name="movie_id", nullable = false)
|
---|
16 | private int movie_id;
|
---|
17 |
|
---|
18 | @Column(name="title", length = 150, unique = true, nullable = false)
|
---|
19 | private String Title;
|
---|
20 |
|
---|
21 | @Column(name="description", nullable = false, length = 1000)
|
---|
22 | private String description;
|
---|
23 |
|
---|
24 | @Column(name="image_url", length = 300, nullable = false)
|
---|
25 | private String image_url;
|
---|
26 |
|
---|
27 | @Column(name="airing_date")
|
---|
28 | private Date airing_date;
|
---|
29 |
|
---|
30 | @Column(name="imdb_rating")
|
---|
31 | private float imdb_rating;
|
---|
32 |
|
---|
33 | @Column(name="director_id")
|
---|
34 | @ManyToOne
|
---|
35 | private Person director;
|
---|
36 |
|
---|
37 | @ManyToMany(mappedBy = "movie_actors")
|
---|
38 | private List<Person> actors;
|
---|
39 |
|
---|
40 | @ManyToMany(mappedBy = "movie_genres")
|
---|
41 | private List<Genre> genres;
|
---|
42 |
|
---|
43 | public boolean isFromGenre(Genre genre){
|
---|
44 | for(Genre g: genres){
|
---|
45 | if(g.getGenre_id() == genre.getGenre_id())
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | public boolean hasActor(Person p){
|
---|
51 | for(Person person: actors){
|
---|
52 | if(person.getPerson_id() == p.getPerson_id())
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public boolean isDirectedBy(Person p){
|
---|
59 | return director.getPerson_id() == p.getPerson_id();
|
---|
60 | }
|
---|
61 |
|
---|
62 | public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
|
---|
63 |
|
---|
64 | public Movie() {
|
---|
65 | }
|
---|
66 |
|
---|
67 | public Movie(String title, String description, String image_url, Date airing_date, float imdb_rating, Person director, List<Person> actors, List<Genre> genres) {
|
---|
68 | Title = title;
|
---|
69 | this.description = description;
|
---|
70 | this.image_url = image_url;
|
---|
71 | this.airing_date = airing_date;
|
---|
72 | this.imdb_rating = imdb_rating;
|
---|
73 | this.director = director;
|
---|
74 | this.actors = actors;
|
---|
75 | this.genres = genres;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | /*
|
---|
81 |
|
---|
82 | create table movies(
|
---|
83 | movie_id serial primary key,
|
---|
84 | title varchar(150) not null unique,
|
---|
85 | description varchar(1000) not null,
|
---|
86 | image_url varchar(300) not null,
|
---|
87 | airing_date date not null,
|
---|
88 | imdb_rating float,
|
---|
89 | director_id integer,
|
---|
90 | constraint fk_movie_director foreign key (director_id) references persons(person_id)
|
---|
91 | on delete cascade on update cascade,
|
---|
92 | constraint ck_person_is_director check( check_constraint_person(director_id) = 'D')
|
---|
93 | );
|
---|
94 | */ |
---|