Added basic dev-data and loading mechanism.
This commit is contained in:
parent
c89524a989
commit
81424eb2e6
@ -60,6 +60,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'org.commonmark:commonmark:0.22.0'
|
implementation 'org.commonmark:commonmark:0.22.0'
|
||||||
implementation 'org.jsoup:jsoup:1.17.2'
|
implementation 'org.jsoup:jsoup:1.17.2'
|
||||||
|
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.2'
|
||||||
|
|
||||||
implementation 'io.minio:minio:8.5.11'
|
implementation 'io.minio:minio:8.5.11'
|
||||||
|
|
||||||
|
BIN
dev-data/images/Obazda.jpg
Normal file
BIN
dev-data/images/Obazda.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
21
dev-data/recipes/Obazda.md
Normal file
21
dev-data/recipes/Obazda.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
title: German (Bavarian) Obazda
|
||||||
|
slug: obazda
|
||||||
|
isPublic: true
|
||||||
|
mainImage:
|
||||||
|
src: images/Obazda.jpg
|
||||||
|
title: Obazda
|
||||||
|
alt: Obazda.
|
||||||
|
caption: German Obazda.
|
||||||
|
isPublic: true
|
||||||
|
---
|
||||||
|
## Ingredients
|
||||||
|
- Butter
|
||||||
|
- Camembert
|
||||||
|
- Scallions
|
||||||
|
- A few slices of red onion
|
||||||
|
- Salt and pepper
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
Mix all together until coarsely blended.
|
||||||
|
Serve cold with pretzels or other lye-type bread!
|
@ -1,7 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api;
|
package app.mealsmadeeasy.api;
|
||||||
|
|
||||||
import app.mealsmadeeasy.api.image.Image;
|
import app.mealsmadeeasy.api.image.Image;
|
||||||
import app.mealsmadeeasy.api.image.ImageException;
|
|
||||||
import app.mealsmadeeasy.api.image.ImageService;
|
import app.mealsmadeeasy.api.image.ImageService;
|
||||||
import app.mealsmadeeasy.api.image.spec.ImageCreateInfoSpec;
|
import app.mealsmadeeasy.api.image.spec.ImageCreateInfoSpec;
|
||||||
import app.mealsmadeeasy.api.recipe.Recipe;
|
import app.mealsmadeeasy.api.recipe.Recipe;
|
||||||
@ -9,6 +8,8 @@ import app.mealsmadeeasy.api.recipe.RecipeService;
|
|||||||
import app.mealsmadeeasy.api.recipe.spec.RecipeCreateSpec;
|
import app.mealsmadeeasy.api.recipe.spec.RecipeCreateSpec;
|
||||||
import app.mealsmadeeasy.api.user.User;
|
import app.mealsmadeeasy.api.user.User;
|
||||||
import app.mealsmadeeasy.api.user.UserService;
|
import app.mealsmadeeasy.api.user.UserService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
@ -16,9 +17,12 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
@ -30,58 +34,82 @@ public class DevConfiguration {
|
|||||||
private final RecipeService recipeService;
|
private final RecipeService recipeService;
|
||||||
private final ImageService imageService;
|
private final ImageService imageService;
|
||||||
|
|
||||||
|
private final ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory());
|
||||||
|
|
||||||
public DevConfiguration(UserService userService, RecipeService recipeService, ImageService imageService) {
|
public DevConfiguration(UserService userService, RecipeService recipeService, ImageService imageService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.recipeService = recipeService;
|
this.recipeService = recipeService;
|
||||||
this.imageService = imageService;
|
this.imageService = imageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class ImageInfo {
|
||||||
|
public String src;
|
||||||
|
public String title;
|
||||||
|
public String alt;
|
||||||
|
public String caption;
|
||||||
|
public boolean isPublic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class RecipeFrontMatter {
|
||||||
|
public String title;
|
||||||
|
public String slug;
|
||||||
|
public boolean isPublic;
|
||||||
|
public ImageInfo mainImage;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CommandLineRunner addTestData() {
|
public CommandLineRunner addTestData() {
|
||||||
return args -> {
|
return args -> {
|
||||||
final User testUser = this.userService.createUser(
|
final User testUser = this.userService.createUser(
|
||||||
"test", "test@test.com", "test", Set.of()
|
"test-user", "test-user@test.com", "test", Set.of()
|
||||||
);
|
);
|
||||||
logger.info("Created {}", testUser);
|
logger.info("Created testUser: {}", testUser);
|
||||||
|
|
||||||
final ImageCreateInfoSpec obazdaCreateSpec = new ImageCreateInfoSpec();
|
try (final Stream<Path> recipePaths = Files.walk(Path.of("dev-data/recipes"))) {
|
||||||
obazdaCreateSpec.setAlt("Obazda");
|
for (final Path recipePath : recipePaths.toList()) {
|
||||||
obazdaCreateSpec.setCaption("German Obazda.");
|
if (Files.isDirectory(recipePath)) {
|
||||||
obazdaCreateSpec.setPublic(true);
|
continue;
|
||||||
final Image obazdaImage;
|
}
|
||||||
try (final InputStream obazdaStream = DevConfiguration.class.getResourceAsStream("Obazda.jpg")) {
|
|
||||||
obazdaImage = this.imageService.create(
|
|
||||||
testUser,
|
|
||||||
"Obazda.jpg",
|
|
||||||
obazdaStream,
|
|
||||||
48654L,
|
|
||||||
obazdaCreateSpec
|
|
||||||
);
|
|
||||||
}
|
|
||||||
logger.info("Created {}", obazdaImage);
|
|
||||||
|
|
||||||
final RecipeCreateSpec recipeCreateSpec = new RecipeCreateSpec();
|
final String fullText = Files.readString(recipePath);
|
||||||
recipeCreateSpec.setSlug("test-recipe");
|
final String[] parts = fullText.split("---");
|
||||||
recipeCreateSpec.setTitle("Test Recipe");
|
if (parts.length != 3) {
|
||||||
recipeCreateSpec.setRawText("Hello, World!");
|
throw new IllegalArgumentException("Invalid recipe file: " + recipePath);
|
||||||
recipeCreateSpec.setPublic(true);
|
}
|
||||||
recipeCreateSpec.setMainImage(obazdaImage);
|
final String rawFrontMatter = parts[1];
|
||||||
final Recipe recipe = this.recipeService.create(testUser, recipeCreateSpec);
|
final String rawRecipeText = parts[2];
|
||||||
logger.info("Created {}", recipe);
|
final RecipeFrontMatter frontMatter = this.yamlObjectMapper.readValue(
|
||||||
|
rawFrontMatter, RecipeFrontMatter.class
|
||||||
|
);
|
||||||
|
|
||||||
try (final InputStream inputStream = DevConfiguration.class.getResourceAsStream("HAL9000.svg")) {
|
final ImageCreateInfoSpec imageCreateSpec = new ImageCreateInfoSpec();
|
||||||
final ImageCreateInfoSpec imageCreateSpec = new ImageCreateInfoSpec();
|
imageCreateSpec.setAlt(frontMatter.mainImage.alt);
|
||||||
imageCreateSpec.setPublic(true);
|
imageCreateSpec.setCaption(frontMatter.mainImage.caption);
|
||||||
final Image image = this.imageService.create(
|
imageCreateSpec.setPublic(frontMatter.mainImage.isPublic);
|
||||||
testUser,
|
final Path givenPath = Path.of(frontMatter.mainImage.src);
|
||||||
"HAL9000.svg",
|
final Path resolvedPath = Path.of("dev-data").resolve(givenPath);
|
||||||
inputStream,
|
final Image mainImage;
|
||||||
27881L,
|
try (final InputStream inputStream = new FileInputStream(resolvedPath.toFile())) {
|
||||||
imageCreateSpec
|
final long size = Files.size(resolvedPath);
|
||||||
);
|
mainImage = this.imageService.create(
|
||||||
logger.info("Created {}", image);
|
testUser,
|
||||||
} catch (IOException | ImageException e) {
|
givenPath.getName(givenPath.getNameCount() - 1).toString(),
|
||||||
logger.error("Failed to load and/or create HAL9000.svg", e);
|
inputStream,
|
||||||
|
size,
|
||||||
|
imageCreateSpec
|
||||||
|
);
|
||||||
|
logger.info("Created mainImage {} for {}", mainImage, recipePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
final RecipeCreateSpec recipeCreateSpec = new RecipeCreateSpec();
|
||||||
|
recipeCreateSpec.setSlug(frontMatter.slug);
|
||||||
|
recipeCreateSpec.setTitle(frontMatter.title);
|
||||||
|
recipeCreateSpec.setRawText(rawRecipeText);
|
||||||
|
recipeCreateSpec.setPublic(frontMatter.isPublic);
|
||||||
|
recipeCreateSpec.setMainImage(mainImage);
|
||||||
|
final Recipe recipe = this.recipeService.create(testUser, recipeCreateSpec);
|
||||||
|
logger.info("Created recipe {}", recipe);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,13 @@ public final class RecipeEntity implements Recipe {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@Lob
|
@Lob
|
||||||
|
@Column(name = "raw_text", columnDefinition = "TEXT", nullable = false)
|
||||||
@Basic(fetch = FetchType.LAZY)
|
@Basic(fetch = FetchType.LAZY)
|
||||||
private String rawText;
|
private String rawText;
|
||||||
|
|
||||||
@Lob
|
@Lob
|
||||||
|
@Column(name = "cached_rendered_text", columnDefinition = "TEXT")
|
||||||
@Basic(fetch = FetchType.LAZY)
|
@Basic(fetch = FetchType.LAZY)
|
||||||
private String cachedRenderedText;
|
private String cachedRenderedText;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user