add basic versions of retrieving answers by question or completion
This commit is contained in:
parent
637e6c9824
commit
d73e0a104f
7 changed files with 95 additions and 16 deletions
|
|
@ -0,0 +1,37 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.Mappers;
|
||||
using SurveyLib.Core.Services;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
public class AnswerController : ControllerBase
|
||||
{
|
||||
private readonly IAnswerService _answerService;
|
||||
|
||||
public AnswerController(IAnswerService answerService)
|
||||
{
|
||||
_answerService = answerService;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
[Route("api/questions/{id:int}/answers")]
|
||||
public async Task<IActionResult> GetAnswersByQuestionId(int id)
|
||||
{
|
||||
var models = await _answerService.GetAnswersByQuestionIdAsync(id);
|
||||
var result = models.Select(AnswerMapper.ModelToOutputDto);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
[Route("api/completions/{id:int}/answers")]
|
||||
public async Task<IActionResult> GetAnswersByCompletionId(int id)
|
||||
{
|
||||
var models = await _answerService.GetAnswersByCompletionIdAsync(id);
|
||||
var result = models.Select(AnswerMapper.ModelToOutputDto);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue