using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SurveyBackend.Core.Contexts; using SurveyBackend.DTOs.Question; using SurveyBackend.Mappers.QuestionDTOs; using SurveyLib.Core.Services; namespace SurveyBackend.Controllers; [ApiController] [Route("api/questions")] public class QuestionController : ControllerBase { private readonly IQuestionService _questionService; public QuestionController(IQuestionService questionService, IUserContext userContext) { _questionService = questionService; } [AllowAnonymous] [HttpGet("by_survey/{id}")] public async Task GetBySurveyId(int id) { var questions = await _questionService.GetQuestionsBySurveyIdAsync(id); var result = questions.Select(QuestionOutputMapper.ModelToQuestionDTO).ToList(); return Ok(result); } [Authorize] [HttpPost] public async Task AddQuestion(CreateQuestionDto dto) { var model = QuestionCreationMapper.QuestionCreationToModel(dto); await _questionService.AddQuestionAsync(model); return Ok(); } }