delete answer variants for logic rework
This commit is contained in:
parent
dc6bca6b6e
commit
c39fd4192a
4 changed files with 13 additions and 7 deletions
|
|
@ -55,4 +55,12 @@ public class QuestionController : ControllerBase
|
||||||
var result = QuestionMapper.ModelToQuestionDto(model);
|
var result = QuestionMapper.ModelToQuestionDto(model);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public async Task<IActionResult> DeleteQuestion([FromRoute] int id, [FromRoute] int surveyId)
|
||||||
|
{
|
||||||
|
await _questionService.DeleteQuestionAsync(id);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,13 +9,9 @@ public class CreateQuestionDto
|
||||||
/// Название вопроса
|
/// Название вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required string Title { get; set; }
|
public required string Title { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип вопроса
|
/// Тип вопроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required string QuestionType { get; set; }
|
public required string QuestionType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Варианты ответа (только если вопрос с выбором)
|
|
||||||
/// </summary>
|
|
||||||
public List<string>? AnswerVariants { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -30,13 +30,13 @@ public static class QuestionMapper
|
||||||
{
|
{
|
||||||
Title = dto.Title,
|
Title = dto.Title,
|
||||||
SurveyId = surveyId,
|
SurveyId = surveyId,
|
||||||
AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? [],
|
AnswerVariants = [],
|
||||||
},
|
},
|
||||||
"multipleanswerquestion" => new MultipleAnswerQuestion
|
"multipleanswerquestion" => new MultipleAnswerQuestion
|
||||||
{
|
{
|
||||||
Title = dto.Title,
|
Title = dto.Title,
|
||||||
SurveyId = surveyId,
|
SurveyId = surveyId,
|
||||||
AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? []
|
AnswerVariants = []
|
||||||
},
|
},
|
||||||
_ => throw new BadRequestException("Unknown question type")
|
_ => throw new BadRequestException("Unknown question type")
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ public class QuestionService : IQuestionService
|
||||||
{
|
{
|
||||||
private readonly IQuestionRepository _questionRepository;
|
private readonly IQuestionRepository _questionRepository;
|
||||||
private readonly ISurveyRepository _surveyRepository;
|
private readonly ISurveyRepository _surveyRepository;
|
||||||
|
private readonly IUserContext _userContext;
|
||||||
|
|
||||||
public QuestionService(IQuestionRepository questionRepository, ISurveyRepository surveyRepository,
|
public QuestionService(IQuestionRepository questionRepository, ISurveyRepository surveyRepository,
|
||||||
IUserContext userContext)
|
IUserContext userContext)
|
||||||
{
|
{
|
||||||
_questionRepository = questionRepository;
|
_questionRepository = questionRepository;
|
||||||
_surveyRepository = surveyRepository;
|
_surveyRepository = surveyRepository;
|
||||||
|
_userContext = userContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddQuestionAsync(QuestionBase question)
|
public async Task AddQuestionAsync(QuestionBase question)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue