From c39fd4192ab8b8a9f7e037af5054649ab28f7609 Mon Sep 17 00:00:00 2001 From: shept Date: Tue, 13 May 2025 19:09:08 +0500 Subject: [PATCH] delete answer variants for logic rework --- .../SurveyBackend.API/Controllers/QuestionController.cs | 8 ++++++++ .../SurveyBackend.API/DTOs/Question/CreateQuestionDTO.cs | 6 +----- SurveyBackend/SurveyBackend.API/Mappers/QuestionMapper.cs | 4 ++-- .../SurveyBackend.Services/Services/QuestionService.cs | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/SurveyBackend/SurveyBackend.API/Controllers/QuestionController.cs b/SurveyBackend/SurveyBackend.API/Controllers/QuestionController.cs index d7240cc..24367f6 100644 --- a/SurveyBackend/SurveyBackend.API/Controllers/QuestionController.cs +++ b/SurveyBackend/SurveyBackend.API/Controllers/QuestionController.cs @@ -55,4 +55,12 @@ public class QuestionController : ControllerBase var result = QuestionMapper.ModelToQuestionDto(model); return Ok(result); } + + [Authorize] + [HttpDelete("{id}")] + public async Task DeleteQuestion([FromRoute] int id, [FromRoute] int surveyId) + { + await _questionService.DeleteQuestionAsync(id); + return Ok(); + } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Question/CreateQuestionDTO.cs b/SurveyBackend/SurveyBackend.API/DTOs/Question/CreateQuestionDTO.cs index 5fc9692..1f40d06 100644 --- a/SurveyBackend/SurveyBackend.API/DTOs/Question/CreateQuestionDTO.cs +++ b/SurveyBackend/SurveyBackend.API/DTOs/Question/CreateQuestionDTO.cs @@ -9,13 +9,9 @@ public class CreateQuestionDto /// Название вопроса /// 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/Mappers/QuestionMapper.cs b/SurveyBackend/SurveyBackend.API/Mappers/QuestionMapper.cs index dab60b9..e68b311 100644 --- a/SurveyBackend/SurveyBackend.API/Mappers/QuestionMapper.cs +++ b/SurveyBackend/SurveyBackend.API/Mappers/QuestionMapper.cs @@ -30,13 +30,13 @@ public static class QuestionMapper { Title = dto.Title, SurveyId = surveyId, - AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? [], + AnswerVariants = [], }, "multipleanswerquestion" => new MultipleAnswerQuestion { Title = dto.Title, SurveyId = surveyId, - AnswerVariants = dto.AnswerVariants?.Select(v => new AnswerVariant { Text = v }).ToList() ?? [] + AnswerVariants = [] }, _ => throw new BadRequestException("Unknown question type") }; diff --git a/SurveyBackend/SurveyBackend.Services/Services/QuestionService.cs b/SurveyBackend/SurveyBackend.Services/Services/QuestionService.cs index d62a28f..261eb2a 100644 --- a/SurveyBackend/SurveyBackend.Services/Services/QuestionService.cs +++ b/SurveyBackend/SurveyBackend.Services/Services/QuestionService.cs @@ -10,12 +10,14 @@ public class QuestionService : IQuestionService { private readonly IQuestionRepository _questionRepository; private readonly ISurveyRepository _surveyRepository; + private readonly IUserContext _userContext; public QuestionService(IQuestionRepository questionRepository, ISurveyRepository surveyRepository, IUserContext userContext) { _questionRepository = questionRepository; _surveyRepository = surveyRepository; + _userContext = userContext; } public async Task AddQuestionAsync(QuestionBase question)