diff --git a/util/SeederApi/Controllers/SeedController.cs b/util/SeederApi/Controllers/SeedController.cs index ab508d2b97..19bee9ad3c 100644 --- a/util/SeederApi/Controllers/SeedController.cs +++ b/util/SeederApi/Controllers/SeedController.cs @@ -65,6 +65,43 @@ public class SeedController : Controller } } + [HttpDelete("/seed/batch")] + public async Task DeleteBatch([FromBody] List seedIds) + { + _logger.LogInformation("Deleting batch of seeded data with IDs: {SeedIds}", string.Join(", ", seedIds)); + + var aggregateException = new AggregateException(); + + await Task.Run(async () => + { + foreach (var seedId in seedIds) + { + try + { + await _recipeService.DestroyRecipe(seedId); + } + catch (Exception ex) + { + aggregateException = new AggregateException(aggregateException, ex); + _logger.LogError(ex, "Error deleting seeded data: {SeedId}", seedId); + } + } + }); + + if (aggregateException.InnerExceptions.Count > 0) + { + return BadRequest(new + { + Error = "One or more errors occurred while deleting seeded data", + Details = aggregateException.InnerExceptions.Select(e => e.Message).ToList() + }); + } + return Ok(new + { + Message = "Batch delete completed successfully" + }); + } + [HttpDelete("/seed/{seedId}")] public async Task Delete([FromRoute] Guid seedId) { @@ -100,6 +137,7 @@ public class SeedController : Controller } } + [HttpDelete("/seed")] public async Task DeleteAll() { diff --git a/util/SeederApi/Services/RecipeService.cs b/util/SeederApi/Services/RecipeService.cs index 8a73ef326c..2d184ac976 100644 --- a/util/SeederApi/Services/RecipeService.cs +++ b/util/SeederApi/Services/RecipeService.cs @@ -65,7 +65,8 @@ public class RecipeService : IRecipeService var seededData = _databaseContext.SeededData.FirstOrDefault(s => s.Id == seedId); if (seededData == null) { - throw new RecipeExecutionException($"Seeded data with ID {seedId} not found"); + _logger.LogInformation("No seeded data found with ID {SeedId}, skipping", seedId); + return null; } var trackedEntities = JsonSerializer.Deserialize>>(seededData.Data);