diff --git a/Endpoints/SuggestEndpoints.cs b/Endpoints/SuggestEndpoints.cs index fd45a24..db14d6e 100644 --- a/Endpoints/SuggestEndpoints.cs +++ b/Endpoints/SuggestEndpoints.cs @@ -111,6 +111,14 @@ public static class SuggestEndpoints if (suggestion == null) return Results.NotFound(new { error = "Suggestion not found." }); + // Break any links that pointed at this suggestion + await db.Suggestions + .Where(s => s.ParentSuggestionId == suggestion.Id) + .ExecuteUpdateAsync(s => s.SetProperty(x => x.ParentSuggestionId, (int?)null)); + + // Remove votes for this suggestion to avoid orphaned vote rows or FK errors + await db.Votes.Where(v => v.SuggestionId == suggestion.Id).ExecuteDeleteAsync(); + db.Suggestions.Remove(suggestion); await db.SaveChangesAsync(); return Results.NoContent();