using YD_Event.Application.Auth;
using YD_Event.Application.Client.Dtos;
namespace YD_Event.Application.Client;
///
/// 小程序裁判执裁报名接口。
///
[ApiDescriptionSettings("微信小程序接口")]
[Authorize]
public class RefereeController : IDynamicApiController
{
private readonly ISqlSugarRepository _userRepository;
private readonly ISqlSugarRepository _eventRepository;
private readonly ISqlSugarRepository _applicationRepository;
private readonly AuthManager _authManager;
public RefereeController(
ISqlSugarRepository userRepository,
ISqlSugarRepository eventRepository,
ISqlSugarRepository applicationRepository,
AuthManager authManager)
{
_userRepository = userRepository;
_eventRepository = eventRepository;
_applicationRepository = applicationRepository;
_authManager = authManager;
}
[HttpGet("applications")]
[DisplayName("获取我的执裁报名")]
public async Task GetApplications()
{
var userId = await EnsureRefereeAsync();
var applications = await _applicationRepository.AsQueryable()
.Where(x => x.RefereeUserId == userId && x.Status == AvailabilityStatus.Enable)
.OrderByDescending(x => x.CreatedTime)
.ToListAsync();
var eventIds = applications.Select(x => x.EventId).Distinct().ToList();
var events = eventIds.Count == 0
? new List()
: await _eventRepository.AsQueryable().Where(x => eventIds.Contains(x.Id)).ToListAsync();
var eventMap = events.ToDictionary(x => x.Id);
var rows = applications.Select(x =>
{
eventMap.TryGetValue(x.EventId, out var evt);
return new RefereeApplicationDto
{
Id = x.Id,
ApplicationId = x.Id,
EventId = x.EventId,
EventName = evt?.EventName ?? string.Empty,
CoverImage = evt?.CoverImage,
Address = evt?.DetailAddress,
EventStatus = evt == null ? 0 : (int)evt.EventStatus,
ApplicationStatus = x.ApplicationStatus,
ApplicationStatusText = ApplicationStatusText(x.ApplicationStatus),
AppliedAt = x.CreatedTime,
MatchStartTime = evt?.MatchStartTime ?? DateTime.MinValue,
MatchEndTime = evt?.MatchEndTime ?? DateTime.MinValue
};
}).ToList();
return new RefereeApplicationListOutput { Rows = rows, Total = rows.Count };
}
[HttpPost("applications/apply")]
[UnitOfWork]
[DisplayName("报名执裁")]
public async Task