Changes in / [7fafead:2d57cad] in Git
- Files:
-
- 25 added
- 44 deleted
- 47 edited
Legend:
- Unmodified
- Added
- Removed
-
.idea/vcs.xml
r7fafead r2d57cad 3 3 <component name="VcsDirectoryMappings"> 4 4 <mapping directory="" vcs="Git" /> 5 <mapping directory="$PROJECT_DIR$/WeDiscussMovies" vcs="Git" />6 5 </component> 7 6 </project> -
README.md
r7fafead r2d57cad 3 3 <div style="float: left; width: 60%;"> 4 4 5 <img src="/img/logo.png" style="display: block; float:left; height: auto; width: 30%;" align="right" alt="q">6 <h4 style="display: block; font-weight: normal; text-align: justify; float: right">Предмет: Бази на податоци 2021/2022/Зимски</h 4><br>5 <img src="/img/logo.png" style="display: block; float:left; height: auto; width: 30%;" align="right"> 6 <h4 style="display: block; font-weight: normal; text-align: justify; float: right">Предмет: Бази на податоци 2021/2022/Зимски</h2><br> 7 7 <h4 style="display: block; font-weight: normal; text-align: justify; float: right">Под менторство на вонр. проф. д-р Вангел Ајановски и демонстр. м-р Ненад Анчев</h4><br> 8 8 <h4 style="display: block; font-weight: normal; text-align: justify; float: right">Започнат: Ноември 2021</h4><br><br> … … 23 23 <li>Мартин Николов (193113)</li> 24 24 </ol> 25 </div> -
pom.xml
r7fafead r2d57cad 42 42 <groupId>org.postgresql</groupId> 43 43 <artifactId>postgresql</artifactId> 44 <scope>runtime</scope> 44 45 </dependency> 45 46 <dependency> … … 71 72 <artifactId>h2</artifactId> 72 73 </dependency> 73 74 74 <dependency> 75 <groupId>org.postgresql</groupId> 76 <artifactId>postgresql</artifactId> 77 </dependency> 78 <dependency> 79 <groupId>com.jcraft</groupId> 80 <artifactId>jsch</artifactId> 81 <version>0.1.55</version> 82 </dependency> 75 83 76 84 </dependencies> -
project.iml
r7fafead r2d57cad 138 138 <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.6.2" level="project" /> 139 139 <orderEntry type="library" name="Maven: com.h2database:h2:1.4.200" level="project" /> 140 <orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.55" level="project" /> 140 141 </component> 141 142 </module> -
src/main/java/com/wediscussmovies/project/model/Discussion.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 import com.wediscussmovies.project.model.enumerations.DiscussionType;4 import lombok.Data;5 2 6 3 import javax.persistence.*; 7 4 import java.sql.Date; 8 5 import java.util.Collection; 9 import java.util.List;10 6 import java.util.Objects; 11 7 12 @Data13 8 @Entity 14 9 @Table(name = "discussions", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 15 10 public class Discussion { 16 17 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 18 12 @Id 19 13 @Column(name = "discussion_id") 20 private Long id; 21 22 @Enumerated 23 private DiscussionType type; 24 14 private int discussionId; 15 @Basic 16 @Column(name = "type") 17 private String type; 18 @Basic 19 @Column(name = "text") 25 20 private String text; 26 21 @Basic 22 @Column(name = "title") 27 23 private String title; 28 24 @Basic 25 @Column(name = "date") 29 26 private Date date; 30 31 32 33 27 @Basic 28 @Column(name = "user_id") 29 private int userId; 30 @Basic 31 @Column(name = "movie_id") 32 private Integer movieId; 33 @Basic 34 @Column(name = "person_id") 35 private Integer personId; 34 36 35 37 @ManyToOne 36 @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false) 37 private User user; 38 @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false,insertable = false, updatable = false) 39 private User usersByUserId; 40 @ManyToOne 41 @JoinColumn(name = "movie_id", referencedColumnName = "movie_id",insertable = false, updatable = false) 42 private Movie moviesByMovieId; 43 @ManyToOne 44 @JoinColumn(name = "person_id", referencedColumnName = "person_id",insertable = false, updatable = false) 45 private Person personsByPersonId; 46 @OneToMany(mappedBy = "discussionsByDiscussionId") 47 private Collection<Reply> repliesByDiscussionId; 38 48 39 @ManyToOne40 @JoinColumn(name = "movie_id", referencedColumnName = "movie_id")41 private Movie movie;49 public int getDiscussionId() { 50 return discussionId; 51 } 42 52 43 @ManyToOne44 @JoinColumn(name = "person_id", referencedColumnName = "person_id")45 private Person person;53 public void setDiscussionId(int discussionId) { 54 this.discussionId = discussionId; 55 } 46 56 57 public String getType() { 58 return type; 59 } 47 60 61 public void setType(String type) { 62 this.type = type; 63 } 48 64 65 public String getText() { 66 return text; 67 } 49 68 69 public void setText(String text) { 70 this.text = text; 71 } 50 72 73 public String getTitle() { 74 return title; 75 } 51 76 52 public Discussion(DiscussionType type, String text, String title, Date date, User user, Movie movie, Person person, List<Reply> replies) { 53 this.type = type; 54 this.text = text; 77 public void setTitle(String title) { 55 78 this.title = title; 79 } 80 81 public Date getDate() { 82 return date; 83 } 84 85 public void setDate(Date date) { 56 86 this.date = date; 57 this.user = user; 58 this.movie = movie; 59 this.person = person; 87 } 88 89 public int getUserId() { 90 return userId; 91 } 92 93 public void setUserId(int userId) { 94 this.userId = userId; 95 } 96 97 public Integer getMovieId() { 98 return movieId; 99 } 100 101 public void setMovieId(Integer movieId) { 102 this.movieId = movieId; 103 } 104 105 public Integer getPersonId() { 106 return personId; 107 } 108 109 public void setPersonId(Integer personId) { 110 this.personId = personId; 111 } 112 113 @Override 114 public boolean equals(Object o) { 115 if (this == o) return true; 116 if (o == null || getClass() != o.getClass()) return false; 117 118 Discussion that = (Discussion) o; 119 120 if (discussionId != that.discussionId) return false; 121 if (userId != that.userId) return false; 122 if (!Objects.equals(type, that.type)) return false; 123 if (!Objects.equals(text, that.text)) return false; 124 if (!Objects.equals(title, that.title)) return false; 125 if (!Objects.equals(date, that.date)) return false; 126 if (!Objects.equals(movieId, that.movieId)) return false; 127 if (!Objects.equals(personId, that.personId)) return false; 128 129 return true; 130 } 131 132 @Override 133 public int hashCode() { 134 int result = discussionId; 135 result = 31 * result + (type != null ? type.hashCode() : 0); 136 result = 31 * result + (text != null ? text.hashCode() : 0); 137 result = 31 * result + (title != null ? title.hashCode() : 0); 138 result = 31 * result + (date != null ? date.hashCode() : 0); 139 result = 31 * result + userId; 140 result = 31 * result + (movieId != null ? movieId.hashCode() : 0); 141 result = 31 * result + (personId != null ? personId.hashCode() : 0); 142 return result; 143 } 144 145 public User getUsersByUserId() { 146 return usersByUserId; 147 } 148 149 public void setUsersByUserId(User usersByUserId) { 150 this.usersByUserId = usersByUserId; 151 } 152 153 public Movie getMoviesByMovieId() { 154 return moviesByMovieId; 155 } 156 157 public void setMoviesByMovieId(Movie moviesByMovieId) { 158 this.moviesByMovieId = moviesByMovieId; 159 } 160 161 public Person getPersonsByPersonId() { 162 return personsByPersonId; 163 } 164 165 public void setPersonsByPersonId(Person personsByPersonId) { 166 this.personsByPersonId = personsByPersonId; 167 } 168 169 public Collection<Reply> getRepliesByDiscussionId() { 170 return repliesByDiscussionId; 171 } 172 173 public void setRepliesByDiscussionId(Collection<Reply> repliesByDiscussionId) { 174 this.repliesByDiscussionId = repliesByDiscussionId; 60 175 } 61 176 … … 63 178 } 64 179 65 180 public Discussion(String type, String text, String title, Date date, int userId, Integer movieId, Integer personId) { 181 this.type = type; 182 this.text = text; 183 this.title = title; 184 this.date = date; 185 this.userId = userId; 186 this.movieId = movieId; 187 this.personId = personId; 188 } 66 189 } -
src/main/java/com/wediscussmovies/project/model/Genre.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 2 4 3 import javax.persistence.*; 5 4 import java.util.Collection; 6 import lombok.Data;7 8 5 9 6 @Entity 10 7 @Table(name = "genres", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 11 @Data12 8 public class Genre { 13 14 9 @GeneratedValue(strategy = GenerationType.IDENTITY) 15 10 @Id 16 11 @Column(name = "genre_id") 17 private Long id; 12 private int genreId; 13 @Basic 14 @Column(name = "genre_type") 15 private String genreType; 16 @OneToMany(mappedBy = "genresByGenreId") 17 private Collection<MovieGenresEntity> movieGenresByGenreId; 18 @OneToMany(mappedBy = "genresByGenreId") 19 private Collection<UserGenresEntity> userGenresByGenreId; 18 20 19 @Column(name = "genre_type") 20 private String genre; 21 public int getGenreId() { 22 return genreId; 23 } 21 24 22 public Genre(String genre) { 23 this.genre = genre; 25 public void setGenreId(int genreId) { 26 this.genreId = genreId; 27 } 28 29 public String getGenreType() { 30 return genreType; 31 } 32 33 public void setGenreType(String genreType) { 34 this.genreType = genreType; 35 } 36 37 @Override 38 public boolean equals(Object o) { 39 if (this == o) return true; 40 if (o == null || getClass() != o.getClass()) return false; 41 42 Genre that = (Genre) o; 43 44 if (genreId != that.genreId) return false; 45 if (genreType != null ? !genreType.equals(that.genreType) : that.genreType != null) return false; 46 47 return true; 48 } 49 50 @Override 51 public int hashCode() { 52 int result = genreId; 53 result = 31 * result + (genreType != null ? genreType.hashCode() : 0); 54 return result; 55 } 56 57 public Collection<MovieGenresEntity> getMovieGenresByGenreId() { 58 return movieGenresByGenreId; 59 } 60 61 public void setMovieGenresByGenreId(Collection<MovieGenresEntity> movieGenresByGenreId) { 62 this.movieGenresByGenreId = movieGenresByGenreId; 63 } 64 65 public Collection<UserGenresEntity> getUserGenresByGenreId() { 66 return userGenresByGenreId; 67 } 68 69 public void setUserGenresByGenreId(Collection<UserGenresEntity> userGenresByGenreId) { 70 this.userGenresByGenreId = userGenresByGenreId; 71 } 72 73 public Genre(String genreType) { 74 this.genreType = genreType; 24 75 } 25 76 26 77 public Genre() { 27 78 } 28 29 79 } -
src/main/java/com/wediscussmovies/project/model/Movie.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 import lombok.Data;4 2 5 3 import javax.persistence.*; 6 4 import java.sql.Date; 7 5 import java.util.Collection; 8 import java.util.Comparator;9 import java.util.List;10 6 import java.util.Objects; 11 12 7 13 8 @Entity 14 9 @Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 15 @Data16 10 public class Movie { 17 18 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 19 12 @Id 20 13 @Column(name = "movie_id") 21 private Long id; 22 14 private int movieId; 15 @Basic 16 @Column(name = "title") 23 17 private String title; 24 18 @Basic 19 @Column(name = "description") 25 20 private String description; 26 21 @Basic 27 22 @Column(name = "image_url") 28 23 private String imageUrl; 24 @Basic 25 @Column(name = "airing_date") 26 private Date airingDate; 27 @Basic 28 @Column(name = "imdb_rating") 29 private Double imdbRating; 30 @Basic 31 @Column(name = "director_id") 32 private Integer directorId; 33 @OneToMany(mappedBy = "moviesByMovieId") 34 private Collection<Discussion> discussionsByMovieId; 35 @OneToMany(mappedBy = "moviesByMovieId") 36 private Collection<MovieActorsEntity> movieActorsByMovieId; 37 @OneToMany(mappedBy = "moviesByMovieId") 38 private Collection<MovieGenresEntity> movieGenresByMovieId; 39 @OneToMany(mappedBy = "moviesByMovieId") 40 private Collection<MovieLikesEntity> movieLikesByMovieId; 41 @OneToMany(mappedBy = "moviesByMovieId") 42 private Collection<MovieRatesEntity> movieRatesByMovieId; 43 @ManyToOne 44 @JoinColumn(name = "director_id", referencedColumnName = "person_id",insertable = false, updatable = false) 45 private Person personsByDirectorId; 29 46 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 47 public int getMovieId() { 48 return movieId; 72 49 } 73 50 74 public boolean isDirectedBy(Person p){75 return Objects.equals(director.getPersonId(), p.getPersonId());51 public void setMovieId(int movieId) { 52 this.movieId = movieId; 76 53 } 77 54 78 public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle); 55 public String getTitle() { 56 return title; 57 } 79 58 59 public void setTitle(String title) { 60 this.title = title; 61 } 80 62 81 public Movie( String title, String description, String imageUrl, Date aringDate, Double imbdRating,Person director, List<Person> actors, List<Genre> genres) { 63 public String getDescription() { 64 return description; 65 } 82 66 67 public void setDescription(String description) { 68 this.description = description; 69 } 70 71 public String getImageUrl() { 72 return imageUrl; 73 } 74 75 public void setImageUrl(String imageUrl) { 76 this.imageUrl = imageUrl; 77 } 78 79 public Date getAiringDate() { 80 return airingDate; 81 } 82 83 public void setAiringDate(Date airingDate) { 84 this.airingDate = airingDate; 85 } 86 87 public Double getImdbRating() { 88 return imdbRating; 89 } 90 91 public void setImdbRating(Double imdbRating) { 92 this.imdbRating = imdbRating; 93 } 94 95 public Integer getDirectorId() { 96 return directorId; 97 } 98 99 public void setDirectorId(Integer directorId) { 100 this.directorId = directorId; 101 } 102 103 @Override 104 public boolean equals(Object o) { 105 if (this == o) return true; 106 if (o == null || getClass() != o.getClass()) return false; 107 108 Movie that = (Movie) o; 109 110 if (movieId != that.movieId) return false; 111 if (!Objects.equals(title, that.title)) return false; 112 if (!Objects.equals(description, that.description)) return false; 113 if (!Objects.equals(imageUrl, that.imageUrl)) return false; 114 if (!Objects.equals(airingDate, that.airingDate)) return false; 115 if (!Objects.equals(imdbRating, that.imdbRating)) return false; 116 if (!Objects.equals(directorId, that.directorId)) return false; 117 118 return true; 119 } 120 121 public Movie(String title, String description, String imageUrl, Date airingDate, Double imdbRating, Integer directorId) { 83 122 this.title = title; 84 123 this.description = description; 85 124 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; 125 this.airingDate = airingDate; 126 this.imdbRating = imdbRating; 127 this.directorId = directorId; 92 128 } 93 129 … … 95 131 } 96 132 133 @Override 134 public int hashCode() { 135 int result = movieId; 136 result = 31 * result + (title != null ? title.hashCode() : 0); 137 result = 31 * result + (description != null ? description.hashCode() : 0); 138 result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0); 139 result = 31 * result + (airingDate != null ? airingDate.hashCode() : 0); 140 result = 31 * result + (imdbRating != null ? imdbRating.hashCode() : 0); 141 result = 31 * result + (directorId != null ? directorId.hashCode() : 0); 142 return result; 143 } 97 144 145 public Collection<Discussion> getDiscussionsByMovieId() { 146 return discussionsByMovieId; 147 } 148 149 public void setDiscussionsByMovieId(Collection<Discussion> discussionsByMovieId) { 150 this.discussionsByMovieId = discussionsByMovieId; 151 } 152 153 public Collection<MovieActorsEntity> getMovieActorsByMovieId() { 154 return movieActorsByMovieId; 155 } 156 157 public void setMovieActorsByMovieId(Collection<MovieActorsEntity> movieActorsByMovieId) { 158 this.movieActorsByMovieId = movieActorsByMovieId; 159 } 160 161 public Collection<MovieGenresEntity> getMovieGenresByMovieId() { 162 return movieGenresByMovieId; 163 } 164 165 public void setMovieGenresByMovieId(Collection<MovieGenresEntity> movieGenresByMovieId) { 166 this.movieGenresByMovieId = movieGenresByMovieId; 167 } 168 169 public Collection<MovieLikesEntity> getMovieLikesByMovieId() { 170 return movieLikesByMovieId; 171 } 172 173 public void setMovieLikesByMovieId(Collection<MovieLikesEntity> movieLikesByMovieId) { 174 this.movieLikesByMovieId = movieLikesByMovieId; 175 } 176 177 public Collection<MovieRatesEntity> getMovieRatesByMovieId() { 178 return movieRatesByMovieId; 179 } 180 181 public void setMovieRatesByMovieId(Collection<MovieRatesEntity> movieRatesByMovieId) { 182 this.movieRatesByMovieId = movieRatesByMovieId; 183 } 184 185 public Person getPersonsByDirectorId() { 186 return personsByDirectorId; 187 } 188 189 public void setPersonsByDirectorId(Person personsByDirectorId) { 190 this.personsByDirectorId = personsByDirectorId; 191 } 98 192 } -
src/main/java/com/wediscussmovies/project/model/Person.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 import com.wediscussmovies.project.model.enumerations.PersonType;4 import lombok.Data;5 2 6 3 import javax.persistence.*; 7 4 import java.sql.Date; 8 5 import java.util.Collection; 9 import java.util.List;10 6 11 7 @Entity 12 8 @Table(name = "persons", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 13 @Data14 9 public class Person { 15 10 @GeneratedValue(strategy = GenerationType.IDENTITY) 16 11 @Id 17 12 @Column(name = "person_id") 18 private Long personId; 19 13 private int personId; 14 @Basic 15 @Column(name = "name") 20 16 private String name; 21 17 @Basic 18 @Column(name = "surname") 22 19 private String surname; 23 24 @ Enumerated25 private PersonTypetype;26 20 @Basic 21 @Column(name = "type") 22 private String type; 23 @Basic 27 24 @Column(name = "date_of_birth") 28 private Date birthDate;29 25 private Date dateOfBirth; 26 @Basic 30 27 @Column(name = "image_url") 31 28 private String imageUrl; 29 @Basic 30 @Column(name = "description") 31 private String description; 32 @OneToMany(mappedBy = "personsByPersonId") 33 private Collection<Discussion> discussionsByPersonId; 34 @OneToMany(mappedBy = "personsByActorId") 35 private Collection<MovieActorsEntity> movieActorsByPersonId; 36 @OneToMany(mappedBy = "personsByDirectorId") 37 private Collection<Movie> moviesByPersonId; 38 @OneToMany(mappedBy = "personsByPersonId") 39 private Collection<PersonRatesEntity> personRatesByPersonId; 32 40 33 private String description; 34 35 36 37 public Person() { 41 public int getPersonId() { 42 return personId; 38 43 } 39 44 40 public Person(String name, String surname, PersonType type, Date date_of_birth, String image_url, String description) { 45 public void setPersonId(int personId) { 46 this.personId = personId; 47 } 48 49 public String getName() { 50 return name; 51 } 52 53 public void setName(String name) { 41 54 this.name = name; 55 } 56 57 public String getSurname() { 58 return surname; 59 } 60 61 public void setSurname(String surname) { 42 62 this.surname = surname; 63 } 64 65 public String getType() { 66 return type; 67 } 68 69 public void setType(String type) { 43 70 this.type = type; 44 this.birthDate = date_of_birth; 45 this.imageUrl = image_url; 71 } 72 73 public Date getDateOfBirth() { 74 return dateOfBirth; 75 } 76 77 public void setDateOfBirth(Date dateOfBirth) { 78 this.dateOfBirth = dateOfBirth; 79 } 80 81 public String getImageUrl() { 82 return imageUrl; 83 } 84 85 public void setImageUrl(String imageUrl) { 86 this.imageUrl = imageUrl; 87 } 88 89 public String getDescription() { 90 return description; 91 } 92 93 public void setDescription(String description) { 46 94 this.description = description; 47 95 } 96 97 @Override 98 public boolean equals(Object o) { 99 if (this == o) return true; 100 if (o == null || getClass() != o.getClass()) return false; 101 102 Person that = (Person) o; 103 104 if (personId != that.personId) return false; 105 if (name != null ? !name.equals(that.name) : that.name != null) return false; 106 if (surname != null ? !surname.equals(that.surname) : that.surname != null) return false; 107 if (type != null ? !type.equals(that.type) : that.type != null) return false; 108 if (dateOfBirth != null ? !dateOfBirth.equals(that.dateOfBirth) : that.dateOfBirth != null) return false; 109 if (imageUrl != null ? !imageUrl.equals(that.imageUrl) : that.imageUrl != null) return false; 110 if (description != null ? !description.equals(that.description) : that.description != null) return false; 111 112 return true; 113 } 114 115 @Override 116 public int hashCode() { 117 int result = personId; 118 result = 31 * result + (name != null ? name.hashCode() : 0); 119 result = 31 * result + (surname != null ? surname.hashCode() : 0); 120 result = 31 * result + (type != null ? type.hashCode() : 0); 121 result = 31 * result + (dateOfBirth != null ? dateOfBirth.hashCode() : 0); 122 result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0); 123 result = 31 * result + (description != null ? description.hashCode() : 0); 124 return result; 125 } 126 127 public Collection<Discussion> getDiscussionsByPersonId() { 128 return discussionsByPersonId; 129 } 130 131 public void setDiscussionsByPersonId(Collection<Discussion> discussionsByPersonId) { 132 this.discussionsByPersonId = discussionsByPersonId; 133 } 134 135 public Collection<MovieActorsEntity> getMovieActorsByPersonId() { 136 return movieActorsByPersonId; 137 } 138 139 public void setMovieActorsByPersonId(Collection<MovieActorsEntity> movieActorsByPersonId) { 140 this.movieActorsByPersonId = movieActorsByPersonId; 141 } 142 143 public Collection<Movie> getMoviesByPersonId() { 144 return moviesByPersonId; 145 } 146 147 public void setMoviesByPersonId(Collection<Movie> moviesByPersonId) { 148 this.moviesByPersonId = moviesByPersonId; 149 } 150 151 public Collection<PersonRatesEntity> getPersonRatesByPersonId() { 152 return personRatesByPersonId; 153 } 154 155 public void setPersonRatesByPersonId(Collection<PersonRatesEntity> personRatesByPersonId) { 156 this.personRatesByPersonId = personRatesByPersonId; 157 } 48 158 } -
src/main/java/com/wediscussmovies/project/model/RepliesEntityPK.java
r7fafead r2d57cad 8 8 9 9 public class RepliesEntityPK implements Serializable { 10 @Column(name = "discussion_id") 10 11 @Id 11 @Column(name = "discussion_id")12 private Long discussionId;12 private int discussionId; 13 @Column(name = "reply_id") 13 14 @Id 14 15 @GeneratedValue(strategy = GenerationType.IDENTITY) 15 @Column(name = "reply_id") 16 private Long replyId; 16 private int replyId; 17 17 18 public int getDiscussionId() { 19 return discussionId; 20 } 18 21 22 public void setDiscussionId(int discussionId) { 23 this.discussionId = discussionId; 24 } 19 25 26 public int getReplyId() { 27 return replyId; 28 } 29 30 public void setReplyId(int replyId) { 31 this.replyId = replyId; 32 } 33 34 @Override 35 public boolean equals(Object o) { 36 if (this == o) return true; 37 if (o == null || getClass() != o.getClass()) return false; 38 39 RepliesEntityPK that = (RepliesEntityPK) o; 40 41 if (discussionId != that.discussionId) return false; 42 if (replyId != that.replyId) return false; 43 44 return true; 45 } 46 47 @Override 48 public int hashCode() { 49 int result = discussionId; 50 result = 31 * result + replyId; 51 return result; 52 } 20 53 } -
src/main/java/com/wediscussmovies/project/model/Reply.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 import lombok.Data;4 2 5 3 import javax.persistence.*; 6 4 import java.sql.Date; 7 import java.util.Optional;8 5 9 6 @Entity 10 7 @Table(name = "replies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 11 8 @IdClass(RepliesEntityPK.class) 12 @Data13 9 public class Reply { 14 10 @Id 15 @Column(name = "discussion_id") 16 private Long discussionId; 17 11 @Column(name = "discussion_id",insertable = false, updatable = false) 12 private int discussionId; 18 13 @GeneratedValue(strategy = GenerationType.IDENTITY) 19 14 @Id 20 15 @Column(name = "reply_id") 21 private Long replyId; 22 16 private int replyId; 17 @Basic 18 @Column(name = "text") 23 19 private String text; 24 20 @Basic 21 @Column(name = "date") 25 22 private Date date; 26 23 @Basic 24 @Column(name = "user_id") 25 private int userId; 27 26 @ManyToOne 28 27 @JoinColumn(name = "discussion_id", referencedColumnName = "discussion_id", nullable = false,insertable = false, updatable = false) 29 private Discussion discussion; 28 private Discussion discussionsByDiscussionId; 29 @ManyToOne 30 @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false,insertable = false, updatable = false) 31 private User usersByUserId; 30 32 31 @ManyToOne 32 @JoinColumn(name = "user_id") 33 private User user; 34 35 36 37 38 public Reply(Discussion discussion, User user, Date date, String text) { 39 this.discussion = discussion; 40 this.user = user; 41 this.date = date; 42 this.text = text; 43 33 public int getDiscussionId() { 34 return discussionId; 44 35 } 45 36 46 public Reply() {47 37 public void setDiscussionId(int discussionId) { 38 this.discussionId = discussionId; 48 39 } 49 40 41 public int getReplyId() { 42 return replyId; 43 } 50 44 45 public void setReplyId(int replyId) { 46 this.replyId = replyId; 47 } 48 49 public String getText() { 50 return text; 51 } 52 53 public void setText(String text) { 54 this.text = text; 55 } 56 57 public Date getDate() { 58 return date; 59 } 60 61 public void setDate(Date date) { 62 this.date = date; 63 } 64 65 public int getUserId() { 66 return userId; 67 } 68 69 public void setUserId(int userId) { 70 this.userId = userId; 71 } 72 73 @Override 74 public boolean equals(Object o) { 75 if (this == o) return true; 76 if (o == null || getClass() != o.getClass()) return false; 77 78 Reply that = (Reply) o; 79 80 if (discussionId != that.discussionId) return false; 81 if (replyId != that.replyId) return false; 82 if (userId != that.userId) return false; 83 if (text != null ? !text.equals(that.text) : that.text != null) return false; 84 if (date != null ? !date.equals(that.date) : that.date != null) return false; 85 86 return true; 87 } 88 89 @Override 90 public int hashCode() { 91 int result = discussionId; 92 result = 31 * result + replyId; 93 result = 31 * result + (text != null ? text.hashCode() : 0); 94 result = 31 * result + (date != null ? date.hashCode() : 0); 95 result = 31 * result + userId; 96 return result; 97 } 98 99 public Discussion getDiscussionsByDiscussionId() { 100 return discussionsByDiscussionId; 101 } 102 103 public void setDiscussionsByDiscussionId(Discussion discussionsByDiscussionId) { 104 this.discussionsByDiscussionId = discussionsByDiscussionId; 105 } 106 107 public User getUsersByUserId() { 108 return usersByUserId; 109 } 110 111 public void setUsersByUserId(User usersByUserId) { 112 this.usersByUserId = usersByUserId; 113 } 51 114 } -
src/main/java/com/wediscussmovies/project/model/User.java
r7fafead r2d57cad 3 3 import javax.persistence.*; 4 4 import java.util.Collection; 5 import java.util.List;6 5 7 6 @Entity … … 11 10 @Id 12 11 @Column(name = "user_id") 13 private Long userId; 12 private int userId; 13 @Basic 14 @Column(name = "username") 15 private String username; 16 @Basic 17 @Column(name = "name") 18 private String name; 19 @Basic 20 @Column(name = "surname") 21 private String surname; 22 @Basic 23 @Column(name = "email") 24 private String email; 25 @Basic 26 @Column(name = "password") 27 private String password; 28 @OneToMany(mappedBy = "usersByUserId") 29 private Collection<Discussion> discussionsByUserId; 30 @OneToMany(mappedBy = "usersByUserId") 31 private Collection<MovieLikesEntity> movieLikesByUserId; 32 @OneToMany(mappedBy = "usersByUserId") 33 private Collection<MovieRatesEntity> movieRatesByUserId; 34 @OneToMany(mappedBy = "usersByUserId") 35 private Collection<PersonRatesEntity> personRatesByUserId; 36 @OneToMany(mappedBy = "usersByUserId") 37 private Collection<Reply> repliesByUserId; 38 @OneToMany(mappedBy = "usersByUserId") 39 private Collection<UserGenresEntity> userGenresByUserId; 14 40 15 private String username; 41 public int getUserId() { 42 return userId; 43 } 16 44 17 private String name; 45 public void setUserId(int userId) { 46 this.userId = userId; 47 } 18 48 19 private String surname; 49 public String getUsername() { 50 return username; 51 } 20 52 21 private String email; 53 public void setUsername(String username) { 54 this.username = username; 55 } 22 56 23 private String password; 57 public String getName() { 58 return name; 59 } 24 60 25 @ManyToMany 26 private List<Movie> movies; 61 public void setName(String name) { 62 this.name = name; 63 } 27 64 65 public String getSurname() { 66 return surname; 67 } 28 68 69 public void setSurname(String surname) { 70 this.surname = surname; 71 } 29 72 73 public String getEmail() { 74 return email; 75 } 30 76 31 public User(String username, String name, String surname, String email, String password) { 32 this.username = username; 33 this.name = name; 34 this.surname = surname; 77 public void setEmail(String email) { 35 78 this.email = email; 79 } 80 81 public String getPassword() { 82 return password; 83 } 84 85 public void setPassword(String password) { 36 86 this.password = password; 37 87 } 38 88 39 public User() { 89 @Override 90 public boolean equals(Object o) { 91 if (this == o) return true; 92 if (o == null || getClass() != o.getClass()) return false; 93 94 User that = (User) o; 95 96 if (userId != that.userId) return false; 97 if (username != null ? !username.equals(that.username) : that.username != null) return false; 98 if (name != null ? !name.equals(that.name) : that.name != null) return false; 99 if (surname != null ? !surname.equals(that.surname) : that.surname != null) return false; 100 if (email != null ? !email.equals(that.email) : that.email != null) return false; 101 if (password != null ? !password.equals(that.password) : that.password != null) return false; 102 103 return true; 104 } 105 106 @Override 107 public int hashCode() { 108 int result = userId; 109 result = 31 * result + (username != null ? username.hashCode() : 0); 110 result = 31 * result + (name != null ? name.hashCode() : 0); 111 result = 31 * result + (surname != null ? surname.hashCode() : 0); 112 result = 31 * result + (email != null ? email.hashCode() : 0); 113 result = 31 * result + (password != null ? password.hashCode() : 0); 114 return result; 115 } 116 117 public Collection<Discussion> getDiscussionsByUserId() { 118 return discussionsByUserId; 119 } 120 121 public void setDiscussionsByUserId(Collection<Discussion> discussionsByUserId) { 122 this.discussionsByUserId = discussionsByUserId; 123 } 124 125 public Collection<MovieLikesEntity> getMovieLikesByUserId() { 126 return movieLikesByUserId; 127 } 128 129 public void setMovieLikesByUserId(Collection<MovieLikesEntity> movieLikesByUserId) { 130 this.movieLikesByUserId = movieLikesByUserId; 131 } 132 133 public Collection<MovieRatesEntity> getMovieRatesByUserId() { 134 return movieRatesByUserId; 135 } 136 137 public void setMovieRatesByUserId(Collection<MovieRatesEntity> movieRatesByUserId) { 138 this.movieRatesByUserId = movieRatesByUserId; 139 } 140 141 public Collection<PersonRatesEntity> getPersonRatesByUserId() { 142 return personRatesByUserId; 143 } 144 145 public void setPersonRatesByUserId(Collection<PersonRatesEntity> personRatesByUserId) { 146 this.personRatesByUserId = personRatesByUserId; 147 } 148 149 public Collection<Reply> getRepliesByUserId() { 150 return repliesByUserId; 151 } 152 153 public void setRepliesByUserId(Collection<Reply> repliesByUserId) { 154 this.repliesByUserId = repliesByUserId; 155 } 156 157 public Collection<UserGenresEntity> getUserGenresByUserId() { 158 return userGenresByUserId; 159 } 160 161 public void setUserGenresByUserId(Collection<UserGenresEntity> userGenresByUserId) { 162 this.userGenresByUserId = userGenresByUserId; 40 163 } 41 164 } -
src/main/java/com/wediscussmovies/project/repository/DiscussionRepository.java
r7fafead r2d57cad 5 5 import org.springframework.stereotype.Repository; 6 6 7 import java.util.List;8 9 7 @Repository 10 8 public interface DiscussionRepository extends JpaRepository<Discussion, Integer> { 11 public List<Discussion> findAllByTitleLike(String title);12 9 } -
src/main/java/com/wediscussmovies/project/repository/GenreRepository.java
r7fafead r2d57cad 5 5 import org.springframework.stereotype.Repository; 6 6 7 import java.util.List;8 9 7 @Repository 10 8 public interface GenreRepository extends JpaRepository<Genre, Integer> { 11 public List<Genre> findAllByGenre(String genre_type);12 9 } -
src/main/java/com/wediscussmovies/project/repository/PersonRepository.java
r7fafead r2d57cad 2 2 3 3 import com.wediscussmovies.project.model.Person; 4 import com.wediscussmovies.project.model.enumerations.PersonType;5 4 import org.springframework.data.jpa.repository.JpaRepository; 6 import org.springframework.data.jpa.repository.Query;7 5 import org.springframework.stereotype.Repository; 8 9 import java.util.List;10 import java.util.Optional;11 6 12 7 @Repository 13 8 public interface PersonRepository extends JpaRepository<Person, Integer> { 14 public List<Person> findAllByPersonType(PersonType type);15 public List<Person> findAllByPersonTypeAndNameLike(PersonType type, String name);16 public List<Person> findAllByPersonTypeAndSurnameLike(PersonType type, String surname);17 public Optional<Person> findPersonByPerson_idAndPersonType(Integer id, PersonType type);18 9 } -
src/main/java/com/wediscussmovies/project/repository/UserRepository.java
r7fafead r2d57cad 5 5 import org.springframework.stereotype.Repository; 6 6 7 import java.util.EnumMap;8 import java.util.Optional;9 10 7 @Repository 11 8 public interface UserRepository extends JpaRepository<User, Integer> { 12 public Optional<User> findByEmailAndPassword(String email, String password);13 public Optional<User> findByUsernameAndPassword(String email, String password);14 public Optional<User> findByUsername(String username);15 public Optional<User> findByEmail(String email);16 9 } -
src/main/java/com/wediscussmovies/project/service/DiscussionService.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.service; 2 2 3 import com.wediscussmovies.project.model.Discussion;4 5 import java.util.List;6 import java.util.Optional;7 8 3 public interface DiscussionService { 9 List<Discussion> listAll();10 List<Discussion> listAllByTitle(String title);11 Optional<Discussion> findById(Integer id);12 void save(Discussion discussion);13 4 } -
src/main/java/com/wediscussmovies/project/service/GenreService.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.service; 2 2 3 import com.wediscussmovies.project.model.Genre;4 import org.springframework.stereotype.Service;5 6 import java.util.List;7 import java.util.Optional;8 9 @Service10 3 public interface GenreService { 11 public List<Genre> findAll();12 public Optional<Genre> findById(Integer id);13 public List<Genre> findAllByType(String genre);14 public Genre save(String genreName);15 4 } -
src/main/java/com/wediscussmovies/project/service/MovieService.java
r7fafead r2d57cad 4 4 5 5 import java.util.List; 6 import java.util.Optional;7 6 8 7 public interface MovieService { 9 8 public List<Movie> listAll(); 10 9 public List<Movie> searchByTitle(String title); 11 public Optional<Movie> findById(Long id);12 public Movie save(Movie movie);13 public void deleteById(Long id);14 10 } -
src/main/java/com/wediscussmovies/project/service/PersonService.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.service; 2 2 3 import com.wediscussmovies.project.model.Person;4 5 import java.util.List;6 import java.util.Optional;7 8 3 public interface PersonService { 9 List<Person> findAllDirectors();10 List<Person> findAllActors();11 Optional<Person> findById(Integer person_id);12 Optional<Person> findActorById(Integer id);13 Optional<Person> findDirectorById(Integer id);14 boolean save(Person person);15 List<Person> findActorsByNameLike(String name);16 List<Person> findActorsBySurnameLike(String surname);17 List<Person> findDirectorsByNameLike(String name);18 List<Person> findDirectorsBySurnameLike(String surname);19 20 4 } -
src/main/java/com/wediscussmovies/project/service/ReplyService.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.service; 2 2 3 import com.wediscussmovies.project.model.Reply;4 5 import java.util.Optional;6 7 3 public interface ReplyService { 8 public Reply save(Reply r);9 public void delete(Reply r);10 Optional<Reply> findById(Long id);11 12 4 } -
src/main/java/com/wediscussmovies/project/service/UserService.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.service; 2 2 3 import com.wediscussmovies.project.model.User;4 5 import javax.servlet.http.HttpServletRequest;6 import java.util.Optional;7 8 3 public interface UserService { 9 public Optional<User> login(String email, String password);10 public Optional<User> register(HttpServletRequest request, String email, String password, String confirmPassword, String username, String name, String surname);11 4 } -
src/main/java/com/wediscussmovies/project/service/impl/MovieServiceImpl.java
r7fafead r2d57cad 7 7 8 8 import java.util.List; 9 import java.util.Optional;10 9 11 10 @Service … … 23 22 24 23 @Override 25 public Optional<Movie> findById(Long id) {26 return movieRepository.findById(1);27 }28 29 @Override30 public Movie save(Movie movie) {31 return movieRepository.save(movie);32 }33 34 @Override35 public void deleteById(Long id) {36 movieRepository.deleteById(0);37 }38 39 @Override40 24 public List<Movie> searchByTitle(String title) { 41 25 return movieRepository.findAllByTitleLike("%"+title+"%"); 42 26 } 43 27 } 44 45 -
src/main/java/com/wediscussmovies/project/web/controller/DiscussionsController.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.web.controller; 2 2 3 import com.wediscussmovies.project.model.*;4 import com.wediscussmovies.project.model.enumerations.DiscussionType;5 import com.wediscussmovies.project.service.DiscussionService;6 import com.wediscussmovies.project.service.MovieService;7 import com.wediscussmovies.project.service.PersonService;8 import com.wediscussmovies.project.service.ReplyService;9 3 import org.springframework.stereotype.Controller; 10 import org.springframework.ui.Model;11 import org.springframework.web.bind.annotation.*;12 13 import javax.servlet.http.HttpServletRequest;14 import java.sql.Date;15 import java.time.LocalDate;16 import java.util.ArrayList;17 import java.util.List;18 import java.util.Optional;19 4 20 5 @Controller 21 @RequestMapping("/discussions")22 6 public class DiscussionsController { 23 private final DiscussionService discussionService;24 private final ReplyService replyService;25 private final MovieService movieService;26 private final PersonService personService;27 public DiscussionsController(DiscussionService discussionService, ReplyService replyService, MovieService movieService, PersonService personService) {28 this.discussionService = discussionService;29 this.replyService = replyService;30 this.movieService = movieService;31 this.personService = personService;32 }33 34 @GetMapping("/")35 public String getDiscussions(@RequestParam(required = false) String titleSearch,36 Model model){37 List<Discussion> discussions = discussionService.listAll();38 if(titleSearch != null && !titleSearch.isEmpty()){39 discussions = discussionService.listAllByTitle(titleSearch);40 }41 model.addAttribute("discussions", discussions);42 model.addAttribute("contentTemplate", "discussionsList");43 return "template";44 }45 46 @GetMapping("/{id}")47 public String getDiscussion(48 @PathVariable Integer id,49 Model model){50 Optional<Discussion> discussion = discussionService.findById(id);51 if(discussion.isEmpty())52 return "redirect:/discussions";53 model.addAttribute("discussion", discussion);54 model.addAttribute("contentTemplate", "discussionsDiscussion");55 return "template";56 }57 58 @GetMapping("/{id}/reply")59 public String getReplyToDiscussion(60 @PathVariable Integer id,61 Model model){62 Optional<Discussion> discussion = discussionService.findById(id);63 if(discussion.isEmpty())64 return "redirect:/discussions";65 model.addAttribute("discussion", discussion);66 model.addAttribute("contentTemplate", "discussionsReply");67 return "template";68 }69 @PostMapping("/{id}/reply/confirm")70 public String getReplyToDiscussionConfirm(71 @PathVariable Integer id,72 @RequestParam String text,73 HttpServletRequest request){74 Optional<Discussion> discussion = discussionService.findById(id);75 User user = (User) request.getSession().getAttribute("user");76 if(user == null){77 return "redirect:/login";78 }79 Date date = Date.valueOf(LocalDate.now());80 if(discussion.isEmpty())81 return "redirect:/discussions";82 Reply reply = new Reply(discussion.get(), user, date, text);83 replyService.save(reply);84 return "redirect:/discussions/"+id;85 }86 87 @GetMapping("/movies/add/{id}")88 public String getAddDiscussionForMovie(Model model,89 @PathVariable Integer id,90 HttpServletRequest request){91 model.addAttribute("contentTemplate", "discussionsAdd");92 request.setAttribute("movieId", id);93 return "template";94 }95 96 @PostMapping("/movies/add/confirm")97 public String getAddDiscussionMovieConfirm(Model model,98 HttpServletRequest request,99 @RequestParam String title,100 @RequestParam String text){101 User user = (User) request.getSession().getAttribute("user");102 if(user == null){103 return "redirect:/login";104 }105 Long movie_id = (Long) request.getSession().getAttribute("movieId");106 request.getSession().setAttribute("movieId", null);107 Optional<Movie> movieOp = movieService.findById(movie_id);108 if(movieOp.isEmpty())109 return "redirect:/movies";110 Discussion discussion = new Discussion(DiscussionType.M,text, title, Date.valueOf(LocalDate.now()),user,movieOp.get(),null,new ArrayList<>());111 discussionService.save(discussion);112 return "redirect:/discussions";113 }114 115 116 @GetMapping("/persons/add/{id}")117 public String getAddDiscussionForPerson(Model model,118 @PathVariable Integer id,119 HttpServletRequest request){120 model.addAttribute("contentTemplate", "discussionsAdd");121 request.setAttribute("personId", id);122 return "template";123 }124 125 @PostMapping("/persons/add/confirm")126 public String getAddDiscussionForPersonConfirm(Model model,127 HttpServletRequest request,128 @RequestParam String title,129 @RequestParam String text){130 User user = (User) request.getSession().getAttribute("user");131 if(user == null){132 return "redirect:/login";133 }134 Integer person_id = (Integer) request.getSession().getAttribute("personId");135 Optional<Person> personOp = personService.findById(person_id);136 request.getSession().setAttribute("personId", null);137 if(personOp.isEmpty())138 return "redirect:/discussions";139 Discussion discussion = new Discussion(DiscussionType.P,title, text,Date.valueOf(LocalDate.now()),user,null,personOp.get(),new ArrayList<>());140 discussionService.save(discussion);141 return "redirect:/discussions";142 }143 144 145 7 } -
src/main/java/com/wediscussmovies/project/web/controller/MovieController.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.web.controller; 2 2 3 import com.wediscussmovies.project.exception.MovieIdNotFoundException;4 import com.wediscussmovies.project.model.Genre;5 3 import com.wediscussmovies.project.model.Movie; 6 import com.wediscussmovies.project.model.Person;7 import com.wediscussmovies.project.service.GenreService;8 4 import com.wediscussmovies.project.service.MovieService; 9 import com.wediscussmovies.project.service.PersonService;10 5 import org.springframework.stereotype.Controller; 11 6 import org.springframework.ui.Model; 12 import org.springframework.web.bind.annotation.*; 7 import org.springframework.web.bind.annotation.GetMapping; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestParam; 13 10 14 import java.sql.Date;15 import java.util.LinkedList;16 11 import java.util.List; 17 import java.util.Optional;18 12 19 13 @Controller … … 21 15 public class MovieController { 22 16 private final MovieService movieService; 23 private final GenreService genreService;24 private final PersonService personService;25 17 26 public MovieController(MovieService movieService , GenreService genreService, PersonService personService) {18 public MovieController(MovieService movieService) { 27 19 this.movieService = movieService; 28 this.genreService = genreService;29 this.personService = personService;30 20 } 31 21 … … 39 29 movies = movieService.searchByTitle(titleQuery); 40 30 } 41 42 movies.sort(Movie.comparatorTitle);43 44 31 model.addAttribute("movies", movies); 45 32 model.addAttribute("contentTemplate", "moviesList"); … … 47 34 } 48 35 49 50 @GetMapping("/add")51 public String addMovie(Model model){52 model.addAttribute("directors", personService.findAllDirectors());53 model.addAttribute("actors", personService.findAllActors());54 model.addAttribute("genres", genreService.findAll());55 model.addAttribute("contentTemplate", "moviesAdd");56 return "template";57 }58 59 60 @PostMapping("/{id}/delete")61 public String addMovie(@PathVariable Long id){62 Optional<Movie> movie = movieService.findById(id);63 if(movie.isPresent()){64 movieService.deleteById(movie.get().getId());65 }66 return "redirect:/movies";67 }68 69 @PostMapping("/add/confirm")70 public String addMoviePost(@RequestParam String title,71 @RequestParam String description,72 @RequestParam String image_url,73 @RequestParam Date airing_date,74 @RequestParam Double rating,75 @RequestParam Integer director_id,76 @RequestParam List<Integer> actors,77 @RequestParam List<Integer> genres,78 Model model){79 if(title == null || title.isEmpty() ||80 description == null || description.isEmpty() ||81 image_url == null || image_url.isEmpty() ||82 airing_date == null ||83 rating == null ||84 director_id == null ||85 actors == null || actors.size() == 0 ||86 genres == null || genres.size() == 0)87 {88 model.addAttribute("error", "Not enough attributes, make sure all values are inputted, all of them are required");89 model.addAttribute("hasError", true);90 return "redirect:/add";91 }92 List<Person> actorsList = new LinkedList<>();93 for(Integer id: actors){94 Optional<Person> person = personService.findActorById(id);95 if(person.isEmpty()){96 model.addAttribute("error", "The actor with ID {" + id + "} was not found.");97 model.addAttribute("hasError", true);98 return "redirect:/add";99 }100 actorsList.add(person.get());101 }102 103 List<Genre> genreList = new LinkedList<>();104 for(Integer id: genres){105 Optional<Genre> genre = genreService.findById(id);106 if(genre.isEmpty()){107 model.addAttribute("error", "The genre with ID {" + id + "} was not found.");108 model.addAttribute("hasError", true);109 return "redirect:/add";110 }111 genreList.add(genre.get());112 }113 114 Optional<Person> directorOp = personService.findDirectorById(director_id);115 if(directorOp.isEmpty()){116 model.addAttribute("error", "The director with ID {" + director_id + "} was not found.");117 model.addAttribute("hasError", true);118 return "redirect:/add";119 }120 121 Person director = directorOp.get();122 123 Movie movie = new Movie(title, description, image_url, airing_date,124 rating, director, actorsList, genreList);125 126 movieService.save(movie);127 128 return "redirect:/movies";129 }130 131 @PostMapping("/edit/confirm")132 public String editMoviePost(133 @RequestParam Long movie_id,134 @RequestParam String title,135 @RequestParam String description,136 @RequestParam String image_url,137 @RequestParam Date airing_date,138 @RequestParam Double rating,139 @RequestParam Integer director_id,140 @RequestParam List<Integer> actors,141 @RequestParam List<Integer> genres,142 Model model){143 if(144 movie_id == null ||145 title == null || title.isEmpty() ||146 description == null || description.isEmpty() ||147 image_url == null || image_url.isEmpty() ||148 airing_date == null ||149 rating == null ||150 director_id == null ||151 actors == null || actors.size() == 0 ||152 genres == null || genres.size() == 0)153 {154 model.addAttribute("error", "Not enough attributes, make sure all values are inputted, all of them are required");155 model.addAttribute("hasError", true);156 return "redirect:/edit";157 }158 159 Optional<Movie> movieOptional = movieService.findById(movie_id);160 if(movieOptional.isEmpty()){161 model.addAttribute("error", "The movie with ID {" + movie_id + "} was not found.");162 model.addAttribute("hasError", true);163 return "redirect:/edit";164 }165 Movie movie = movieOptional.get();166 167 List<Person> actorsList = new LinkedList<>();168 for(Integer id: actors){169 Optional<Person> person = personService.findActorById(id);170 if(person.isEmpty()){171 model.addAttribute("error", "The actor with ID {" + id + "} was not found.");172 model.addAttribute("hasError", true);173 return "redirect:/edit";174 }175 actorsList.add(person.get());176 }177 178 List<Genre> genreList = new LinkedList<>();179 for(Integer id: genres){180 Optional<Genre> genre = genreService.findById(id);181 if(genre.isEmpty()){182 model.addAttribute("error", "The genre with ID {" + id + "} was not found.");183 model.addAttribute("hasError", true);184 return "redirect:/edit";185 }186 genreList.add(genre.get());187 }188 189 Optional<Person> directorOp = personService.findDirectorById(director_id);190 if(directorOp.isEmpty()){191 model.addAttribute("error", "The director with ID {" + director_id + "} was not found.");192 model.addAttribute("hasError", true);193 return "redirect:/edit";194 }195 196 Person director = directorOp.get();197 198 movieService.deleteById(movie_id);199 200 movie.setActors(actorsList);201 movie.setDirector(director);202 movie.setGenres(genreList);203 movie.setTitle(title);204 movie.setDescription(description);205 movie.setAringDate(airing_date);206 movie.setImageUrl(image_url);207 movie.setImbdRating(rating);208 209 movieService.save(movie);210 211 return "redirect:/movies";212 }213 214 @GetMapping("/{id}/edit")215 public String editMovie(@PathVariable Long id, Model model){216 Movie movie = movieService.findById(id).orElseThrow(() -> new MovieIdNotFoundException(id));217 model.addAttribute("directors", personService.findAllDirectors());218 model.addAttribute("actors", personService.findAllActors());219 model.addAttribute("genres", genreService.findAll());220 model.addAttribute("movie", movie);221 model.addAttribute("contentTemplate", "moviesEdit");222 return "template";223 }224 36 } -
src/main/java/com/wediscussmovies/project/web/controller/UserController.java
r7fafead r2d57cad 1 1 package com.wediscussmovies.project.web.controller; 2 2 3 import com.wediscussmovies.project.model.PasswordEncoder;4 import com.wediscussmovies.project.model.User;5 import com.wediscussmovies.project.model.exception.InvalidUserCredentialsException;6 import com.wediscussmovies.project.service.UserService;7 3 import org.springframework.stereotype.Controller; 8 import org.springframework.ui.Model;9 import org.springframework.web.bind.annotation.GetMapping;10 import org.springframework.web.bind.annotation.PostMapping;11 import org.springframework.web.bind.annotation.RequestMapping;12 import org.springframework.web.bind.annotation.RequestParam;13 14 import javax.servlet.http.HttpServletRequest;15 import java.security.NoSuchAlgorithmException;16 import java.util.Optional;17 4 18 5 @Controller 19 @RequestMapping("/")20 6 public class UserController { 21 private final UserService userService;22 23 public UserController(UserService userService) {24 this.userService = userService;25 }26 27 @GetMapping("/login")28 public String getLoginPage(Model model){29 return "login";30 }31 32 @PostMapping("/login/confirm")33 public String confirmLogin(HttpServletRequest request, Model model,34 @RequestParam String username,35 @RequestParam String password){36 Optional<User> user;37 try{38 password = PasswordEncoder.getEncodedPasswordString(password);39 }40 catch (NoSuchAlgorithmException ex){41 model.addAttribute("hasError", true);42 model.addAttribute("error", ex.getMessage());43 return "login";44 }45 46 try{47 user = this.userService.login(username, password);48 request.getSession().setAttribute("user", user);49 request.getSession().setAttribute("loggedIn",true);50 return "redirect:/movies";51 }52 catch (InvalidUserCredentialsException ex){53 model.addAttribute("hasError", true);54 model.addAttribute("error", ex.getMessage());55 return "login";56 }57 }58 59 @GetMapping("/register")60 public String getRegisterPage(){61 return "register";62 }63 64 @PostMapping("/login/confirm")65 public String confirmRegister(HttpServletRequest request,66 @RequestParam String username,67 @RequestParam String email,68 @RequestParam String password,69 @RequestParam String confirmPassword,70 @RequestParam String name,71 @RequestParam String surname){72 Optional<User> user;73 74 try{75 password = PasswordEncoder.getEncodedPasswordString(password);76 confirmPassword = PasswordEncoder.getEncodedPasswordString(confirmPassword);77 }78 catch (NoSuchAlgorithmException ex){79 request.getSession().setAttribute("error", "Contact the administrators!");80 request.getSession().setAttribute("hasError", "true");81 return "redirect:/movies";82 }83 84 user = this.userService.register(request, email, password, confirmPassword, username, name, surname);85 if(user.isEmpty()){86 request.setAttribute("hasError", "true");87 }else{88 request.getSession().setAttribute("hasError", "false");89 request.getSession().setAttribute("user", user.get());90 request.getSession().setAttribute("loggedIn",true);91 }92 return "redirect:/movies";93 }94 95 @GetMapping96 public String logout(HttpServletRequest request){97 request.getSession().invalidate();98 return "redirect:/login";99 }100 7 } -
target/classes/application-prod.properties
r7fafead r2d57cad 1 1 spring.datasource.url=jdbc:postgresql://localhost:5432/db_202122z_va_prj_wediscussmovies 2 spring.datasource.username=db_202122z_va_prj_wediscussmovies_owner _1931132 spring.datasource.username=db_202122z_va_prj_wediscussmovies_owner 3 3 spring.datasource.password=7d8fb26b5697 4 4
Note:
See TracChangeset
for help on using the changeset viewer.