MilliSim/backend/MilliSim.Api/Controllers/PartnersController.cs

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