using Microsoft.AspNetCore.Mvc;
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
using QYZH.InteractiveMagazine.IService;
using QYZH.InteractiveMagazine.Models.Common;
using QYZH.InteractiveMagazine.Models.Dto;
using QYZH.InteractiveMagazine.Models.Enum;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
///
/// 社区消息管理控制器
///
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class CommunityMessageController : BaseController
{
private readonly ICommunityMessageService _communityMessageService;
private readonly ILogger _logger;
public CommunityMessageController(ICommunityMessageService communityMessageService, ILogger logger)
{
_communityMessageService = communityMessageService;
_logger = logger;
}
///
/// 分页查询社区消息列表
///
[HttpPost("list")]
public async Task>> GetListAsync([FromBody] AdminMessageQueryInput input)
{
try
{
var result = await _communityMessageService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询社区消息列表业务异常: {Message}", ex.Message);
return BaseResponse>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询社区消息列表系统异常,参数:{Input}", input);
return BaseResponse>.Fail("查询社区消息列表失败,请稍后重试");
}
}
///
/// 查看消息详情
///
[HttpGet("{id}")]
public async Task> GetDetailAsync(long id)
{
try
{
var result = await _communityMessageService.GetDetailAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取社区消息详情业务异常: {Message}", ex.Message);
return BaseResponse.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取社区消息详情系统异常,ID:{Id}", id);
return BaseResponse.Fail("获取消息详情失败,请稍后重试");
}
}
///
/// 删除消息
///
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.CommunityMessage)]
[HttpDelete("{id}")]
public async Task> DeleteAsync(long id)
{
try
{
await _communityMessageService.DeleteAsync(id);
return Success(new object(), "删除消息成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "删除社区消息业务异常: {Message}", ex.Message);
return BaseResponse