life quality changes
- refactored SurveyController.cs - added ProducesResponseType to every endpoint in every controller - remade mappers
This commit is contained in:
parent
9e50b97bc9
commit
6692a91821
11 changed files with 146 additions and 93 deletions
|
|
@ -2,13 +2,13 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.Core.Contexts;
|
||||
using SurveyBackend.DTOs.Question;
|
||||
using SurveyBackend.Mappers.QuestionDTOs;
|
||||
using SurveyBackend.Mappers;
|
||||
using SurveyLib.Core.Services;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/questions")]
|
||||
[Route("surveys/{surveyId}/questions")]
|
||||
public class QuestionController : ControllerBase
|
||||
{
|
||||
private readonly IQuestionService _questionService;
|
||||
|
|
@ -19,20 +19,24 @@ public class QuestionController : ControllerBase
|
|||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("by_survey/{id}")]
|
||||
public async Task<IActionResult> GetBySurveyId(int id)
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(List<OutputQuestionDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetBySurveyId([FromRoute] int surveyId)
|
||||
{
|
||||
var questions = await _questionService.GetQuestionsBySurveyIdAsync(id);
|
||||
var result = questions.Select(QuestionOutputMapper.ModelToQuestionDTO).ToList();
|
||||
var questions = await _questionService.GetQuestionsBySurveyIdAsync(surveyId);
|
||||
var result = questions.Select(QuestionMapper.ModelToQuestionDto).ToList();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> AddQuestion(CreateQuestionDto dto)
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
public async Task<IActionResult> AddQuestion(CreateQuestionDto dto, [FromRoute] int surveyId)
|
||||
{
|
||||
var model = QuestionCreationMapper.QuestionCreationToModel(dto);
|
||||
var model = QuestionMapper.QuestionCreationToModel(dto, surveyId);
|
||||
await _questionService.AddQuestionAsync(model);
|
||||
return Ok();
|
||||
return Created();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue