34 lines
No EOL
1.2 KiB
C#
34 lines
No EOL
1.2 KiB
C#
using SurveyBackend.DTOs.Question;
|
|
using SurveyBackend.Services.Exceptions;
|
|
using SurveyLib.Core.Models;
|
|
using SurveyLib.Core.Models.QuestionVariants;
|
|
|
|
namespace SurveyBackend.Mappers.QuestionDTOs;
|
|
|
|
public static class QuestionCreationMapper
|
|
{
|
|
public static QuestionBase QuestionCreationToModel(CreateQuestionDto dto)
|
|
{
|
|
return dto.QuestionType.ToLower() switch
|
|
{
|
|
"textquestion" => new TextQuestion
|
|
{
|
|
Title = dto.Title,
|
|
SurveyId = dto.SurveyId,
|
|
},
|
|
"singleanswerquestion" => new SingleAnswerQuestion
|
|
{
|
|
Title = dto.Title,
|
|
SurveyId = dto.SurveyId,
|
|
AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? [],
|
|
},
|
|
"multipleanswerquestion" => new MultipleAnswerQuestion
|
|
{
|
|
Title = dto.Title,
|
|
SurveyId = dto.SurveyId,
|
|
AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? []
|
|
},
|
|
_ => throw new BadRequestException("Unknown question type")
|
|
};
|
|
}
|
|
} |