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.Collection;
|
---|
8 | import java.util.Comparator;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Objects;
|
---|
11 |
|
---|
12 |
|
---|
13 | @Entity
|
---|
14 | @Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
|
---|
15 | @Data
|
---|
16 | public class Movie {
|
---|
17 |
|
---|
18 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
19 | @Id
|
---|
20 | @Column(name = "movie_id")
|
---|
21 | private Long id;
|
---|
22 |
|
---|
23 | private String title;
|
---|
24 |
|
---|
25 | private String description;
|
---|
26 |
|
---|
27 | @Column(name = "image_url")
|
---|
28 | private String imageUrl;
|
---|
29 |
|
---|
30 |
|
---|
31 | @Column(name = "airing_date")
|
---|
32 | private Date aringDate;
|
---|
33 |
|
---|
34 | @Column(name = "imdb_rating")
|
---|
35 | private Double imbdRating;
|
---|
36 |
|
---|
37 | @ManyToMany
|
---|
38 | private List<Genre> genres;
|
---|
39 |
|
---|
40 | @ManyToMany
|
---|
41 | private List<Person> likes;
|
---|
42 |
|
---|
43 | @ManyToMany
|
---|
44 | private List<Person> actors;
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | @ManyToOne
|
---|
50 | @JoinColumn(name = "director_id")
|
---|
51 | private Person director;
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | public boolean isFromGenre(Genre genre){
|
---|
59 |
|
---|
60 | return genres
|
---|
61 | .stream()
|
---|
62 | .anyMatch(g -> Objects.equals(g.getId(), genre.getId()));
|
---|
63 |
|
---|
64 | }
|
---|
65 | public boolean hasActor(Person p){
|
---|
66 | return
|
---|
67 | actors
|
---|
68 | .stream()
|
---|
69 | .anyMatch(a -> Objects.equals(a.getPersonId(), p.getPersonId()));
|
---|
70 |
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | public boolean isDirectedBy(Person p){
|
---|
75 | return Objects.equals(director.getPersonId(), p.getPersonId());
|
---|
76 | }
|
---|
77 |
|
---|
78 | public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
|
---|
79 |
|
---|
80 |
|
---|
81 | public Movie( String title, String description, String imageUrl, Date aringDate, Double imbdRating,Person director, List<Person> actors, List<Genre> genres) {
|
---|
82 |
|
---|
83 | this.title = title;
|
---|
84 | this.description = description;
|
---|
85 | this.imageUrl = imageUrl;
|
---|
86 | this.aringDate = aringDate;
|
---|
87 | this.imbdRating = imbdRating;
|
---|
88 | this.genres = genres;
|
---|
89 | this.likes = likes;
|
---|
90 | this.actors = actors;
|
---|
91 | this.director = director;
|
---|
92 | }
|
---|
93 |
|
---|
94 | public Movie() {
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | }
|
---|