Skip to content

Commit

Permalink
POST /Upvote response formatted.
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesBaserr committed May 17, 2024
1 parent 3d67b47 commit 30fb14c
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 18 deletions.
20 changes: 18 additions & 2 deletions backend/src/main/java/com/group1/cuisines/entities/Bookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import jakarta.persistence.*;
import lombok.*;

@Data
@Builder
import java.util.Objects;

@Getter
@Setter
@Builder

@NoArgsConstructor
@AllArgsConstructor
@Entity
Expand All @@ -22,4 +25,17 @@ public class Bookmark {
@ManyToOne
@JoinColumn(name = "recipe_id", nullable = false)
private Recipe recipe;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Bookmark recipe = (Bookmark) o;
return Objects.equals(id, recipe.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
21 changes: 20 additions & 1 deletion backend/src/main/java/com/group1/cuisines/entities/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import jakarta.persistence.*;
import lombok.*;
import org.apache.commons.lang3.builder.ToStringExclude;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Objects;
import java.util.Set;

@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -18,8 +21,10 @@ public class Comment {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;


@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
@ToString.Exclude
private User user;

@ManyToOne
Expand All @@ -37,4 +42,18 @@ public class Comment {
private Set<Upvote> upvotes;

private int upvoteCount;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Comment recipe = (Comment) o;
return Objects.equals(id, recipe.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

import java.net.URL;
import java.util.ArrayList;
Expand All @@ -14,7 +11,8 @@
import java.util.Set;


@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down
8 changes: 3 additions & 5 deletions backend/src/main/java/com/group1/cuisines/entities/Dish.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import jakarta.persistence.*;
import lombok.*;

@Data
import java.util.Objects;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -18,4 +21,16 @@ public class Ingredient {
@ManyToOne
@JoinColumn(name = "recipe_id") // This column in the Ingredient table will hold the foreign key to the Recipe
private Recipe recipe; // This is the 'recipe' field expected by the 'mappedBy' attribute
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ingredient recipe = (Ingredient) o;
return Objects.equals(id, recipe.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
18 changes: 17 additions & 1 deletion backend/src/main/java/com/group1/cuisines/entities/Rating.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import jakarta.persistence.*;
import lombok.*;

@Data
import java.util.Objects;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -23,4 +26,17 @@ public class Rating {
private Recipe recipe;

private int ratingValue; // Assuming ratings are integer values

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Rating recipe = (Rating) o;
return Objects.equals(id, recipe.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
17 changes: 16 additions & 1 deletion backend/src/main/java/com/group1/cuisines/entities/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -39,6 +41,7 @@ public class Recipe {
private Date createdAt;

@ManyToOne
@ToString.Exclude
@JoinColumn(name = "user_id", nullable = false)
private User user;
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
Expand All @@ -49,6 +52,18 @@ public class Recipe {
@CollectionTable(name = "recipe_allergens", joinColumns = @JoinColumn(name = "recipe_id"))
@Column(name = "allergen")
private List<String> allergens = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Recipe recipe = (Recipe) o;
return Objects.equals(id, recipe.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
Expand Down
17 changes: 16 additions & 1 deletion backend/src/main/java/com/group1/cuisines/entities/Upvote.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import lombok.*;

import java.time.LocalDateTime;
import java.util.Objects;

@Data
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -24,4 +26,17 @@ public class Upvote {
@ManyToOne
@JoinColumn(name = "comment_id", nullable = false)
private Comment comment;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Upvote upvote = (Upvote) o;
return Objects.equals(id, upvote.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

}
3 changes: 2 additions & 1 deletion backend/src/main/java/com/group1/cuisines/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Objects;
import java.util.Set;

@Data

@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -80,6 +80,7 @@ public boolean equals(Object obj) {
return Objects.equals(id, other.id); // Compare only IDs for equality
}


@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public UpvoteDto upvote(Integer commentId, String username) {
upvoteRepository.save(upvote);

comment.setUpvoteCount(comment.getUpvoteCount()+1);
comment.getUpvotes().add(upvote);
commentRepository.save(comment);
return new UpvoteDto().builder()
.id(upvote.getId())
Expand Down

0 comments on commit 30fb14c

Please sign in to comment.