Add also here recipeId

This commit is contained in:
franc
2025-04-23 13:33:33 +02:00
parent 146cdf9bff
commit 7035a9b64d
6 changed files with 160 additions and 13 deletions
@@ -12,6 +12,6 @@
Task SwapInstructionNumbersAsync(Instruction a, Instruction b);
Task<List<Instruction>> GetInstructionsOfRecipeAsync(Guid instructionId);
Task<List<Instruction>> GetInstructionsOfRecipeAsync(Guid recipeId);
}
}
@@ -70,19 +70,19 @@
}
}
public async Task<List<Instruction>> GetInstructionsOfRecipeAsync(Guid instructionId)
public async Task<List<Instruction>> GetInstructionsOfRecipeAsync(Guid recipeId)
{
var instruction = await _context.Instructions
.Include(i => i.Recipe)
.ThenInclude(r => r.Instructions)
.FirstOrDefaultAsync(i => i.Id == instructionId);
var instructions = await _context.Instructions
.Where(i => i.Recipe.Id == recipeId)
.OrderBy(i => i.Number)
.ToListAsync();
if (instruction?.Recipe == null)
if (!instructions.Any())
{
throw new InvalidDataException($"Instruction with ID {instructionId} or its Recipe not found.");
throw new InvalidDataException($"No instructions found for Recipe ID {recipeId}.");
}
return instruction.Recipe.Instructions.ToList();
return instructions;
}
public async Task SwapInstructionNumbersAsync(Instruction a, Instruction b)