summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/Elements.Backend/Controllers/SuggestionController.cs13
1 files changed, 10 insertions, 3 deletions
diff --git a/backend/Elements.Backend/Controllers/SuggestionController.cs b/backend/Elements.Backend/Controllers/SuggestionController.cs
index 932e774..b1d28b8 100644
--- a/backend/Elements.Backend/Controllers/SuggestionController.cs
+++ b/backend/Elements.Backend/Controllers/SuggestionController.cs
@@ -30,16 +30,17 @@ public class SuggestionController : ControllerBase
if (!firstExists || !secondExists)
return BadRequest();
- IEnumerable<Suggestion> suggestion = await _dbContext.Suggestions
+ IEnumerable<Suggestion> suggestions = await _dbContext.Suggestions
.Where(s =>
(s.FirstElementId == firstElementId && s.SecondElementId == secondElementId) ||
(s.FirstElementId == secondElementId && s.SecondElementId == firstElementId))
.Include(suggestion => suggestion.Votes)
.ToListAsync();
- if (!suggestion.Any())
+ if (!suggestions.Any())
return NotFound();
- var result = suggestion.Select(s => new
+ DateTime votingEnd = suggestions.OrderBy(s => s.VotingEnd).First().VotingEnd;
+ var suggestionJson = suggestions.Select(s => new
{
s.Id,
s.Name,
@@ -50,6 +51,12 @@ public class SuggestionController : ControllerBase
s.UserId,
s.VotingEnd
}).ToList();
+
+ var result = new
+ {
+ VotingEnd = votingEnd,
+ Suggestions = suggestionJson
+ };
var serializeOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
return Ok(JsonSerializer.Serialize(result, serializeOptions));