JWT-Authentifizierung & GameState-Verbesserungen

Neuer AuthController mit Endpunkten für Registrierung, Login und Nutzerinfo (/register, /login, /me) implementiert. Auth-spezifische DTOs hinzugefügt. GameHub mit [Authorize] geschützt und Spielteilnahme validiert. GameService liefert jetzt Rundeninfos, aktuelle Rundennummer und verbleibende Rundendauer. Migrations-Ordner im Projekt angelegt.
This commit is contained in:
Tim Krampitz
2026-07-26 13:30:03 +02:00
parent d29bff17a1
commit 070727d5cd
5 changed files with 190 additions and 1 deletions

View File

@@ -205,7 +205,9 @@ public class GameService : IGameService
.ThenInclude(p => p.User)
.Include(g => g.Players)
.ThenInclude(p => p.Cards)
.Include(g => g.Rounds)
.FirstOrDefaultAsync(g => g.Id == gameId) ?? throw new InvalidOperationException("Game not found");
var playerInfos = game.Players.Select(p => new PlayerInfoDto
{
PlayerId = p.Id,
@@ -215,13 +217,27 @@ public class GameService : IGameService
CardCount = p.Cards.Count // Nur Anzahl, nicht die Karten selbst!
}).ToList();
var currentRound = game.Rounds
.OrderByDescending(r => r.RoundNumber)
.FirstOrDefault();
var roundDurationSeconds = Math.Clamp(game.RoundDurationSeconds, 30, 60);
var roundTimeRemaining = roundDurationSeconds;
if (currentRound?.Status == RoundStatus.Active)
{
var elapsedSeconds = (int)(DateTime.UtcNow - currentRound.StartedAt).TotalSeconds;
roundTimeRemaining = Math.Max(0, roundDurationSeconds - elapsedSeconds);
}
return new GameStateDto
{
GameId = game.Id,
LobbyCode = game.LobbyCode,
Status = game.Status.ToString(),
Players = playerInfos,
CurrentRound = game.Rounds?.Count ?? 0
CurrentRound = currentRound?.RoundNumber ?? 0,
RoundTimeRemaining = roundTimeRemaining
};
}