From 842aaba2300b295f6e046bfaf9f34cb556e203b8 Mon Sep 17 00:00:00 2001 From: Paweł Bernaciak Date: Wed, 25 Oct 2023 20:50:20 +0200 Subject: Return needed data from API --- .../Elements.Backend/Controllers/SuggestionController.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'backend/Elements.Backend/Controllers/SuggestionController.cs') 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 = await _dbContext.Suggestions + IEnumerable 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)); -- cgit v1.2.3