using SurveyBackend.Services.Exceptions; using SurveyLib.Core.Models; using SurveyLib.Core.Repositories; using SurveyLib.Core.Services; namespace SurveyBackend.Services.Services; public class CompletionService : ICompletionService { private readonly ICompletionRepository _completionRepository; private readonly ISurveyRepository _surveyRepository; public CompletionService(ICompletionRepository completionRepository, ISurveyRepository surveyRepository) { _completionRepository = completionRepository; _surveyRepository = surveyRepository; } public async Task AddCompletionAsync(Completion completion) { var survey = await _surveyRepository.GetByIdAsync(completion.SurveyId); if (survey is null) { throw new NotFoundException("Survey not found"); } await _completionRepository.AddAsync(completion); } public async Task UpdateCompletionAsync(Completion completion) { // TODO: лол а что вообще значит ОбновитьВыполнение, надо выпилить из SurveyLib await _completionRepository.UpdateAsync(completion); } public async Task DeleteCompletionAsync(int id) { // TODO: да и удалять их как-то бессмысленно 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) { var survey = await _surveyRepository.GetByIdAsync(surveyId); if (survey is null) { throw new NotFoundException("Survey not found"); } // TODO: проверить что запрашивает создатель (хз как) return await _completionRepository.GetCompletionsBySurveyIdAsync(surveyId); } }