diff --git a/src/integrationTest/java/app/mealsmadeeasy/api/recipe/RecipeControllerTests.java b/src/integrationTest/java/app/mealsmadeeasy/api/recipe/RecipeControllerTests.java
index 55f0ac0..65b794b 100644
--- a/src/integrationTest/java/app/mealsmadeeasy/api/recipe/RecipeControllerTests.java
+++ b/src/integrationTest/java/app/mealsmadeeasy/api/recipe/RecipeControllerTests.java
@@ -66,7 +66,8 @@ public class RecipeControllerTests {
.andExpect(jsonPath("$.slug").value(recipe.getSlug()))
.andExpect(jsonPath("$.title").value("Test Recipe"))
.andExpect(jsonPath("$.text").value("
Hello, World!
"))
- .andExpect(jsonPath("$.ownerUsername").value(owner.getUsername()))
+ .andExpect(jsonPath("$.owner.id").value(owner.getId()))
+ .andExpect(jsonPath("$.owner.username").value(owner.getUsername()))
.andExpect(jsonPath("$.starCount").value(0))
.andExpect(jsonPath("$.viewerCount").value(0))
.andExpect(jsonPath("$.isPublic").value(true));
@@ -87,7 +88,8 @@ public class RecipeControllerTests {
.andExpect(jsonPath("$.content[0].updated").exists())
.andExpect(jsonPath("$.content[0].slug").value(recipe.getSlug()))
.andExpect(jsonPath("$.content[0].title").value(recipe.getTitle()))
- .andExpect(jsonPath("$.content[0].ownerUsername").value(owner.getUsername()))
+ .andExpect(jsonPath("$.content[0].owner.id").value(owner.getId()))
+ .andExpect(jsonPath("$.content[0].owner.username").value(owner.getUsername()))
.andExpect(jsonPath("$.content[0].isPublic").value(true))
.andExpect(jsonPath("$.content[0].starCount").value(0));
}
diff --git a/src/main/java/app/mealsmadeeasy/api/recipe/RecipeServiceImpl.java b/src/main/java/app/mealsmadeeasy/api/recipe/RecipeServiceImpl.java
index e9f31d8..4967dde 100644
--- a/src/main/java/app/mealsmadeeasy/api/recipe/RecipeServiceImpl.java
+++ b/src/main/java/app/mealsmadeeasy/api/recipe/RecipeServiceImpl.java
@@ -8,6 +8,7 @@ import app.mealsmadeeasy.api.recipe.view.FullRecipeView;
import app.mealsmadeeasy.api.recipe.view.RecipeInfoView;
import app.mealsmadeeasy.api.user.User;
import app.mealsmadeeasy.api.user.UserEntity;
+import app.mealsmadeeasy.api.user.view.UserInfoView;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.jetbrains.annotations.Nullable;
@@ -106,8 +107,7 @@ public class RecipeServiceImpl implements RecipeService {
view.setSlug(recipe.getSlug());
view.setTitle(recipe.getTitle());
view.setText(this.getRenderedMarkdown(recipe));
- view.setOwnerId(recipe.getOwner().getId());
- view.setOwnerUsername(recipe.getOwner().getUsername());
+ view.setOwner(UserInfoView.from(recipe.getOwner()));
view.setStarCount(this.getStarCount(recipe));
view.setViewerCount(this.getViewerCount(recipe.getId()));
if (recipe.getMainImage() != null) {
@@ -149,7 +149,7 @@ public class RecipeServiceImpl implements RecipeService {
}
view.setSlug(entity.getSlug());
view.setTitle(entity.getTitle());
- view.setOwnerUsername(entity.getOwner().getUsername());
+ view.setOwner(UserInfoView.from(entity.getOwner()));
view.setIsPublic(entity.isPublic());
view.setStarCount(this.getStarCount(entity));
if (entity.getMainImage() != null) {
diff --git a/src/main/java/app/mealsmadeeasy/api/recipe/view/FullRecipeView.java b/src/main/java/app/mealsmadeeasy/api/recipe/view/FullRecipeView.java
index e3e8a0c..af94f04 100644
--- a/src/main/java/app/mealsmadeeasy/api/recipe/view/FullRecipeView.java
+++ b/src/main/java/app/mealsmadeeasy/api/recipe/view/FullRecipeView.java
@@ -1,6 +1,7 @@
package app.mealsmadeeasy.api.recipe.view;
import app.mealsmadeeasy.api.image.view.ImageView;
+import app.mealsmadeeasy.api.user.view.UserInfoView;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
@@ -13,8 +14,9 @@ public class FullRecipeView {
private String slug;
private String title;
private String text;
- private long ownerId;
- private String ownerUsername;
+ @Deprecated private long ownerId;
+ @Deprecated private String ownerUsername;
+ private UserInfoView owner;
private int starCount;
private int viewerCount;
private ImageView mainImage;
@@ -68,22 +70,34 @@ public class FullRecipeView {
this.text = text;
}
+ @Deprecated
public long getOwnerId() {
return this.ownerId;
}
+ @Deprecated
public void setOwnerId(long ownerId) {
this.ownerId = ownerId;
}
+ @Deprecated
public String getOwnerUsername() {
return this.ownerUsername;
}
+ @Deprecated
public void setOwnerUsername(String ownerUsername) {
this.ownerUsername = ownerUsername;
}
+ public UserInfoView getOwner() {
+ return this.owner;
+ }
+
+ public void setOwner(UserInfoView owner) {
+ this.owner = owner;
+ }
+
public int getStarCount() {
return this.starCount;
}
diff --git a/src/main/java/app/mealsmadeeasy/api/recipe/view/RecipeInfoView.java b/src/main/java/app/mealsmadeeasy/api/recipe/view/RecipeInfoView.java
index 53c06c8..ddc8698 100644
--- a/src/main/java/app/mealsmadeeasy/api/recipe/view/RecipeInfoView.java
+++ b/src/main/java/app/mealsmadeeasy/api/recipe/view/RecipeInfoView.java
@@ -1,6 +1,7 @@
package app.mealsmadeeasy.api.recipe.view;
import app.mealsmadeeasy.api.image.view.ImageView;
+import app.mealsmadeeasy.api.user.view.UserInfoView;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
@@ -11,7 +12,11 @@ public final class RecipeInfoView {
private LocalDateTime updated;
private String slug;
private String title;
+
+ @Deprecated
private String ownerUsername;
+
+ private UserInfoView owner;
private boolean isPublic;
private int starCount;
private @Nullable ImageView mainImage;
@@ -48,14 +53,24 @@ public final class RecipeInfoView {
this.title = title;
}
+ @Deprecated
public String getOwnerUsername() {
return this.ownerUsername;
}
+ @Deprecated
public void setOwnerUsername(String ownerUsername) {
this.ownerUsername = ownerUsername;
}
+ public UserInfoView getOwner() {
+ return this.owner;
+ }
+
+ public void setOwner(UserInfoView owner) {
+ this.owner = owner;
+ }
+
public boolean getIsPublic() {
return this.isPublic;
}
diff --git a/src/main/java/app/mealsmadeeasy/api/user/view/UserInfoView.java b/src/main/java/app/mealsmadeeasy/api/user/view/UserInfoView.java
index 5aa5146..c50b5cf 100644
--- a/src/main/java/app/mealsmadeeasy/api/user/view/UserInfoView.java
+++ b/src/main/java/app/mealsmadeeasy/api/user/view/UserInfoView.java
@@ -1,7 +1,16 @@
package app.mealsmadeeasy.api.user.view;
+import app.mealsmadeeasy.api.user.User;
+
public class UserInfoView {
+ public static UserInfoView from(User user) {
+ final UserInfoView userInfoView = new UserInfoView();
+ userInfoView.setId(user.getId());
+ userInfoView.setUsername(user.getUsername());
+ return userInfoView;
+ }
+
private long id;
private String username;