diff options
| author | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2023-10-25 20:50:20 +0200 |
|---|---|---|
| committer | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2023-10-25 20:50:20 +0200 |
| commit | 842aaba2300b295f6e046bfaf9f34cb556e203b8 (patch) | |
| tree | 7579c67b1b3abde57591af05328c870ddc1a49cf /backend | |
| parent | 1912feb9cfe51deaedbe3abe9239fd1bcf2b37f8 (diff) | |
Return needed data from API
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/Elements.Backend/Controllers/SuggestionController.cs | 13 |
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)); |
