mirror of
https://github.com/bitwarden/server
synced 2025-12-15 15:53:59 +00:00
Delete all seeded data
Fixup single user recipe to inform of seeded entities
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using Bit.SeederApi.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Bit.SeederApi.Controllers;
|
||||
|
||||
@@ -99,4 +99,44 @@ public class SeedController : Controller
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("/seed")]
|
||||
public async Task<IActionResult> DeleteAll()
|
||||
{
|
||||
_logger.LogInformation("Deleting all seeded data");
|
||||
|
||||
// Pull all Seeded Data ids
|
||||
var seededData = _recipeService.GetAllSeededData();
|
||||
|
||||
var aggregateException = new AggregateException();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var sd in seededData)
|
||||
{
|
||||
try
|
||||
{
|
||||
_recipeService.DestroyRecipe(sd.Id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
aggregateException = new AggregateException(aggregateException, ex);
|
||||
_logger.LogError(ex, "Error deleting seeded data: {SeedId}", sd.Id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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 = "All seeded data deleted successfully"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user