From 363936641a31b0b508197d41bea1ce116931b5d4 Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Sat, 20 Jan 2024 11:03:44 +0100 Subject: New element creator --- backend/Elements.Backend/Controllers/SuggestionController.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'backend/Elements.Backend') diff --git a/backend/Elements.Backend/Controllers/SuggestionController.cs b/backend/Elements.Backend/Controllers/SuggestionController.cs index b1d28b8..9c39163 100644 --- a/backend/Elements.Backend/Controllers/SuggestionController.cs +++ b/backend/Elements.Backend/Controllers/SuggestionController.cs @@ -122,6 +122,12 @@ public class SuggestionController : ControllerBase //User already suggested something if (await _dbContext.Suggestions.AnyAsync(s => s.UserId.ToString() == currentUserId)) return BadRequest(); + + var exists = await _dbContext.Recipes.AnyAsync(r => + (r.FirstElementId == suggestion.FirstElementId && r.SecondElementId == suggestion.SecondElementId) || + (r.FirstElementId == suggestion.SecondElementId && r.SecondElementId == suggestion.FirstElementId)); + if (exists) + return BadRequest(); Suggestion newSuggestion = new() { @@ -130,7 +136,7 @@ public class SuggestionController : ControllerBase Icon = ConvertBitmapToPng(Convert.FromBase64String(suggestion.IconBitmap)), FirstElementId = suggestion.FirstElementId, SecondElementId = suggestion.SecondElementId, - VotingEnd = DateTime.UtcNow + TimeSpan.FromMinutes(5), + VotingEnd = DateTime.UtcNow + TimeSpan.FromMinutes(1), UserId = int.Parse(currentUserId) }; await _dbContext.Suggestions.AddAsync(newSuggestion); -- cgit v1.2.3