diff --git a/SurveyBackend/SurveyBackend.API/Controllers/CompletionController.cs b/SurveyBackend/SurveyBackend.API/Controllers/CompletionController.cs index 72a8fda..cae1bc9 100644 --- a/SurveyBackend/SurveyBackend.API/Controllers/CompletionController.cs +++ b/SurveyBackend/SurveyBackend.API/Controllers/CompletionController.cs @@ -26,14 +26,18 @@ public class CompletionController : ControllerBase [Authorize] public async Task 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 GetCompletionAsync(int id) { - return NotFound(); + var model = await _completionService.GetCompletionByIdAsync(id); + var result = CompletionMapper.ModelToOutputDto(model); + return Ok(result); } [HttpPost] diff --git a/SurveyBackend/SurveyBackend.API/DTOs/Completion/CompletionOutputDto.cs b/SurveyBackend/SurveyBackend.API/DTOs/Completion/CompletionOutputDto.cs index 0514242..d546267 100644 --- a/SurveyBackend/SurveyBackend.API/DTOs/Completion/CompletionOutputDto.cs +++ b/SurveyBackend/SurveyBackend.API/DTOs/Completion/CompletionOutputDto.cs @@ -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 Answers { get; set; } } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs b/SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs index 9596947..3eb1edf 100644 --- a/SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs +++ b/SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs @@ -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 }; } \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.Services/Services/CompletionService.cs b/SurveyBackend/SurveyBackend.Services/Services/CompletionService.cs index 8d2e633..655c9dd 100644 --- a/SurveyBackend/SurveyBackend.Services/Services/CompletionService.cs +++ b/SurveyBackend/SurveyBackend.Services/Services/CompletionService.cs @@ -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 GetCompletionByIdAsync(int id) + { + var completion = await _completionRepository.GetByIdAsync(id); + if (completion is null) + { + throw new NotFoundException("Completion not found"); + } + + return completion; + } + public async Task> GetCompletionsBySurveyIdAsync(int surveyId) { // TODO: проверить существование опроса