overthinking repositories from scratch
This commit is contained in:
parent
58271df949
commit
845db13c63
8 changed files with 4 additions and 51 deletions
|
|
@ -4,6 +4,5 @@ namespace SurveyLib.Core.Repositories;
|
|||
|
||||
public interface IAnswerRepository : IGenericRepository<Answer>
|
||||
{
|
||||
Task<IEnumerable<Answer>> GetByAttemptIdAsync(int attemptId);
|
||||
Task<IEnumerable<Answer>> GetByQuestionIdAsync(int questionId);
|
||||
|
||||
}
|
||||
|
|
@ -4,5 +4,5 @@ namespace SurveyLib.Core.Repositories;
|
|||
|
||||
public interface ICompletionRepository : IGenericRepository<Completion>
|
||||
{
|
||||
Task<IEnumerable<Completion>> GetBySurveyIdAsync(int surveyId);
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,5 @@ namespace SurveyLib.Core.Repositories;
|
|||
|
||||
public interface IQuestionRepository : IGenericRepository<QuestionBase>
|
||||
{
|
||||
Task<QuestionBase?> GetWithAnswersAsync(int questionId);
|
||||
Task<IEnumerable<QuestionBase>> GetBySurveyIdAsync(int surveyId);
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,5 @@ namespace SurveyLib.Core.Repositories;
|
|||
|
||||
public interface ISurveyRepository : IGenericRepository<Survey>
|
||||
{
|
||||
Task<Survey?> GetWithQuestionsAsync(int surveyId);
|
||||
Task<Survey?> GetWithCompletionsAsync(int surveyId);
|
||||
Task<IEnumerable<Survey>> FindByTitleAsync(string title);
|
||||
|
||||
}
|
||||
|
|
@ -41,14 +41,4 @@ public class AnswerRepository : IAnswerRepository
|
|||
_context.Answers.Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Answer>> GetByAttemptIdAsync(int attemptId)
|
||||
{
|
||||
return await _context.Answers.Where(a => a.CompletionId == attemptId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Answer>> GetByQuestionIdAsync(int questionId)
|
||||
{
|
||||
return await _context.Answers.Where(a => a.QuestionId == questionId).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +41,4 @@ public class CompletionRepository : ICompletionRepository
|
|||
_context.Completions.Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Completion>> GetBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
return await _context.Completions.Where(c => c.SurveyId == surveyId).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -41,15 +41,4 @@ public class QuestionRepository : IQuestionRepository
|
|||
_context.Questions.Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<QuestionBase?> GetWithAnswersAsync(int questionId)
|
||||
{
|
||||
return await _context.Questions.Include(q => q.Answers)
|
||||
.FirstOrDefaultAsync(q => q.Id == questionId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<QuestionBase>> GetBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
return await _context.Questions.Where(q => q.SurveyId == surveyId).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
|
@ -41,21 +41,4 @@ public class SurveyRepository : ISurveyRepository
|
|||
_context.Surveys.Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<Survey?> GetWithQuestionsAsync(int surveyId)
|
||||
{
|
||||
return await _context.Surveys.Include(survey => survey.Questions)
|
||||
.FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||
}
|
||||
|
||||
public async Task<Survey?> GetWithCompletionsAsync(int surveyId)
|
||||
{
|
||||
return await _context.Surveys.Include(survey => survey.Completions)
|
||||
.FirstOrDefaultAsync(s => s.Id == surveyId);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Survey>> FindByTitleAsync(string title)
|
||||
{
|
||||
return await _context.Surveys.Where(s => s.Title.ToLower().Contains(title.ToLower())).ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue