add completions methods (not final)
This commit is contained in:
parent
58b5b2b17d
commit
c2f6ba6dde
4 changed files with 23 additions and 5 deletions
|
|
@ -26,14 +26,18 @@ public class CompletionController : ControllerBase
|
|||
[Authorize]
|
||||
public async Task<IActionResult> GetCompletionsAsync(int surveyId)
|
||||
{
|
||||
return NotFound();
|
||||
var models = await _completionService.GetCompletionsBySurveyIdAsync(surveyId);
|
||||
var result = models.Select(CompletionMapper.ModelToOutputDto);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetCompletionAsync(int id)
|
||||
{
|
||||
return NotFound();
|
||||
var model = await _completionService.GetCompletionByIdAsync(id);
|
||||
var result = CompletionMapper.ModelToOutputDto(model);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ namespace SurveyBackend.DTOs.Completion;
|
|||
|
||||
public class CompletionOutputDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int SurveyId { get; set; }
|
||||
public int? CompletedBy { get; set; }
|
||||
public DateTime FinishedAt { get; set; }
|
||||
public List<AnswerOutputDto> Answers { get; set; }
|
||||
}
|
||||
|
|
@ -14,8 +14,9 @@ public static class CompletionMapper
|
|||
|
||||
public static CompletionOutputDto ModelToOutputDto(Completion model) => new CompletionOutputDto
|
||||
{
|
||||
Id = model.Id,
|
||||
SurveyId = model.SurveyId,
|
||||
CompletedBy = model.CompletedBy,
|
||||
FinishedAt = model.FinishedAt,
|
||||
Answers = model.Answers.Select(AnswerMapper.ModelToOutputDto).ToList(),
|
||||
FinishedAt = model.FinishedAt
|
||||
};
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using SurveyBackend.Services.Exceptions;
|
||||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Core.Services;
|
||||
|
|
@ -31,6 +32,17 @@ public class CompletionService : ICompletionService
|
|||
await _completionRepository.DeleteAsync(id);
|
||||
}
|
||||
|
||||
public async Task<Completion> GetCompletionByIdAsync(int id)
|
||||
{
|
||||
var completion = await _completionRepository.GetByIdAsync(id);
|
||||
if (completion is null)
|
||||
{
|
||||
throw new NotFoundException("Completion not found");
|
||||
}
|
||||
|
||||
return completion;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Completion>> GetCompletionsBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue