c0c8f852d2
PR Checks / test-and-build (pull_request) Successful in 3m49s
- SessionBatchDto: добавлено поле JoinLink - SessionViewItem: добавлено поле JoinLink - SessionBatchViewBuilder: прокидывание JoinLink из DTO в ViewModel - CreateSessionHandler, SessionService: обновлены все вызовы конструктора - TelegramSessionBatchRenderer (Bot + Web): рендеринг ссылки в карточке - Добавлены тесты на наличие ссылки в рендере - Все 7 SQL-запросов, загружающих SessionBatchDto, обновлены с join_link AS JoinLink - Бамп версии до 1.11.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
using GmRelay.Shared.Domain;
|
|
|
|
namespace GmRelay.Shared.Rendering;
|
|
|
|
public static class SessionBatchViewBuilder
|
|
{
|
|
public static SessionBatchViewModel Build(
|
|
string title,
|
|
IReadOnlyList<SessionBatchDto> sessions,
|
|
IReadOnlyList<ParticipantBatchDto> participants)
|
|
{
|
|
var orderedSessions = sessions.OrderBy(s => s.ScheduledAt).ToList();
|
|
var sessionItems = new List<SessionViewItem>();
|
|
|
|
foreach (var session in orderedSessions)
|
|
{
|
|
var activePlayers = participants
|
|
.Where(p => p.SessionId == session.SessionId && p.RegistrationStatus == ParticipantRegistrationStatus.Active)
|
|
.Select(p => new PlayerViewItem(p.DisplayName, p.TelegramUsername, p.RegistrationStatus))
|
|
.ToList();
|
|
|
|
var waitlistedPlayers = participants
|
|
.Where(p => p.SessionId == session.SessionId && p.RegistrationStatus == ParticipantRegistrationStatus.Waitlisted)
|
|
.Select(p => new PlayerViewItem(p.DisplayName, p.TelegramUsername, p.RegistrationStatus))
|
|
.ToList();
|
|
|
|
var actions = new List<AvailableAction>();
|
|
if (!SessionStatus.IsCancelled(session.Status))
|
|
{
|
|
var dateTitle = session.ScheduledAt.FormatMoscowShort();
|
|
var joinLabel = GetJoinButtonText(session, activePlayers.Count, dateTitle);
|
|
actions.Add(new AvailableAction("join_session", joinLabel, session.SessionId));
|
|
actions.Add(new AvailableAction("leave_session", $"🚪 Выйти {dateTitle}", session.SessionId));
|
|
}
|
|
|
|
sessionItems.Add(new SessionViewItem(
|
|
session.SessionId,
|
|
session.ScheduledAt,
|
|
session.Status,
|
|
session.MaxPlayers,
|
|
session.JoinLink,
|
|
activePlayers.Count,
|
|
activePlayers,
|
|
waitlistedPlayers,
|
|
actions));
|
|
}
|
|
|
|
return new SessionBatchViewModel(title, sessionItems);
|
|
}
|
|
|
|
private static string GetJoinButtonText(SessionBatchDto session, int activePlayers, string dateTitle)
|
|
{
|
|
if (session.MaxPlayers.HasValue && activePlayers >= session.MaxPlayers.Value)
|
|
{
|
|
return $"⏳ В лист ожидания {dateTitle}";
|
|
}
|
|
|
|
return $"✋ На {dateTitle}";
|
|
}
|
|
}
|
|
// trigger pr
|