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

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

Added new core functionalities, fixed bugs and improved visual clarity

  • Property mode set to 100644
File size: 2.7 KB
Line 
1package com.wediscussmovies.project.model;
2
3import com.wediscussmovies.project.model.relation.MovieLikes;
4import com.wediscussmovies.project.model.relation.MovieActors;
5import com.wediscussmovies.project.model.relation.MovieGenres;
6import com.wediscussmovies.project.model.relation.MovieRates;
7import lombok.Data;
8import org.hibernate.annotations.Fetch;
9
10import javax.persistence.*;
11import java.sql.Date;
12import java.util.Collection;
13import java.util.Comparator;
14import java.util.Objects;
15
16@Entity
17@Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
18@Data
19public class Movie {
20 @GeneratedValue(strategy = GenerationType.IDENTITY)
21 @Id
22 @Column(name = "movie_id")
23 private int movieId;
24 @Basic
25 @Column(name = "title")
26 private String title;
27 @Basic
28 @Column(name = "description")
29 private String description;
30 @Basic
31 @Column(name = "image_url")
32 private String imageUrl;
33 @Basic
34 @Column(name = "airing_date")
35 private Date airingDate;
36 @Basic
37 @Column(name = "imdb_rating")
38 private Double imdbRating;
39
40 @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
41 private Collection<MovieActors> actors;
42 @OneToMany(mappedBy = "movie", fetch = FetchType.LAZY)
43 private Collection<MovieGenres> genres;
44 @OneToMany(mappedBy = "movie")
45 private Collection<MovieLikes> likes;
46 @OneToMany(mappedBy = "movie")
47 private Collection<MovieRates> rates;
48
49 @ManyToOne
50 @JoinColumn(name = "director_id")
51 private Person director;
52
53 public Movie() {
54
55 }
56
57 public Movie(String title, String description, String imageUrl, Date airingDate,
58 Double imdbRating, Person director) {
59 this.title = title;
60 this.description = description;
61 this.imageUrl = imageUrl;
62 this.airingDate = airingDate;
63 this.imdbRating = imdbRating;
64 this.director = director;
65
66 }
67
68 public Movie(int movieId, String title, Double imdbRating, String imageUrl) {
69 this.movieId = movieId;
70 this.title = title;
71 this.imdbRating = imdbRating;
72 this.imageUrl = imageUrl;
73 }
74
75 public String getDateFormatted(){
76 String dob = airingDate.toString();
77 String [] parts = dob.split("-");
78 return parts[2]+"/"+parts[1]+"/"+parts[0];
79 }
80
81 @Override
82 public boolean equals(Object o) {
83 if (this == o) return true;
84 if (o == null || getClass() != o.getClass()) return false;
85 Movie movie = (Movie) o;
86 return movieId == movie.movieId;
87 }
88
89 @Override
90 public int hashCode() {
91 return Objects.hash(movieId);
92 }
93
94 public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle);
95
96
97
98
99
100
101
102}
Note: See TracBrowser for help on using the repository browser.