MilliSim/backend/MilliSim.Api/Controllers/PlatformsController.cs

59 lines
1.5 KiB
C#

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/platforms")]
public class PlatformsController : ControllerBase
{
private readonly IProjectService _projectService;
public PlatformsController(IProjectService projectService)
{
_projectService = projectService;
}
/// <summary>
/// 平台列表
/// </summary>
[HttpGet]
public async Task<ApiResponse<List<PlatformDto>>> GetPlatforms()
{
return await _projectService.GetPlatformsAsync();
}
/// <summary>
/// 创建平台
/// </summary>
[HttpPost]
[Authorize(Policy = "Admin")]
public async Task<ApiResponse<PlatformDto>> CreatePlatform([FromBody] CreatePlatformRequest request)
{
return await _projectService.CreatePlatformAsync(request);
}
/// <summary>
/// 更新平台
/// </summary>
[HttpPost("{id:long}")]
[Authorize(Policy = "Admin")]
public async Task<ApiResponse<PlatformDto>> UpdatePlatform(long id, [FromBody] CreatePlatformRequest request)
{
return await _projectService.UpdatePlatformAsync(id, request);
}
/// <summary>
/// 删除平台
/// </summary>
[HttpPost("{id:long}/delete")]
[Authorize(Policy = "Admin")]
public async Task<ApiResponse> DeletePlatform(long id)
{
return await _projectService.DeletePlatformAsync(id);
}
}