Notes not randomized anymore?

This commit is contained in:
durn
2026-04-25 14:17:30 -06:00
parent ca3e64c096
commit ac5e289db8
4 changed files with 44 additions and 20 deletions
@@ -106,11 +106,13 @@ public class RecipeUploadController {
String unit = getListValue(form.getIngredientUnit(), i); String unit = getListValue(form.getIngredientUnit(), i);
String notes = getListValue(form.getIngredientNotes(), i); String notes = getListValue(form.getIngredientNotes(), i);
ingredientDtos.add(new RecipeIngredientDto( RecipeIngredientDto riDto = new RecipeIngredientDto(
ingredientName.trim(), ingredientName.trim(),
quantity, quantity,
unit != null ? unit.trim() : "", unit != null ? unit.trim() : "",
notes != null ? notes.trim() : "")); notes != null ? notes.trim() : "");
riDto.setIndex(i);
ingredientDtos.add(riDto);
} }
} }
dto.setIngredients(ingredientDtos); dto.setIngredients(ingredientDtos);
@@ -7,6 +7,7 @@ public class RecipeIngredientDto {
private String quantity; private String quantity;
private String unit; private String unit;
private String notes; private String notes;
private Integer orderIndex;
public RecipeIngredientDto() { public RecipeIngredientDto() {
super(); super();
@@ -53,4 +54,12 @@ public class RecipeIngredientDto {
this.notes = notes; this.notes = notes;
} }
public Integer getIndex() {
return orderIndex;
}
public void setIndex(Integer index) {
this.orderIndex = index;
}
} }
@@ -317,21 +317,33 @@ public class RecipeServiceImpl implements RecipeService {
List<Tag> tagsToRemove = new ArrayList<>(); List<Tag> tagsToRemove = new ArrayList<>();
if (updatedIngredients != null) { if (updatedIngredients != null) {
for (RecipeIngredient ri : existingRecipe.getRecipeIngredients()) {
boolean existsInUpdatedList = false; for (int i = 0; i < updatedIngredients.size(); i++) {
for (RecipeIngredientDto dto : updatedIngredients) { RecipeIngredientDto riDto = updatedIngredients.get(i);
String updatedName = dto.getIngredientName();
String existingName = ri.getIngredient().getName();
if (java.util.Objects.equals(updatedName, existingName)) { RecipeIngredient existingRI = existingRecipe.getRecipeIngredients().stream()
existsInUpdatedList = true; .filter(ri -> java.util.Objects.equals(ri.getIngredient().getName(), riDto.getIngredientName()))
break; .findFirst()
} .orElse(null);
if (existingRI != null) {
existingRI.setQuantity(riDto.getQuantity());
existingRI.setUnit(riDto.getUnit());
existingRI.setNotes(riDto.getNotes());
existingRI.setOrderIndex(i);
} else {
Ingredient ingredient = ingredientRepository.findByNameIgnoreCase(riDto.getIngredientName())
.orElseGet(() -> new Ingredient(riDto.getIngredientName()));
if (ingredient.getId() == null) {
ingredientRepository.save(ingredient);
} }
if (!existsInUpdatedList) { RecipeIngredient newRI = new RecipeIngredient(existingRecipe, ingredient, riDto.getQuantity(),
ingredientsToRemove.add(ri); riDto.getUnit(), riDto.getNotes());
newRI.setOrderIndex(i);
existingRecipe.getRecipeIngredients().add(newRI);
} }
} }
@@ -543,7 +543,7 @@ document.getElementById('publish-btn').addEventListener('click', async function(
formData.append('cost', document.getElementById('cost').value.trim()); formData.append('cost', document.getElementById('cost').value.trim());
formData.append('removeImage', String(imageRemoved)); formData.append('removeImage', String(imageRemoved));
document.querySelectorAll('#ingredients-container .dynamic-row').forEach(row => { document.querySelectorAll('#ingredients-container .dynamic-row').forEach((row, index) => {
const ingredientName = row.querySelector('.ing-name').value.trim(); const ingredientName = row.querySelector('.ing-name').value.trim();
if (!ingredientName) return; if (!ingredientName) return;
@@ -555,6 +555,7 @@ document.getElementById('publish-btn').addEventListener('click', async function(
formData.append('ingredientQuantity', qty); formData.append('ingredientQuantity', qty);
if (unit) formData.append('ingredientUnit', unit); if (unit) formData.append('ingredientUnit', unit);
if (notes) formData.append('ingredientNotes', notes); if (notes) formData.append('ingredientNotes', notes);
formData.append('ingredientOrder', index);
}); });
document.querySelectorAll('#steps-container textarea').forEach(textarea => { document.querySelectorAll('#steps-container textarea').forEach(textarea => {