diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputMultipleAnswerQuestionDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputMultipleAnswerQuestionDTO.cs deleted file mode 100644 index 606c9a0..0000000 --- a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputMultipleAnswerQuestionDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SurveyBackend.DTOs.Question; - -public class OutputMultipleAnswerQuestionDto : OutputQuestionBaseDto -{ - public List AnswerVariants { get; set; } = []; -} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionBaseDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionDto.cs similarity index 69% rename from SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionBaseDTO.cs rename to SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionDto.cs index b522001..bfae54c 100644 --- a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionBaseDTO.cs +++ b/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputQuestionDto.cs @@ -1,9 +1,10 @@ namespace SurveyBackend.DTOs.Question; -public abstract class OutputQuestionBaseDto +public class OutputQuestionDto { public required int Id { get; set; } public required int SurveyId { get; set; } public required string Title { get; set; } public required string QuestionType { get; set; } + public List? AnswerVariants { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputSingleAnswerQuestionDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputSingleAnswerQuestionDTO.cs deleted file mode 100644 index 2084f10..0000000 --- a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputSingleAnswerQuestionDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SurveyBackend.DTOs.Question; - -public class OutputSingleAnswerQuestionDto : OutputQuestionBaseDto -{ - public List AnswerVariants { get; set; } = []; -} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputTextQuestionDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputTextQuestionDTO.cs deleted file mode 100644 index d955b8d..0000000 --- a/SurveyBackend/SurveyBackend.API/DTOs/Question/OutputTextQuestionDTO.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SurveyBackend.DTOs.Question; - -public class OutputTextQuestionDto : OutputQuestionBaseDto -{ - -} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Mappers/QuestionDTOs/QuestionOutputMapper.cs b/SurveyBackend/SurveyBackend.API/Mappers/QuestionDTOs/QuestionOutputMapper.cs index 2f7a205..a647851 100644 --- a/SurveyBackend/SurveyBackend.API/Mappers/QuestionDTOs/QuestionOutputMapper.cs +++ b/SurveyBackend/SurveyBackend.API/Mappers/QuestionDTOs/QuestionOutputMapper.cs @@ -1,38 +1,21 @@ using SurveyBackend.DTOs.Question; using SurveyLib.Core.Models; +using SurveyLib.Core.Models.QuestionVariants; namespace SurveyBackend.Mappers.QuestionDTOs; public static class QuestionOutputMapper { - public static object ModelToQuestionDTO(QuestionBase question) + public static OutputQuestionDto ModelToQuestionDTO(QuestionBase question) { - return question.Discriminator.ToLower() switch + var withAnswerVariants = question.GetType() != typeof(TextQuestion); + return new OutputQuestionDto { - "textquestion" => new OutputTextQuestionDto - { - Id = question.Id, - Title = question.Title, - SurveyId = question.SurveyId, - QuestionType = question.Discriminator - }, - "singleanswerquestion" => new OutputSingleAnswerQuestionDto - { - Id = question.Id, - Title = question.Title, - SurveyId = question.SurveyId, - QuestionType = question.Discriminator, - AnswerVariants = GetAnswerVariants(question.AnswerVariants ?? Array.Empty()) - }, - "multipleanswerquestion" => new OutputMultipleAnswerQuestionDto - { - Id = question.Id, - Title = question.Title, - SurveyId = question.SurveyId, - QuestionType = question.Discriminator, - AnswerVariants = GetAnswerVariants(question.AnswerVariants ?? Array.Empty()) - }, - _ => throw new Exception($"Unknown question type: {question.Discriminator}") + Id = question.Id, + SurveyId = question.SurveyId, + Title = question.Title, + QuestionType = question.Discriminator, + AnswerVariants = withAnswerVariants ? GetAnswerVariants(question.AnswerVariants) : null, }; } diff --git a/SurveyBackend/SurveyBackend.API/Program.cs b/SurveyBackend/SurveyBackend.API/Program.cs index 36198e2..7c22f06 100644 --- a/SurveyBackend/SurveyBackend.API/Program.cs +++ b/SurveyBackend/SurveyBackend.API/Program.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Serialization; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; @@ -66,8 +67,8 @@ public class Program }; }); - builder.Services.AddControllers(); - + builder.Services.AddControllers().AddJsonOptions(opts => { opts.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; }); + builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => {