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

main
Last change on this file since 7bc8942 was 2a5d6a3, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago

Controller, Repository and Service layer improvements, Entity updating

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