mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
Notes not randomized anymore?
This commit is contained in:
@@ -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,22 +317,34 @@ 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 (!existsInUpdatedList) {
|
if (existingRI != null) {
|
||||||
ingredientsToRemove.add(ri);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
RecipeIngredient newRI = new RecipeIngredient(existingRecipe, ingredient, riDto.getQuantity(),
|
||||||
|
riDto.getUnit(), riDto.getNotes());
|
||||||
|
newRI.setOrderIndex(i);
|
||||||
|
|
||||||
|
existingRecipe.getRecipeIngredients().add(newRI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
existingRecipe.getRecipeIngredients().removeAll(ingredientsToRemove);
|
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('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,7 +555,8 @@ 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 => {
|
||||||
const instruction = textarea.value.trim();
|
const instruction = textarea.value.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user