重构项目结构,移除Assignment相关功能,优化Submission模块
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 12s
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 12s
This commit is contained in:
@@ -9,18 +9,18 @@ namespace TechHelper.Server.Repositories
|
||||
public class ExamRepository : IExamRepository
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IRepository<Assignment> _assignmentRepo;
|
||||
private readonly IRepository<Exam> _assignmentRepo;
|
||||
private readonly IRepository<Question> _questionRepo;
|
||||
private readonly IRepository<AssignmentQuestion> _assignQuestionRepo;
|
||||
private readonly IRepository<ExamQuestion> _assignQuestionRepo;
|
||||
|
||||
public ExamRepository(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_assignmentRepo = _unitOfWork.GetRepository<Assignment>();
|
||||
_assignQuestionRepo = _unitOfWork.GetRepository<AssignmentQuestion>();
|
||||
_assignmentRepo = _unitOfWork.GetRepository<Exam>();
|
||||
_assignQuestionRepo = _unitOfWork.GetRepository<ExamQuestion>();
|
||||
}
|
||||
|
||||
public async Task<Assignment?> GetFullExamByIdAsync(Guid assignmentId)
|
||||
public async Task<Exam?> GetFullExamByIdAsync(Guid assignmentId)
|
||||
{
|
||||
var result = await _assignmentRepo.GetFirstOrDefaultAsync(
|
||||
predicate:
|
||||
@@ -35,12 +35,12 @@ namespace TechHelper.Server.Repositories
|
||||
}
|
||||
|
||||
|
||||
public async Task<AssignmentQuestion?> GetNeed(Guid id)
|
||||
public async Task<ExamQuestion?> GetNeed(Guid id)
|
||||
{
|
||||
var result = await _assignQuestionRepo.GetFirstOrDefaultAsync(
|
||||
predicate: aq => aq.Id == id,
|
||||
include: i => i
|
||||
.Include(aq => aq.ChildrenAssignmentQuestion)
|
||||
.Include(aq => aq.ChildExamQuestions)
|
||||
.Include(aq => aq.Question)
|
||||
.ThenInclude(q => q.Lesson)
|
||||
.Include(aq => aq.Question)
|
||||
@@ -52,8 +52,8 @@ namespace TechHelper.Server.Repositories
|
||||
return null;
|
||||
}
|
||||
|
||||
var loadedChildren = new List<AssignmentQuestion>();
|
||||
foreach (var child in result.ChildrenAssignmentQuestion)
|
||||
var loadedChildren = new List<ExamQuestion>();
|
||||
foreach (var child in result.ChildExamQuestions)
|
||||
{
|
||||
var loadedChild = await GetNeed(child.Id);
|
||||
if (loadedChild != null)
|
||||
@@ -61,25 +61,25 @@ namespace TechHelper.Server.Repositories
|
||||
loadedChildren.Add(loadedChild);
|
||||
}
|
||||
}
|
||||
result.ChildrenAssignmentQuestion = loadedChildren;
|
||||
result.ChildExamQuestions = loadedChildren;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<IEnumerable<Assignment>> GetExamPreviewsByUserAsync(Guid userId)
|
||||
public async Task<IEnumerable<Exam>> GetExamPreviewsByUserAsync(Guid userId)
|
||||
{
|
||||
return await _assignmentRepo.GetAllAsync(
|
||||
predicate: a => a.CreatorId == userId && !a.IsDeleted);
|
||||
}
|
||||
|
||||
public async Task AddAsync(Assignment assignment)
|
||||
public async Task AddAsync(Exam assignment)
|
||||
{
|
||||
await _assignmentRepo.InsertAsync(assignment);
|
||||
}
|
||||
|
||||
public async Task AddAsync(AssignmentQuestion assignment)
|
||||
public async Task AddAsync(ExamQuestion assignment)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -87,21 +87,17 @@ namespace TechHelper.Server.Repositories
|
||||
{
|
||||
}
|
||||
|
||||
public async Task AddAsync(AssignmentClass assignment)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task AddAsync(Submission submission)
|
||||
{
|
||||
await _unitOfWork.GetRepository<Submission>().InsertAsync(submission);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Assignment>> GetAllSubmissionPreviewsByUserAsync(Guid id)
|
||||
public async Task<IEnumerable<Exam>> GetAllSubmissionPreviewsByUserAsync(Guid id)
|
||||
{
|
||||
var submissions = await _unitOfWork.GetRepository<Submission>().GetAllAsync(predicate: s => s.StudentId == id, include: i => i.Include(s => s.Assignment));
|
||||
var submissions = await _unitOfWork.GetRepository<Submission>().GetAllAsync(predicate: s => s.StudentId == id, include: i => i.Include(s => s.Exam));
|
||||
if (submissions == null || !submissions.Any())
|
||||
return Enumerable.Empty<Assignment>();
|
||||
return submissions.ToList().Select(s => s.Assignment).Where(a => a != null).ToList();
|
||||
return Enumerable.Empty<Exam>();
|
||||
return submissions.ToList().Select(s => s.Exam).Where(a => a != null).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,29 @@ namespace TechHelper.Server.Repositories
|
||||
/// </summary>
|
||||
/// <param name="assignmentId">试卷ID</param>
|
||||
/// <returns>完整的 Assignment 实体,如果找不到则返回 null。</returns>
|
||||
Task<Assignment?> GetFullExamByIdAsync(Guid assignmentId);
|
||||
Task<Exam?> GetFullExamByIdAsync(Guid assignmentId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定用户创建的所有试卷的预览信息。
|
||||
/// </summary>
|
||||
/// <param name="userId">用户ID</param>
|
||||
/// <returns>Assignment 实体集合。</returns>
|
||||
Task<IEnumerable<Assignment>> GetExamPreviewsByUserAsync(Guid userId);
|
||||
Task<IEnumerable<Exam>> GetExamPreviewsByUserAsync(Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// 向数据库添加一个新的试卷。
|
||||
/// </summary>
|
||||
/// <param name="assignment">要添加的试卷实体。</param>
|
||||
Task AddAsync(Assignment assignment);
|
||||
Task AddAsync(Exam assignment);
|
||||
Task AddAsync(Submission submission);
|
||||
|
||||
|
||||
|
||||
|
||||
Task AddAsync(AssignmentQuestion assignment);
|
||||
Task AddAsync(ExamQuestion assignment);
|
||||
|
||||
Task AddAsync(Question assignment);
|
||||
|
||||
Task AddAsync(AssignmentClass assignment);
|
||||
Task<IEnumerable<Assignment>> GetAllSubmissionPreviewsByUserAsync(Guid id);
|
||||
Task<IEnumerable<Exam>> GetAllSubmissionPreviewsByUserAsync(Guid id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user