Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/com/example/demo/models/BlogPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ public class BlogPost {
private Long id;
private String title;
private String imageUrl;
@OneToOne(cascade = CascadeType.ALL)
private Recipe recipe;
@ManyToOne(cascade = CascadeType.ALL)
@JsonIgnore
private User user;

public BlogPost() {
}

public BlogPost(Long id, String title, String imageUrl, User user) {
public BlogPost(Long id, String title, String imageUrl, Recipe recipe, User user) {
this.id = id;
this.title = title;
this.imageUrl = imageUrl;
this.recipe = recipe;
this.user = user;
}

Expand Down Expand Up @@ -51,6 +54,10 @@ public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public Recipe getRecipe() { return recipe; }

public void setRecipe(Recipe recipe) { this.recipe = recipe; }

public User getUser() { return user; }

public void setUser(User user) { this.user = user; }
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/example/demo/models/Recipe.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.example.demo.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;

@Entity
public class Recipe {
Expand All @@ -14,16 +12,20 @@ public class Recipe {
private String name;
private String ingredients;
private String instructions;
@OneToOne(cascade = CascadeType.ALL)
@JsonIgnore
private BlogPost blogPost;


public Recipe() {
}

public Recipe(Long id, String name, String ingredients, String instructions) {
public Recipe(Long id, String name, String ingredients, String instructions, BlogPost blogPost) {
this.id = id;
this.name = name;
this.ingredients = ingredients;
this.instructions = instructions;
this.blogPost = blogPost;
}

public Long getId() {
Expand Down Expand Up @@ -57,4 +59,8 @@ public String getInstructions() {
public void setInstructions(String instructions) {
this.instructions = instructions;
}

public BlogPost getBlogPost() { return blogPost; }

public void setBlogPost(BlogPost blogPost) { this.blogPost = blogPost; }
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/demo/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public List<User> readAll(){
Iterable<User> userIterable = repository.findAll();
List<User> result = new ArrayList<>();
userIterable.forEach(result::add);
for(User user : result) {
user.setBlogPostList(blogPostRepository.findByUser(user.getId()));
}
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/blogdatabase
spring.datasource.username=jen
spring.datasource.password=zipcode0
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
2 changes: 1 addition & 1 deletion target/classes/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/blogdatabase
spring.datasource.username=jen
spring.datasource.password=zipcode0
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
Binary file modified target/classes/com/example/demo/models/BlogPost.class
Binary file not shown.
Binary file modified target/classes/com/example/demo/models/Recipe.class
Binary file not shown.
Binary file modified target/classes/com/example/demo/repository/RecipeRepository.class
Binary file not shown.
Binary file modified target/classes/com/example/demo/repository/TagRepository.class
Binary file not shown.
Binary file modified target/classes/com/example/demo/service/UserService.class
Binary file not shown.