2026-07-07 15:53:25 +08:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-07-09 18:01:37 +08:00
|
|
|
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
2026-07-07 15:53:25 +08:00
|
|
|
using QYZH.InteractiveMagazine.IService;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto.Material;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Enum;
|
|
|
|
|
|
|
|
|
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 资料管理控制器
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
|
|
|
|
public class MaterialController(IMaterialService materialService) : BaseController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建资料
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">资料信息</param>
|
|
|
|
|
/// <returns>创建后的资料信息</returns>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.Material)]
|
2026-07-07 15:53:25 +08:00
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<BaseResponse<MaterialOutput>> CreateAsync([FromBody] MaterialInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await materialService.CreateAsync(input);
|
|
|
|
|
return Success(result, "创建资料成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新资料
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">资料ID</param>
|
|
|
|
|
/// <param name="input">资料信息</param>
|
|
|
|
|
/// <returns>更新后的资料信息</returns>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.Material)]
|
2026-07-07 15:53:25 +08:00
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public async Task<BaseResponse<MaterialOutput>> UpdateAsync(long id, [FromBody] MaterialInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await materialService.UpdateAsync(id, input);
|
|
|
|
|
return Success(result, "更新资料成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除资料
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">资料ID</param>
|
|
|
|
|
/// <returns>操作结果</returns>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.Material)]
|
2026-07-07 15:53:25 +08:00
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async Task<BaseResponse<object>> DeleteAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
await materialService.DeleteAsync(id);
|
|
|
|
|
return Success(new object(), "删除资料成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ID获取资料
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">资料ID</param>
|
|
|
|
|
/// <returns>资料信息</returns>
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public async Task<BaseResponse<MaterialOutput>> GetByIdAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var result = await materialService.GetByIdAsync(id);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询资料列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input">查询条件</param>
|
|
|
|
|
/// <returns>分页结果</returns>
|
|
|
|
|
[HttpPost("list")]
|
|
|
|
|
public async Task<BaseResponse<PageListModel<MaterialOutput>>> GetListAsync([FromBody] MaterialQueryInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await materialService.GetListAsync(input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新资料启用/禁用状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">资料ID</param>
|
|
|
|
|
/// <returns>操作结果</returns>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.Material)]
|
2026-07-07 15:53:25 +08:00
|
|
|
[HttpPut("{id}/status")]
|
|
|
|
|
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var result = await materialService.UpdateStatusAsync(id);
|
|
|
|
|
return Success(result, "更新资料状态成功");
|
|
|
|
|
}
|
|
|
|
|
}
|