- refactored SurveyController.cs - added ProducesResponseType to every endpoint in every controller - remade mappers
42 lines
No EOL
1.4 KiB
C#
42 lines
No EOL
1.4 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SurveyBackend.Core.Contexts;
|
|
using SurveyBackend.DTOs.Question;
|
|
using SurveyBackend.Mappers;
|
|
using SurveyLib.Core.Services;
|
|
|
|
namespace SurveyBackend.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("surveys/{surveyId}/questions")]
|
|
public class QuestionController : ControllerBase
|
|
{
|
|
private readonly IQuestionService _questionService;
|
|
|
|
public QuestionController(IQuestionService questionService, IUserContext userContext)
|
|
{
|
|
_questionService = questionService;
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpGet]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(List<OutputQuestionDto>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetBySurveyId([FromRoute] int surveyId)
|
|
{
|
|
var questions = await _questionService.GetQuestionsBySurveyIdAsync(surveyId);
|
|
var result = questions.Select(QuestionMapper.ModelToQuestionDto).ToList();
|
|
return Ok(result);
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPost]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
|
public async Task<IActionResult> AddQuestion(CreateQuestionDto dto, [FromRoute] int surveyId)
|
|
{
|
|
var model = QuestionMapper.QuestionCreationToModel(dto, surveyId);
|
|
await _questionService.AddQuestionAsync(model);
|
|
return Created();
|
|
}
|
|
} |