less shit code but still not good
This commit is contained in:
parent
ddfb5eff54
commit
9e50b97bc9
6 changed files with 14 additions and 47 deletions
|
|
@ -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<AnswerVariant>())
|
||||
},
|
||||
"multipleanswerquestion" => new OutputMultipleAnswerQuestionDto
|
||||
{
|
||||
Id = question.Id,
|
||||
Title = question.Title,
|
||||
SurveyId = question.SurveyId,
|
||||
QuestionType = question.Discriminator,
|
||||
AnswerVariants = GetAnswerVariants(question.AnswerVariants ?? Array.Empty<AnswerVariant>())
|
||||
},
|
||||
_ => 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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue