重构作业结构:优化实体模型、DTO映射和前端界面
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 13s

- 重构AppMainStruct、AssignmentQuestion、Question等实体模型
- 更新相关DTO以匹配新的数据结构
- 优化前端页面布局和组件
- 添加全局信息和笔记功能相关代码
- 更新数据库迁移和程序配置
This commit is contained in:
SpecialX
2025-09-04 15:43:33 +08:00
parent 730b0ba04b
commit 6a65281850
58 changed files with 5459 additions and 244 deletions

View File

@@ -0,0 +1,151 @@
using Entities.DTO;
using System.Net.Http.Json;
using TechHelper.Client.AI;
using TechHelper.Services;
namespace TechHelper.Client.Services
{
public class NoteService : INoteService
{
private readonly HttpClient _client;
public NoteService(HttpClient client)
{
_client = client;
}
/// <summary>
/// 添加一个新笔记
/// </summary>
/// <param name="dto">包含笔记数据的数据传输对象</param>
/// <returns>操作结果</returns>
public async Task<ApiResponse> AddNote(GlobalDto dto)
{
try
{
var response = await _client.PostAsJsonAsync("note", dto);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadFromJsonAsync<ApiResponse>();
return result ?? ApiResponse.Success("操作成功。");
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error($"添加失败。状态码: {response.StatusCode}。详情: {errorContent}");
}
}
catch (HttpRequestException ex)
{
return ApiResponse.Error($"网络请求错误: {ex.Message}");
}
}
/// <summary>
/// 根据 ID 删除一个笔记
/// </summary>
/// <param name="id">要删除的笔记的 ID</param>
/// <returns>操作结果</returns>
public async Task<ApiResponse> DeleteNote(byte id)
{
try
{
var response = await _client.DeleteAsync($"note/{id}");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadFromJsonAsync<ApiResponse>();
return result ?? ApiResponse.Success("删除成功。");
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error($"删除失败。状态码: {response.StatusCode}。详情: {errorContent}");
}
}
catch (HttpRequestException ex)
{
return ApiResponse.Error($"网络请求错误: {ex.Message}");
}
}
/// <summary>
/// 获取所有笔记
/// </summary>
/// <returns>包含所有笔记列表的操作结果</returns>
public async Task<ApiResponse> GetAllNotes()
{
try
{
var response = await _client.GetAsync("note");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadFromJsonAsync<ApiResponse>();
return result ?? ApiResponse.Success("获取成功。");
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error($"获取失败。状态码: {response.StatusCode}。详情: {errorContent}");
}
}
catch (HttpRequestException ex)
{
return ApiResponse.Error($"网络请求错误: {ex.Message}");
}
}
/// <summary>
/// 根据 ID 获取单个笔记
/// </summary>
/// <param name="id">要获取的笔记的 ID</param>
/// <returns>包含单个笔记数据的操作结果</returns>
public async Task<ApiResponse> GetNote(byte id)
{
try
{
var response = await _client.GetAsync($"note/{id}");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadFromJsonAsync<ApiResponse>();
return result ?? ApiResponse.Success("获取成功。");
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error($"获取失败。状态码: {response.StatusCode}。详情: {errorContent}");
}
}
catch (HttpRequestException ex)
{
return ApiResponse.Error($"网络请求错误: {ex.Message}");
}
}
public async Task<ApiResponse> UpdateNote(GlobalDto dto)
{
try
{
var response = await _client.PutAsJsonAsync("note", dto);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadFromJsonAsync<ApiResponse>();
return result ?? ApiResponse.Success("更新成功。");
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
return ApiResponse.Error($"更新失败。状态码: {response.StatusCode}。详情: {errorContent}");
}
}
catch (HttpRequestException ex)
{
return ApiResponse.Error($"网络请求错误: {ex.Message}");
}
}
}
}