62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using MilliSim.Common.Dtos;
|
||
using MilliSim.Services;
|
||
|
||
namespace MilliSim.Controllers;
|
||
|
||
[ApiController]
|
||
[Route("api/banners")]
|
||
public class BannersController : ControllerBase
|
||
{
|
||
private readonly IContentService _contentService;
|
||
|
||
public BannersController(IContentService contentService)
|
||
{
|
||
_contentService = contentService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 轮播图列表(前台传 onlyActive=true)
|
||
/// </summary>
|
||
[HttpGet]
|
||
public async Task<IActionResult> GetList([FromQuery] bool onlyActive = false)
|
||
{
|
||
var result = await _contentService.GetBannersAsync(onlyActive);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建轮播图
|
||
/// </summary>
|
||
[HttpPost]
|
||
[Authorize(Policy = "Admin")]
|
||
public async Task<IActionResult> Create([FromBody] CreateBannerRequest request)
|
||
{
|
||
var result = await _contentService.CreateBannerAsync(request);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新轮播图
|
||
/// </summary>
|
||
[HttpPost("{id:long}")]
|
||
[Authorize(Policy = "Admin")]
|
||
public async Task<IActionResult> Update(long id, [FromBody] CreateBannerRequest request)
|
||
{
|
||
var result = await _contentService.UpdateBannerAsync(id, request);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除轮播图
|
||
/// </summary>
|
||
[HttpPost("{id:long}/delete")]
|
||
[Authorize(Policy = "Admin")]
|
||
public async Task<IActionResult> Delete(long id)
|
||
{
|
||
var result = await _contentService.DeleteBannerAsync(id);
|
||
return Ok(result);
|
||
}
|
||
}
|