source: Git/src/main/java/com/wediscussmovies/project/model/Movie.java@ 7fafead

main
Last change on this file since 7fafead was 7fafead, checked in by Test <matonikolov77@…>, 2 years ago

Resolving models

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package com.wediscussmovies.project.model;
2
3import lombok.Data;
4
5import javax.persistence.*;
6import java.sql.Date;
7import java.util.Collection;
8import java.util.Comparator;
9import java.util.List;
10import java.util.Objects;
11
12
13@Entity
14@Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
15@Data
16public 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}
Note: See TracBrowser for help on using the repository browser.