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/partners")]
|
||
public class PartnersController : ControllerBase
|
||
{
|
||
private readonly IContentService _contentService;
|
||
|
||
public PartnersController(IContentService contentService)
|
||
{
|
||
_contentService = contentService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 合作伙伴列表(前台传 onlyVisible=true)
|
||
/// </summary>
|
||
[HttpGet]
|
||
public async Task<IActionResult> GetList([FromQuery] bool onlyVisible = false)
|
||
{
|
||
var result = await _contentService.GetPartnersAsync(onlyVisible);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建合作伙伴
|
||
/// </summary>
|
||
[HttpPost]
|
||
[Authorize(Policy = "Admin")]
|
||
public async Task<IActionResult> Create([FromBody] CreatePartnerRequest request)
|
||
{
|
||
var result = await _contentService.CreatePartnerAsync(request);
|
||
return Ok(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新合作伙伴
|
||
/// </summary>
|
||
[HttpPost("{id:long}")]
|
||
[Authorize(Policy = "Admin")]
|
||
public async Task<IActionResult> Update(long id, [FromBody] CreatePartnerRequest request)
|
||
{
|
||
var result = await _contentService.UpdatePartnerAsync(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.DeletePartnerAsync(id);
|
||
return Ok(result);
|
||
}
|
||
}
|