LingAdmin/Backend/LingAdmin.API/Controllers/PagesController.cs

80 lines
3.0 KiB
C#
Raw Permalink Normal View History

2026-04-16 18:13:06 +08:00
using Microsoft.AspNetCore.Mvc;
using LingAdmin.API.DTOs;
namespace LingAdmin.API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class PagesController : ControllerBase
{
private readonly ILogger<PagesController> _logger;
public PagesController(ILogger<PagesController> logger)
{
_logger = logger;
}
[HttpGet("inventory/config")]
public ActionResult<ApiResponse<PageConfigDto>> GetInventoryConfig()
{
try
{
var config = new PageConfigDto
{
Title = "Inventory Management",
TitleKey = "common.inventory",
DataUrl = "/api/inventory",
Columns = new List<ColumnConfig>
{
new ColumnConfig { Field = "sku", Title = "SKU", HeaderKey = "common.sku" },
new ColumnConfig { Field = "name", Title = "Product Name", HeaderKey = "common.productName" },
new ColumnConfig { Field = "stock", Title = "Stock", HeaderKey = "common.stock" },
new ColumnConfig { Field = "price", Title = "Price", HeaderKey = "common.price" }
},
Actions = new List<ActionConfig>
{
new ActionConfig { Code = "add", Label = "Add Item", LabelKey = "common.add" },
new ActionConfig { Code = "edit", Label = "Edit Item", LabelKey = "common.edit" },
new ActionConfig { Code = "delete", Label = "Delete Item", LabelKey = "common.delete" }
}
};
return Ok(ApiResponse<PageConfigDto>.Success(config));
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting inventory config");
return StatusCode(500, ApiResponse<PageConfigDto>.Error("Internal server error", 500));
}
}
[HttpGet("audit/config")]
public ActionResult<ApiResponse<PageConfigDto>> GetAuditConfig()
{
try
{
var config = new PageConfigDto
{
Title = "Audit Logs",
TitleKey = "common.audit",
DataUrl = "/api/audit",
Columns = new List<ColumnConfig>
{
new ColumnConfig { Field = "id", Title = "ID", HeaderKey = "common.id" },
new ColumnConfig { Field = "user", Title = "User", HeaderKey = "common.user" },
new ColumnConfig { Field = "action", Title = "Action", HeaderKey = "common.action" },
new ColumnConfig { Field = "timestamp", Title = "Time", HeaderKey = "common.time" }
},
Actions = null // Audit logs typically don't have actions
};
return Ok(ApiResponse<PageConfigDto>.Success(config));
}
catch (Exception ex)
{
_logger.LogError(ex, "Error getting audit config");
return StatusCode(500, ApiResponse<PageConfigDto>.Error("Internal server error", 500));
}
}
}