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 notes = getListValue(form.getIngredientNotes(), i);
ingredientDtos.add(new RecipeIngredientDto(
ingredientName.trim(),
quantity,
unit != null ? unit.trim() : "",
notes != null ? notes.trim() : ""));
RecipeIngredientDto riDto = new RecipeIngredientDto(
ingredientName.trim(),
quantity,
unit != null ? unit.trim() : "",
notes != null ? notes.trim() : "");
riDto.setIndex(i);
ingredientDtos.add(riDto);
}
}
dto.setIngredients(ingredientDtos);
@@ -7,6 +7,7 @@ public class RecipeIngredientDto {
private String quantity;
private String unit;
private String notes;
private Integer orderIndex;
public RecipeIngredientDto() {
super();
@@ -52,5 +53,13 @@ public class RecipeIngredientDto {
public void setNotes(String notes) {
this.notes = notes;
}
public Integer getIndex() {
return orderIndex;
}
public void setIndex(Integer index) {
this.orderIndex = index;
}
}
@@ -317,22 +317,34 @@ public class RecipeServiceImpl implements RecipeService {
List<Tag> tagsToRemove = new ArrayList<>();
if (updatedIngredients != null) {
for (RecipeIngredient ri : existingRecipe.getRecipeIngredients()) {
for (int i = 0; i < updatedIngredients.size(); i++) {
RecipeIngredientDto riDto = updatedIngredients.get(i);
boolean existsInUpdatedList = false;
for (RecipeIngredientDto dto : updatedIngredients) {
String updatedName = dto.getIngredientName();
String existingName = ri.getIngredient().getName();
RecipeIngredient existingRI = existingRecipe.getRecipeIngredients().stream()
.filter(ri -> java.util.Objects.equals(ri.getIngredient().getName(), riDto.getIngredientName()))
.findFirst()
.orElse(null);
if (java.util.Objects.equals(updatedName, existingName)) {
existsInUpdatedList = true;
break;
}
}
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 (!existsInUpdatedList) {
ingredientsToRemove.add(ri);
}
if (ingredient.getId() == null) {
ingredientRepository.save(ingredient);
}
RecipeIngredient newRI = new RecipeIngredient(existingRecipe, ingredient, riDto.getQuantity(),
riDto.getUnit(), riDto.getNotes());
newRI.setOrderIndex(i);
existingRecipe.getRecipeIngredients().add(newRI);
}
}
existingRecipe.getRecipeIngredients().removeAll(ingredientsToRemove);
@@ -543,7 +543,7 @@ document.getElementById('publish-btn').addEventListener('click', async function(
formData.append('cost', document.getElementById('cost').value.trim());
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();
if (!ingredientName) return;
@@ -555,7 +555,8 @@ document.getElementById('publish-btn').addEventListener('click', async function(
formData.append('ingredientQuantity', qty);
if (unit) formData.append('ingredientUnit', unit);
if (notes) formData.append('ingredientNotes', notes);
});
formData.append('ingredientOrder', index);
});
document.querySelectorAll('#steps-container textarea').forEach(textarea => {
const instruction = textarea.value.trim();