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