Ajoute l Elo et les statistiques de parties
This commit is contained in:
@@ -4,6 +4,7 @@ using ChessCubing.Server.Admin;
|
||||
using ChessCubing.Server.Auth;
|
||||
using ChessCubing.Server.Data;
|
||||
using ChessCubing.Server.Social;
|
||||
using ChessCubing.Server.Stats;
|
||||
using ChessCubing.Server.Users;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
@@ -73,6 +74,7 @@ builder.Services.AddSignalR();
|
||||
builder.Services.AddHttpClient<KeycloakAuthService>();
|
||||
builder.Services.AddSingleton<MySqlUserProfileStore>();
|
||||
builder.Services.AddSingleton<MySqlSocialStore>();
|
||||
builder.Services.AddSingleton<MySqlPlayerStatsStore>();
|
||||
builder.Services.AddSingleton<ConnectedUserTracker>();
|
||||
builder.Services.AddSingleton<PlayInviteCoordinator>();
|
||||
builder.Services.AddSingleton<CollaborativeMatchCoordinator>();
|
||||
@@ -83,8 +85,10 @@ await using (var scope = app.Services.CreateAsyncScope())
|
||||
{
|
||||
var profileStore = scope.ServiceProvider.GetRequiredService<MySqlUserProfileStore>();
|
||||
var socialStore = scope.ServiceProvider.GetRequiredService<MySqlSocialStore>();
|
||||
var statsStore = scope.ServiceProvider.GetRequiredService<MySqlPlayerStatsStore>();
|
||||
await profileStore.InitializeAsync(CancellationToken.None);
|
||||
await socialStore.InitializeAsync(CancellationToken.None);
|
||||
await statsStore.InitializeAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
app.UseAuthentication();
|
||||
@@ -133,6 +137,44 @@ app.MapPut("/api/users/me", async Task<IResult> (
|
||||
}
|
||||
}).RequireAuthorization();
|
||||
|
||||
app.MapGet("/api/users/me/stats", async Task<IResult> (
|
||||
ClaimsPrincipal user,
|
||||
MySqlPlayerStatsStore statsStore,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var siteUser = AuthenticatedSiteUserFactory.FromClaimsPrincipal(user);
|
||||
if (siteUser is null)
|
||||
{
|
||||
return TypedResults.BadRequest(new ApiErrorResponse("La session utilisateur est incomplete."));
|
||||
}
|
||||
|
||||
var stats = await statsStore.GetUserStatsAsync(siteUser.Subject, cancellationToken);
|
||||
return TypedResults.Ok(stats);
|
||||
}).RequireAuthorization();
|
||||
|
||||
app.MapPost("/api/users/me/stats/matches", async Task<IResult> (
|
||||
ReportCompletedMatchRequest request,
|
||||
ClaimsPrincipal user,
|
||||
MySqlPlayerStatsStore statsStore,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var siteUser = AuthenticatedSiteUserFactory.FromClaimsPrincipal(user);
|
||||
if (siteUser is null)
|
||||
{
|
||||
return TypedResults.BadRequest(new ApiErrorResponse("La session utilisateur est incomplete."));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = await statsStore.RecordCompletedMatchAsync(siteUser, request, cancellationToken);
|
||||
return TypedResults.Ok(result);
|
||||
}
|
||||
catch (PlayerStatsValidationException exception)
|
||||
{
|
||||
return TypedResults.BadRequest(new ApiErrorResponse(exception.Message));
|
||||
}
|
||||
}).RequireAuthorization();
|
||||
|
||||
var socialGroup = app.MapGroup("/api/social")
|
||||
.RequireAuthorization();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user