This commit is contained in:
SpecialX
2025-06-27 19:03:10 +08:00
parent 14fbe6397a
commit a21ca80782
57 changed files with 3872 additions and 611 deletions

View File

@@ -1,6 +1,9 @@
using Entities.DTO;
using Entities.Contracts;
using Entities.DTO;
using Newtonsoft.Json;
using System.Net.Http.Json;
using TechHelper.Client.HttpRepository;
using TechHelper.Services;
namespace TechHelper.Client.Services
{
@@ -20,6 +23,21 @@ namespace TechHelper.Client.Services
throw new NotImplementedException();
}
public async Task<ApiResponse> GetClassStudents()
{
try
{
var result = await _client.PostAsJsonAsync("class/getClassStudents","");
var content = await result.Content.ReadAsStringAsync();
var users = JsonConvert.DeserializeObject<List<StudentDto>>(content);
return ApiResponse.Success(result: users);
}
catch(Exception ex)
{
return ApiResponse.Error($"获取失败,{ex.Message}, InnerException: {ex.InnerException}");
}
}
public async Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto)
{
try

View File

@@ -9,13 +9,13 @@ namespace TechHelper.Client.Services
{
public class ExamService : IExamService
{
private readonly IAIService _aIService;
private readonly HttpClient _client;
private readonly IAIService _aIService;
private readonly HttpClient _client;
public ExamService(IAIService aIService, HttpClient client)
public ExamService(IAIService aIService, HttpClient client)
{
_aIService = aIService;
_client = client;
_client = client;
}
public ApiResponse ConvertToXML<T>(string xmlContent)
@@ -86,9 +86,9 @@ namespace TechHelper.Client.Services
}
}
public async Task<ApiResponse> GetAllExam(string user)
public async Task<ApiResponse> GetAllExam()
{
var response = await _client.GetAsync($"exam/getAllPreview?user={user}");
var response = await _client.GetAsync($"exam/getAllPreview");
if (response.IsSuccessStatusCode)
{
@@ -104,6 +104,25 @@ namespace TechHelper.Client.Services
}
}
public async Task<ApiResponse> GetAllSubmission()
{
try
{
var response = await _client.GetAsync($"exam/getAllSubmission");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var exam = JsonConvert.DeserializeObject<AssignmentDto>(content);
return ApiResponse.Success();
}
return ApiResponse.Error(message: "获取失败");
}
catch (Exception ex)
{
return ApiResponse.Error(message: $"内部错误{ex.Message}, InerEx{ex.InnerException}");
}
}
public async Task<ApiResponse> GetExam(Guid guid)
{
@@ -158,5 +177,18 @@ namespace TechHelper.Client.Services
return ApiResponse.Error(message: $"保存试题失败: {response.StatusCode} - {errorContent}");
}
}
public async Task<ApiResponse> SubmissionAssignment(SubmissionDto submission)
{
var response = await _client.PostAsJsonAsync("exam/submission", submission);
if (response.IsSuccessStatusCode)
{
return ApiResponse.Success("提交成功");
}
else
{
return ApiResponse.Error("提交失败");
}
}
}
}

View File

@@ -8,5 +8,6 @@ namespace TechHelper.Client.Services
{
public Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto);
public Task<ResponseDto> CreateClass(UserRegistrationToClassDto userClass);
public Task<ApiResponse> GetClassStudents();
}
}

View File

@@ -11,7 +11,9 @@ namespace TechHelper.Client.Services
public Task<ApiResponse> ParseSingleQuestionGroup(string examContent);
public ApiResponse ConvertToXML<T>(string xmlContent);
public Task<ApiResponse> GetAllExam(string user);
public Task<ApiResponse> GetAllExam();
public Task<ApiResponse> GetExam(Guid guid);
public Task<ApiResponse> SubmissionAssignment(SubmissionDto submission);
public Task<ApiResponse> GetAllSubmission();
}
}