added existance check (not sure if it's working)
This commit is contained in:
parent
9a7c74e307
commit
a5aad09046
4 changed files with 78 additions and 13 deletions
|
|
@ -8,15 +8,22 @@ namespace SurveyBackend.Services.Services;
|
|||
public class CompletionService : ICompletionService
|
||||
{
|
||||
private readonly ICompletionRepository _completionRepository;
|
||||
private readonly ISurveyRepository _surveyRepository;
|
||||
|
||||
public CompletionService(ICompletionRepository completionRepository)
|
||||
public CompletionService(ICompletionRepository completionRepository, ISurveyRepository surveyRepository)
|
||||
{
|
||||
_completionRepository = completionRepository;
|
||||
_surveyRepository = surveyRepository;
|
||||
}
|
||||
|
||||
public async Task AddCompletionAsync(Completion completion)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
var survey = await _surveyRepository.GetByIdAsync(completion.SurveyId);
|
||||
if (survey is null)
|
||||
{
|
||||
throw new NotFoundException("Survey not found");
|
||||
}
|
||||
|
||||
await _completionRepository.AddAsync(completion);
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +52,12 @@ public class CompletionService : ICompletionService
|
|||
|
||||
public async Task<IEnumerable<Completion>> GetCompletionsBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
var survey = await _surveyRepository.GetByIdAsync(surveyId);
|
||||
if (survey is null)
|
||||
{
|
||||
throw new NotFoundException("Survey not found");
|
||||
}
|
||||
|
||||
// TODO: проверить что запрашивает создатель (хз как)
|
||||
return await _completionRepository.GetCompletionsBySurveyIdAsync(surveyId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue