66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
|
|
using YD_Event.Application.Auth;
|
||
|
|
using YD_Event.Application.CitizenSports.Dtos;
|
||
|
|
|
||
|
|
namespace YD_Event.Application.CitizenSports;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 市民运动会报名数据同步。
|
||
|
|
/// </summary>
|
||
|
|
[ApiDescriptionSettings("报名管理")]
|
||
|
|
[Route("api/citizen-sports-sync")]
|
||
|
|
[Authorize]
|
||
|
|
public sealed class CitizenSportsSyncController : IDynamicApiController
|
||
|
|
{
|
||
|
|
private readonly CitizenSportsPlatformService _service;
|
||
|
|
private readonly AuthManager _authManager;
|
||
|
|
|
||
|
|
public CitizenSportsSyncController(
|
||
|
|
CitizenSportsPlatformService service,
|
||
|
|
AuthManager authManager)
|
||
|
|
{
|
||
|
|
_service = service;
|
||
|
|
_authManager = authManager;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 使用当前环境配置验证平台地址和签名。
|
||
|
|
/// </summary>
|
||
|
|
[HttpPost("connection-test")]
|
||
|
|
[DisplayName("测试市民运动会平台连接")]
|
||
|
|
public async Task<CitizenSportsConnectionTestOutput> TestConnection(CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
EnsureSuperAdministrator();
|
||
|
|
return await _service.TestConnectionAsync(cancellationToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 只读取本地报名数据,返回不含敏感信息的上传预览。
|
||
|
|
/// </summary>
|
||
|
|
[HttpPost("preview")]
|
||
|
|
[DisplayName("预览市民运动会报名同步")]
|
||
|
|
public async Task<CitizenSportsPreviewOutput> Preview([FromBody] CitizenSportsSyncInput input)
|
||
|
|
{
|
||
|
|
EnsureSuperAdministrator();
|
||
|
|
return await _service.PreviewAsync(input);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 将预检通过的报名人员上传到市民运动会平台。
|
||
|
|
/// </summary>
|
||
|
|
[HttpPost("execute")]
|
||
|
|
[DisplayName("执行市民运动会报名同步")]
|
||
|
|
public async Task<CitizenSportsExecuteOutput> Execute(
|
||
|
|
[FromBody] CitizenSportsExecuteInput input,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
EnsureSuperAdministrator();
|
||
|
|
return await _service.ExecuteAsync(input, cancellationToken);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void EnsureSuperAdministrator()
|
||
|
|
{
|
||
|
|
if (_authManager.AuthPlatformType != AuthPlatformType.Manager || !_authManager.IsSuperAdmin)
|
||
|
|
throw Oops.Bah("仅超级管理员可以同步市民运动会报名数据");
|
||
|
|
}
|
||
|
|
}
|