- 添加学生提交管理服务 (StudentSubmissionService, StudentSubmissionDetailService) - 新增学生提交相关控制器 (StudentSubmissionController, StudentSubmissionDetailController) - 添加学生提交数据传输对象 (StudentSubmissionDetailDto, StudentSubmissionSummaryDto) - 新增学生提交相关页面组件 (StudentExamView, ExamDetailView, StudentCard等) - 添加学生提交信息卡片组件 (SubmissionInfoCard, TeacherSubmissionInfoCard) - 更新数据库迁移文件以支持提交系统
This commit is contained in:
127
TechHelper.Server/Controllers/StudentSubmissionController.cs
Normal file
127
TechHelper.Server/Controllers/StudentSubmissionController.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using Entities.Contracts;
|
||||
using Entities.DTO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TechHelper.Server.Services;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace TechHelper.Server.Controllers
|
||||
{
|
||||
[Route("api/student-submission")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class StudentSubmissionController : ControllerBase
|
||||
{
|
||||
private readonly IStudentSubmissionService _studentSubmissionService;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public StudentSubmissionController(
|
||||
IStudentSubmissionService studentSubmissionService,
|
||||
UserManager<User> userManager)
|
||||
{
|
||||
_studentSubmissionService = studentSubmissionService;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前学生的所有提交摘要
|
||||
/// </summary>
|
||||
/// <returns>学生提交摘要列表</returns>
|
||||
[HttpGet("my-submissions")]
|
||||
public async Task<IActionResult> GetMySubmissions()
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(User.Identity.Name);
|
||||
if (user == null)
|
||||
return NotFound("未找到用户信息");
|
||||
|
||||
var result = await _studentSubmissionService.GetStudentSubmissionsAsync(user.Id);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前学生的提交摘要(分页)
|
||||
/// </summary>
|
||||
/// <param name="pageNumber">页码,默认为1</param>
|
||||
/// <param name="pageSize">每页数量,默认为10</param>
|
||||
/// <returns>分页的学生提交摘要列表</returns>
|
||||
[HttpGet("my-submissions-paged")]
|
||||
public async Task<IActionResult> GetMySubmissionsPaged(int pageNumber = 1, int pageSize = 10)
|
||||
{
|
||||
if (pageNumber < 1) pageNumber = 1;
|
||||
if (pageSize < 1) pageSize = 10;
|
||||
if (pageSize > 100) pageSize = 100; // 限制最大页面大小
|
||||
|
||||
var user = await _userManager.FindByEmailAsync(User.Identity.Name);
|
||||
if (user == null)
|
||||
return NotFound("未找到用户信息");
|
||||
|
||||
var result = await _studentSubmissionService.GetStudentSubmissionsPagedAsync(user.Id, pageNumber, pageSize);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定学生的提交摘要(仅教师可使用)
|
||||
/// </summary>
|
||||
/// <param name="studentId">学生ID</param>
|
||||
/// <returns>学生提交摘要列表</returns>
|
||||
[HttpGet("student/{studentId:guid}")]
|
||||
[Authorize(Roles = "Teacher")]
|
||||
public async Task<IActionResult> GetStudentSubmissions(Guid studentId)
|
||||
{
|
||||
var result = await _studentSubmissionService.GetStudentSubmissionsAsync(studentId);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定学生的提交摘要(分页,仅教师可使用)
|
||||
/// </summary>
|
||||
/// <param name="studentId">学生ID</param>
|
||||
/// <param name="pageNumber">页码,默认为1</param>
|
||||
/// <param name="pageSize">每页数量,默认为10</param>
|
||||
/// <returns>分页的学生提交摘要列表</returns>
|
||||
[HttpGet("student/{studentId:guid}/paged")]
|
||||
[Authorize(Roles = "Teacher")]
|
||||
public async Task<IActionResult> GetStudentSubmissionsPaged(Guid studentId, int pageNumber = 1, int pageSize = 10)
|
||||
{
|
||||
if (pageNumber < 1) pageNumber = 1;
|
||||
if (pageSize < 1) pageSize = 10;
|
||||
if (pageSize > 100) pageSize = 100; // 限制最大页面大小
|
||||
|
||||
var result = await _studentSubmissionService.GetStudentSubmissionsPagedAsync(studentId, pageNumber, pageSize);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
using Entities.Contracts;
|
||||
using Entities.DTO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TechHelper.Server.Services;
|
||||
using TechHelper.Context;
|
||||
using TechHelper.Repository;
|
||||
using SharedDATA.Api;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace TechHelper.Server.Controllers
|
||||
{
|
||||
[Route("api/student-submission-detail")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class StudentSubmissionDetailController : ControllerBase
|
||||
{
|
||||
private readonly IStudentSubmissionDetailService _studentSubmissionDetailService;
|
||||
private readonly UserManager<User> _userManager;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public StudentSubmissionDetailController(
|
||||
IStudentSubmissionDetailService studentSubmissionDetailService,
|
||||
UserManager<User> userManager,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_studentSubmissionDetailService = studentSubmissionDetailService;
|
||||
_userManager = userManager;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取学生提交的详细信息
|
||||
/// </summary>
|
||||
/// <param name="submissionId">提交ID</param>
|
||||
/// <returns>学生提交详细信息</returns>
|
||||
[HttpGet("{submissionId:guid}")]
|
||||
public async Task<IActionResult> GetSubmissionDetail(Guid submissionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证用户权限 - 只有学生本人或教师可以查看
|
||||
var user = await _userManager.FindByEmailAsync(User.Identity.Name);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound("未找到用户信息");
|
||||
}
|
||||
|
||||
var submission = await _unitOfWork.GetRepository<Submission>()
|
||||
.GetFirstOrDefaultAsync(predicate: s => s.Id == submissionId);
|
||||
|
||||
if (submission == null)
|
||||
{
|
||||
return NotFound("未找到指定的提交记录");
|
||||
}
|
||||
|
||||
// 检查权限:学生只能查看自己的提交,教师可以查看所有提交
|
||||
if (user.Id != submission.StudentId && !User.IsInRole("Teacher"))
|
||||
{
|
||||
return Forbid("您没有权限查看此提交记录");
|
||||
}
|
||||
|
||||
var result = await _studentSubmissionDetailService.GetSubmissionDetailAsync(submissionId);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, $"获取学生提交详细信息失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user