From 96cceafe7760b957efd0d962656f5aa513a99b38 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 12 Aug 2025 17:48:03 +0800 Subject: [PATCH] :bug: Fix non-required field poll validate incorrect --- DysonNetwork.Sphere/Poll/PollController.cs | 6 +++--- DysonNetwork.Sphere/Poll/PollService.cs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DysonNetwork.Sphere/Poll/PollController.cs b/DysonNetwork.Sphere/Poll/PollController.cs index 95c5890..c29b52f 100644 --- a/DysonNetwork.Sphere/Poll/PollController.cs +++ b/DysonNetwork.Sphere/Poll/PollController.cs @@ -91,10 +91,10 @@ public class PollController(AppDatabase db, PollService polls, Publisher.Publish var answerQuery = db.PollAnswers .Where(a => a.PollId == id) .AsQueryable(); - + var total = await answerQuery.CountAsync(); Response.Headers.Append("X-Total", total.ToString()); - + var answers = await answerQuery .OrderByDescending(a => a.CreatedAt) .Skip(offset) @@ -325,4 +325,4 @@ public class PollController(AppDatabase db, PollService polls, Publisher.Publish return StatusCode(500, "An error occurred while deleting the poll... " + ex.Message); } } -} \ No newline at end of file +} diff --git a/DysonNetwork.Sphere/Poll/PollService.cs b/DysonNetwork.Sphere/Poll/PollService.cs index 1e06615..39e5fee 100644 --- a/DysonNetwork.Sphere/Poll/PollService.cs +++ b/DysonNetwork.Sphere/Poll/PollService.cs @@ -75,6 +75,8 @@ public class PollService(AppDatabase db, ICacheService cache) var questionId = question.Id.ToString(); if (question.IsRequired && !answer.ContainsKey(questionId)) throw new Exception($"Missing required field: {question.Title}"); + else if (!answer.ContainsKey(questionId)) + continue; switch (question.Type) { case PollQuestionType.Rating when answer[questionId].ValueKind != JsonValueKind.Number: