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