Recipe views now use UserInfoView.
This commit is contained in:
parent
577ae6824f
commit
22441a8e47
@ -66,7 +66,8 @@ public class RecipeControllerTests {
|
||||
.andExpect(jsonPath("$.slug").value(recipe.getSlug()))
|
||||
.andExpect(jsonPath("$.title").value("Test Recipe"))
|
||||
.andExpect(jsonPath("$.text").value("<h1>Hello, World!</h1>"))
|
||||
.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));
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user