package app.mealsmadeeasy.api.recipe.view; import app.mealsmadeeasy.api.image.view.ImageView; import app.mealsmadeeasy.api.recipe.Recipe; import app.mealsmadeeasy.api.user.view.UserInfoView; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Builder; import lombok.Value; import org.jetbrains.annotations.Nullable; import java.time.OffsetDateTime; @Value @Builder public class FullRecipeView { public static FullRecipeView from( Recipe recipe, String renderedText, boolean includeRawText, int starCount, int viewerCount, @Nullable ImageView mainImage ) { final var b = FullRecipeView.builder() .id(recipe.getId()) .created(recipe.getCreated()) .modified(recipe.getModified()) .slug(recipe.getSlug()) .title(recipe.getTitle()) .preparationTime(recipe.getPreparationTime()) .cookingTime(recipe.getCookingTime()) .totalTime(recipe.getTotalTime()) .text(renderedText) .owner(UserInfoView.from(recipe.getOwner())) .starCount(starCount) .viewerCount(viewerCount) .mainImage(mainImage) .isPublic(recipe.getIsPublic()); if (includeRawText) { b.rawText(recipe.getRawText()); } return b.build(); } Integer id; OffsetDateTime created; @Nullable OffsetDateTime modified; String slug; String title; @Nullable Integer preparationTime; @Nullable Integer cookingTime; @Nullable Integer totalTime; String text; @Nullable String rawText; UserInfoView owner; int starCount; int viewerCount; @Nullable ImageView mainImage; boolean isPublic; @JsonInclude(JsonInclude.Include.NON_NULL) public @Nullable String getRawText() { return this.rawText; } }