重构作业结构:优化实体模型、DTO映射和前端界面
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 13s
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 13s
- 重构AppMainStruct、AssignmentQuestion、Question等实体模型 - 更新相关DTO以匹配新的数据结构 - 优化前端页面布局和组件 - 添加全局信息和笔记功能相关代码 - 更新数据库迁移和程序配置
This commit is contained in:
91
TechHelper.Server/Controllers/NoteController.cs
Normal file
91
TechHelper.Server/Controllers/NoteController.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Entities.DTO;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Server.Controllers
|
||||
{
|
||||
[Route("api/note")]
|
||||
[ApiController]
|
||||
public class NoteController : ControllerBase
|
||||
{
|
||||
private readonly INoteService _noteService;
|
||||
|
||||
// 通过依赖注入获取 NoteService
|
||||
public NoteController(INoteService noteService)
|
||||
{
|
||||
_noteService = noteService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有全局数据。
|
||||
/// GET: api/Note
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] QueryParameter query)
|
||||
{
|
||||
var response = await _noteService.GetAllAsync(query);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 ID 获取单个全局数据。
|
||||
/// GET: api/Note/{id}
|
||||
/// </summary>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> Get(byte id)
|
||||
{
|
||||
var response = await _noteService.GetAsync(id);
|
||||
if (!response.Status)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加新的全局数据。
|
||||
/// POST: api/Note
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Add([FromBody] GlobalDto model)
|
||||
{
|
||||
var response = await _noteService.AddAsync(model);
|
||||
if (!response.Status)
|
||||
{
|
||||
return BadRequest(response);
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新已存在的全局数据。
|
||||
/// PUT: api/Note
|
||||
/// </summary>
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> Update([FromBody] GlobalDto model)
|
||||
{
|
||||
var response = await _noteService.UpdateAsync(model);
|
||||
if (!response.Status)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 ID 删除全局数据。
|
||||
/// DELETE: api/Note/{id}
|
||||
/// </summary>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> Delete(byte id)
|
||||
{
|
||||
var response = await _noteService.DeleteAsync(id);
|
||||
if (!response.Status)
|
||||
{
|
||||
return NotFound(response);
|
||||
}
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user