diff --git a/DysonNetwork.Sphere/Poll/Poll.cs b/DysonNetwork.Sphere/Poll/Poll.cs index a45ed70..9b0c1db 100644 --- a/DysonNetwork.Sphere/Poll/Poll.cs +++ b/DysonNetwork.Sphere/Poll/Poll.cs @@ -10,12 +10,12 @@ public class Poll : ModelBase { public Guid Id { get; set; } = Guid.NewGuid(); public List Questions { get; set; } = new(); - + [MaxLength(1024)] public string? Title { get; set; } [MaxLength(4096)] public string? Description { get; set; } - + public Instant? EndedAt { get; set; } - + public Guid PublisherId { get; set; } [JsonIgnore] public Publisher.Publisher? Publisher { get; set; } } @@ -32,15 +32,15 @@ public enum PollQuestionType public class PollQuestion : ModelBase { public Guid Id { get; set; } = Guid.NewGuid(); - + public PollQuestionType Type { get; set; } [Column(TypeName = "jsonb")] public List? Options { get; set; } - + [MaxLength(1024)] public string Title { get; set; } = null!; [MaxLength(4096)] public string? Description { get; set; } public int Order { get; set; } = 0; public bool IsRequired { get; set; } - + public Guid PollId { get; set; } [JsonIgnore] public Poll Poll { get; set; } = null!; } @@ -48,7 +48,7 @@ public class PollQuestion : ModelBase public class PollOption { public Guid Id { get; set; } = Guid.NewGuid(); - [Required] [MaxLength(1024)] public string Label { get; set; } = null!; + [Required][MaxLength(1024)] public string Label { get; set; } = null!; [MaxLength(4096)] public string? Description { get; set; } public int Order { get; set; } = 0; } @@ -57,8 +57,8 @@ public class PollAnswer : ModelBase { public Guid Id { get; set; } = Guid.NewGuid(); [Column(TypeName = "jsonb")] public Dictionary Answer { get; set; } = null!; - + public Guid AccountId { get; set; } public Guid PollId { get; set; } - [JsonIgnore] public Poll Poll { get; set; } = null!; -} \ No newline at end of file + [JsonIgnore] public Poll? Poll { get; set; } +} diff --git a/DysonNetwork.Sphere/Poll/PollService.cs b/DysonNetwork.Sphere/Poll/PollService.cs index 11f4115..1e06615 100644 --- a/DysonNetwork.Sphere/Poll/PollService.cs +++ b/DysonNetwork.Sphere/Poll/PollService.cs @@ -51,7 +51,10 @@ public class PollService(AppDatabase db, ICacheService cache) var answer = await db.PollAnswers .Where(e => e.PollId == pollId && e.AccountId == accountId) + .AsNoTracking() .FirstOrDefaultAsync(); + if (answer is not null) + answer.Poll = null; // Set the answer even it is null, which stands for unanswered await cache.SetAsync(cacheKey, answer, TimeSpan.FromMinutes(30));