Files
TechHelper/TechHelper.Client/Services/StudentSubmissionService.cs
SpecialX ac900159ba
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 12s
重构项目结构,移除Assignment相关功能,优化Submission模块
2025-10-09 18:57:28 +08:00

74 lines
2.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Newtonsoft.Json;
using Entities.DTO;
namespace TechHelper.Client.Services
{
public class StudentSubmissionService : IStudentSubmissionService
{
private readonly HttpClient _client;
public StudentSubmissionService(HttpClient client)
{
_client = client;
}
/// <summary>
/// 获取当前学生的所有提交摘要
/// </summary>
/// <returns>学生提交摘要列表</returns>
public async Task<ApiResponse> GetMySubmissionsAsync()
{
try
{
var response = await _client.GetAsync("student-submission/my-submissions");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var submissions = JsonConvert.DeserializeObject<List<StudentSubmissionSummaryDto>>(content);
return ApiResponse.Success(result: submissions);
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error(message: $"获取学生提交信息失败: {response.StatusCode} - {errorContent}");
}
}
catch (Exception ex)
{
return ApiResponse.Error(message: $"内部错误: {ex.Message}");
}
}
/// <summary>
/// 获取当前学生的提交摘要(分页)
/// </summary>
/// <param name="pageNumber">页码默认为1</param>
/// <param name="pageSize">每页数量默认为10</param>
/// <returns>分页的学生提交摘要列表</returns>
public async Task<ApiResponse> GetMySubmissionsPagedAsync(int pageNumber = 1, int pageSize = 10)
{
try
{
var response = await _client.GetAsync($"student-submission/my-submissions-paged?pageNumber={pageNumber}&pageSize={pageSize}");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<StudentSubmissionSummaryResponseDto>(content);
return ApiResponse.Success(result: result);
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error(message: $"获取学生提交信息失败: {response.StatusCode} - {errorContent}");
}
}
catch (Exception ex)
{
return ApiResponse.Error(message: $"内部错误: {ex.Message}");
}
}
}
}