using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MilliSim.Common.Dtos;
using MilliSim.Common.Models;
using MilliSim.Services;
namespace MilliSim.Controllers;
[ApiController]
[Route("api/consultations")]
public class ConsultationsController : ControllerBase
{
private readonly IContentService _contentService;
public ConsultationsController(IContentService contentService)
{
_contentService = contentService;
}
///
/// 咨询消息列表
///
[HttpGet]
[Authorize(Policy = "Staff")]
public async Task GetList([FromQuery] PageRequest request, [FromQuery] bool? isRead)
{
var result = await _contentService.GetConsultationsAsync(request, isRead);
return Ok(result);
}
///
/// 提交咨询(公开)
///
[HttpPost]
public async Task Create([FromBody] CreateConsultationRequest request)
{
var result = await _contentService.CreateConsultationAsync(request);
return Ok(result);
}
///
/// 标记已读
///
[HttpPost("{id:long}/read")]
[Authorize(Policy = "Staff")]
public async Task MarkAsRead(long id)
{
var result = await _contentService.MarkAsReadAsync(id);
return Ok(result);
}
///
/// 删除咨询消息
///
[HttpPost("{id:long}/delete")]
[Authorize(Policy = "Staff")]
public async Task Delete(long id)
{
var result = await _contentService.DeleteConsultationAsync(id);
return Ok(result);
}
}