62 lines
1.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}