Loading rating-microservice/README.md +12 −4 Original line number Diff line number Diff line Loading @@ -117,12 +117,20 @@ In order to clear or seed the dockerized ratings database, you can run the follo To clear run the following command (from the repo root, or change the sqeal file's path) (substitute your credentials accordingly): ```bash docker cp ./sql/clear_rating_database.sql rating-postgres:/ && \ docker exec -it rating-postgres psql -U rating_user -d rating_database -p 5432 -a -f ./clear_rating_database.sql # Copy the SQL script to the Docker container docker cp ./sql/clear_rating_database.sql rating_postgres:/clear_rating_database.sql # Execute the SQL script inside the Docker container docker exec -it rating_postgres psql -U rating_user -d rating_database -a -f /clear_rating_database.sql ``` To seed: ```bash docker cp ./sql/seed_rating_database.sql rating-postgres:/ && \ docker exec -it rating-postgres psql -U rating_user -d rating_database -p 5432 -a -f ./seed_rating_database.sql # Copy the SQL script to the Docker container docker cp ./sql/seed_rating_database.sql rating_postgres:/seed_rating_database.sql # Execute the SQL script inside the Docker container docker exec -it rating_postgres psql -U rating_user -d rating_database -a -f /seed_rating_database.sql ``` rating-microservice/src/main/java/cz/muni/fi/iamdb/api/CommentDto.java 0 → 100644 +75 −0 Original line number Diff line number Diff line package cz.muni.fi.iamdb.api; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; import java.util.UUID; public class CommentDto { private UUID id; @JsonProperty("rating_id") private UUID ratingId; @JsonProperty("user_id") private UUID userId; private String text; public CommentDto(UUID id, UUID ratingId, UUID userId, String text) { this.id = id; this.ratingId = ratingId; this.userId = userId; this.text = text; } public CommentDto() { } public UUID getId() { return id; } public UUID getRatingId() { return ratingId; } public UUID getUserId() { return userId; } public String getText() { return text; } public void setId(UUID id) { this.id = id; } public void setRatingId(UUID ratingId) { this.ratingId = ratingId; } public void setUserId(UUID userId) { this.userId = userId; } public void setText(String text) { this.text = text; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CommentDto that = (CommentDto) o; return Objects.equals(id, that.id) && Objects.equals(ratingId, that.ratingId) && Objects.equals(userId, that.userId) && Objects.equals(text, that.text); } @Override public int hashCode() { return Objects.hash(id, ratingId, userId, text); } } rating-microservice/src/main/java/cz/muni/fi/iamdb/api/RatingDto.java +28 −19 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package cz.muni.fi.iamdb.api; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.Objects; import java.util.UUID; public class RatingDto { Loading @@ -13,18 +15,20 @@ public class RatingDto { private UUID userId; private Double score; private String review; private List<CommentDto> comments; public RatingDto(UUID id, UUID movieId, UUID userId, Double score, String review) { public RatingDto(UUID id, UUID movieId, UUID userId, Double score, String review, List<CommentDto> comments) { this.id = id; this.movieId = movieId; this.userId = userId; this.score = score; this.review = review; this.comments = comments; } public RatingDto() { public RatingDto() {} } // Getters and setters public UUID getId() { return id; Loading Loading @@ -69,24 +73,29 @@ public class RatingDto { this.review = review; } @Override public boolean equals(Object o){ if (this == o) { return true; public List<CommentDto> getComments() { return comments; } if (!(o instanceof RatingDto ratingDto)) { return false; public void setComments(List<CommentDto> comments) { this.comments = comments; } return getId().equals(ratingDto.getId()); @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RatingDto ratingDto = (RatingDto) o; return Objects.equals(id, ratingDto.id) && Objects.equals(movieId, ratingDto.movieId) && Objects.equals(userId, ratingDto.userId) && Objects.equals(score, ratingDto.score) && Objects.equals(review, ratingDto.review) && Objects.equals(comments, ratingDto.comments); } @Override public String toString() { return "RatingDto{" + "id=" + id + ", movieId=" + movieId + ", userId=" + userId + ", score=" + score + ", review='" + review + '\'' + '}'; public int hashCode() { return Objects.hash(id, movieId, userId, score, review, comments); } } rating-microservice/src/main/java/cz/muni/fi/iamdb/data/model/Comment.java 0 → 100644 +71 −0 Original line number Diff line number Diff line package cz.muni.fi.iamdb.data.model; import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; import java.io.Serializable; import java.util.UUID; @Entity @Table(name = "comments") public class Comment implements Serializable { @Id @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") @Column(name = "id_comment", updatable = false, nullable = false) private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "rating_id", nullable = false) private Rating rating; @Column(name = "user_id", nullable = false) private UUID userId; @Column(name = "text", nullable = false, length = 1000) private String text; public Comment() { } public Comment(UUID id, Rating rating, UUID userId, String text) { this.id = id; this.rating = rating; this.userId = userId; this.text = text; } public UUID getId() { return id; } public Rating getRating() { return rating; } public UUID getUserId() { return userId; } public String getText() { return text; } public void setId(UUID id) { this.id = id; } public void setRating(Rating rating) { this.rating = rating; } public void setUserId(UUID userId) { this.userId = userId; } public void setText(String text) { this.text = text; } } rating-microservice/src/main/java/cz/muni/fi/iamdb/data/model/Rating.java +24 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; import java.io.Serializable; import java.util.HashSet; import java.util.Objects; import java.util.Set; import java.util.UUID; @Entity Loading Loading @@ -32,6 +34,9 @@ public class Rating implements Serializable { @Column(name = "review", length = 1000) private String review; @OneToMany(mappedBy = "rating", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private Set<Comment> comments = new HashSet<>(); public Rating() { } Loading Loading @@ -83,6 +88,24 @@ public class Rating implements Serializable { this.review = review; } public Set<Comment> getComments() { return comments; } public void setComments(Set<Comment> comments) { this.comments = comments; } public void addComment(Comment comment) { comments.add(comment); comment.setRating(this); } public void removeComment(Comment comment) { comments.remove(comment); comment.setRating(null); } @Override public boolean equals(Object o) { if (this == o) return true; Loading @@ -92,7 +115,6 @@ public class Rating implements Serializable { Objects.equals(userId, rating.getUserId()); } @Override public int hashCode() { return Objects.hash(id, movieId, userId); Loading @@ -106,6 +128,7 @@ public class Rating implements Serializable { ", userId=" + userId + ", score=" + score + ", review='" + review + '\'' + ", comments=" + comments + '}'; } } Loading
rating-microservice/README.md +12 −4 Original line number Diff line number Diff line Loading @@ -117,12 +117,20 @@ In order to clear or seed the dockerized ratings database, you can run the follo To clear run the following command (from the repo root, or change the sqeal file's path) (substitute your credentials accordingly): ```bash docker cp ./sql/clear_rating_database.sql rating-postgres:/ && \ docker exec -it rating-postgres psql -U rating_user -d rating_database -p 5432 -a -f ./clear_rating_database.sql # Copy the SQL script to the Docker container docker cp ./sql/clear_rating_database.sql rating_postgres:/clear_rating_database.sql # Execute the SQL script inside the Docker container docker exec -it rating_postgres psql -U rating_user -d rating_database -a -f /clear_rating_database.sql ``` To seed: ```bash docker cp ./sql/seed_rating_database.sql rating-postgres:/ && \ docker exec -it rating-postgres psql -U rating_user -d rating_database -p 5432 -a -f ./seed_rating_database.sql # Copy the SQL script to the Docker container docker cp ./sql/seed_rating_database.sql rating_postgres:/seed_rating_database.sql # Execute the SQL script inside the Docker container docker exec -it rating_postgres psql -U rating_user -d rating_database -a -f /seed_rating_database.sql ```
rating-microservice/src/main/java/cz/muni/fi/iamdb/api/CommentDto.java 0 → 100644 +75 −0 Original line number Diff line number Diff line package cz.muni.fi.iamdb.api; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; import java.util.UUID; public class CommentDto { private UUID id; @JsonProperty("rating_id") private UUID ratingId; @JsonProperty("user_id") private UUID userId; private String text; public CommentDto(UUID id, UUID ratingId, UUID userId, String text) { this.id = id; this.ratingId = ratingId; this.userId = userId; this.text = text; } public CommentDto() { } public UUID getId() { return id; } public UUID getRatingId() { return ratingId; } public UUID getUserId() { return userId; } public String getText() { return text; } public void setId(UUID id) { this.id = id; } public void setRatingId(UUID ratingId) { this.ratingId = ratingId; } public void setUserId(UUID userId) { this.userId = userId; } public void setText(String text) { this.text = text; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CommentDto that = (CommentDto) o; return Objects.equals(id, that.id) && Objects.equals(ratingId, that.ratingId) && Objects.equals(userId, that.userId) && Objects.equals(text, that.text); } @Override public int hashCode() { return Objects.hash(id, ratingId, userId, text); } }
rating-microservice/src/main/java/cz/muni/fi/iamdb/api/RatingDto.java +28 −19 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ package cz.muni.fi.iamdb.api; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.Objects; import java.util.UUID; public class RatingDto { Loading @@ -13,18 +15,20 @@ public class RatingDto { private UUID userId; private Double score; private String review; private List<CommentDto> comments; public RatingDto(UUID id, UUID movieId, UUID userId, Double score, String review) { public RatingDto(UUID id, UUID movieId, UUID userId, Double score, String review, List<CommentDto> comments) { this.id = id; this.movieId = movieId; this.userId = userId; this.score = score; this.review = review; this.comments = comments; } public RatingDto() { public RatingDto() {} } // Getters and setters public UUID getId() { return id; Loading Loading @@ -69,24 +73,29 @@ public class RatingDto { this.review = review; } @Override public boolean equals(Object o){ if (this == o) { return true; public List<CommentDto> getComments() { return comments; } if (!(o instanceof RatingDto ratingDto)) { return false; public void setComments(List<CommentDto> comments) { this.comments = comments; } return getId().equals(ratingDto.getId()); @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; RatingDto ratingDto = (RatingDto) o; return Objects.equals(id, ratingDto.id) && Objects.equals(movieId, ratingDto.movieId) && Objects.equals(userId, ratingDto.userId) && Objects.equals(score, ratingDto.score) && Objects.equals(review, ratingDto.review) && Objects.equals(comments, ratingDto.comments); } @Override public String toString() { return "RatingDto{" + "id=" + id + ", movieId=" + movieId + ", userId=" + userId + ", score=" + score + ", review='" + review + '\'' + '}'; public int hashCode() { return Objects.hash(id, movieId, userId, score, review, comments); } }
rating-microservice/src/main/java/cz/muni/fi/iamdb/data/model/Comment.java 0 → 100644 +71 −0 Original line number Diff line number Diff line package cz.muni.fi.iamdb.data.model; import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; import java.io.Serializable; import java.util.UUID; @Entity @Table(name = "comments") public class Comment implements Serializable { @Id @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") @Column(name = "id_comment", updatable = false, nullable = false) private UUID id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "rating_id", nullable = false) private Rating rating; @Column(name = "user_id", nullable = false) private UUID userId; @Column(name = "text", nullable = false, length = 1000) private String text; public Comment() { } public Comment(UUID id, Rating rating, UUID userId, String text) { this.id = id; this.rating = rating; this.userId = userId; this.text = text; } public UUID getId() { return id; } public Rating getRating() { return rating; } public UUID getUserId() { return userId; } public String getText() { return text; } public void setId(UUID id) { this.id = id; } public void setRating(Rating rating) { this.rating = rating; } public void setUserId(UUID userId) { this.userId = userId; } public void setText(String text) { this.text = text; } }
rating-microservice/src/main/java/cz/muni/fi/iamdb/data/model/Rating.java +24 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,9 @@ import jakarta.persistence.*; import org.hibernate.annotations.GenericGenerator; import java.io.Serializable; import java.util.HashSet; import java.util.Objects; import java.util.Set; import java.util.UUID; @Entity Loading Loading @@ -32,6 +34,9 @@ public class Rating implements Serializable { @Column(name = "review", length = 1000) private String review; @OneToMany(mappedBy = "rating", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private Set<Comment> comments = new HashSet<>(); public Rating() { } Loading Loading @@ -83,6 +88,24 @@ public class Rating implements Serializable { this.review = review; } public Set<Comment> getComments() { return comments; } public void setComments(Set<Comment> comments) { this.comments = comments; } public void addComment(Comment comment) { comments.add(comment); comment.setRating(this); } public void removeComment(Comment comment) { comments.remove(comment); comment.setRating(null); } @Override public boolean equals(Object o) { if (this == o) return true; Loading @@ -92,7 +115,6 @@ public class Rating implements Serializable { Objects.equals(userId, rating.getUserId()); } @Override public int hashCode() { return Objects.hash(id, movieId, userId); Loading @@ -106,6 +128,7 @@ public class Rating implements Serializable { ", userId=" + userId + ", score=" + score + ", review='" + review + '\'' + ", comments=" + comments + '}'; } }