exam_service

This commit is contained in:
SpecialX
2025-06-11 15:02:20 +08:00
parent 97843ab5fd
commit e26881ec2f
52 changed files with 3510 additions and 1174 deletions

View File

@@ -2,6 +2,9 @@
using TechHelper.Client.AI;
using TechHelper.Services;
using Entities.DTO;
using System.Net.Http.Json;
using Newtonsoft.Json;
using TechHelper.Client.Pages.Exam;
namespace TechHelper.Client.Exam
@@ -9,10 +12,13 @@ namespace TechHelper.Client.Exam
public class ExamService : IExamService
{
private IAIService aIService;
private IHttpClientFactory httpClientFactory;
public ExamService(IAIService aIService)
public ExamService(IAIService aIService,
IHttpClientFactory httpClientFactory)
{
this.aIService = aIService;
this.httpClientFactory = httpClientFactory;
}
public ApiResponse ConvertToXML<T>(string xmlContent)
@@ -86,7 +92,7 @@ namespace TechHelper.Client.Exam
{
Status = false,
Result = null,
Message = $"处理试题分割时发生内部错误: {ex.Message}"
Message = $"处理试题分割时发生内部错误: {ex.Message}"
};
}
}
@@ -127,6 +133,31 @@ namespace TechHelper.Client.Exam
}
}
public async Task<ApiResponse> GetAllExam(string user)
{
using (var client = httpClientFactory.CreateClient("Default"))
{
var response = await client.GetAsync($"exam/getAllPreview?user={user}");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<List<ExamDto>>(content);
return ApiResponse.Success(result: result);
}
else
{
return ApiResponse.Error(await response.Content.ReadAsStringAsync());
}
}
}
public async Task<ApiResponse> GetExam(Guid guid)
{
return ApiResponse.Success("HELLO");
}
public async Task<ApiResponse> ParseSingleQuestionGroup(string examContent)
{
try
@@ -163,9 +194,19 @@ namespace TechHelper.Client.Exam
}
}
public Task<ApiResponse> SaveParsedExam(ExamDto examDto)
public async Task<ApiResponse> SaveParsedExam(ExamDto examDto)
{
throw new NotImplementedException();
using (var client = httpClientFactory.CreateClient("Default"))
{
var respont = await client.PostAsJsonAsync("exam/add",
examDto);
if (respont.StatusCode == System.Net.HttpStatusCode.OK)
{
return new ApiResponse(true, "ok");
}
return new ApiResponse("false");
}
}
}
}