Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/Codebreaker.Analyzers.sln

This file was deleted.

4 changes: 4 additions & 0 deletions src/Codebreaker.Analyzers.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Solution>
<Project Path="services/common/Codebreaker.GameAPIs.Analyzers.Tests/Codebreaker.GameAPIs.Analyzers.Tests.csproj" />
<Project Path="services/common/Codebreaker.GameAPIs.Analyzers/Codebreaker.Analyzers.csproj" />
</Solution>
22 changes: 0 additions & 22 deletions src/Codebreaker.Backend.Cosmos.sln

This file was deleted.

3 changes: 3 additions & 0 deletions src/Codebreaker.Backend.Cosmos.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="services/common/Codebreaker.Data.Cosmos/Codebreaker.Data.Cosmos.csproj" />
</Solution>
31 changes: 0 additions & 31 deletions src/Codebreaker.Backend.Models.sln

This file was deleted.

4 changes: 4 additions & 0 deletions src/Codebreaker.Backend.Models.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Solution>
<Project Path="services/common/Codebreaker.GameAPIs.Models.Tests/Codebreaker.GameAPIs.Models.Tests.csproj" />
<Project Path="services/common/Codebreaker.GameAPIs.Models/Codebreaker.GameAPIs.Models.csproj" />
</Solution>
27 changes: 0 additions & 27 deletions src/Codebreaker.Backend.Postgres.sln

This file was deleted.

4 changes: 4 additions & 0 deletions src/Codebreaker.Backend.Postgres.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Solution>
<Folder Name="/Solution Items/" />
<Project Path="services/common/Codebreaker.Data.Postgres/Codebreaker.Data.Postgres.csproj" />
</Solution>
28 changes: 0 additions & 28 deletions src/Codebreaker.Backend.SqlServer.sln

This file was deleted.

4 changes: 4 additions & 0 deletions src/Codebreaker.Backend.SqlServer.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Solution>
<Project Path="services/common/Codebreaker.Data.SqlServer.Tests/Codebreaker.Data.SqlServer.Tests.csproj" />
<Project Path="services/common/Codebreaker.Data.SqlServer/Codebreaker.Data.SqlServer.csproj" />
</Solution>
36 changes: 0 additions & 36 deletions src/Codebreaker.GameAPIs.Client.sln

This file was deleted.

7 changes: 7 additions & 0 deletions src/Codebreaker.GameAPIs.Client.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path="Directory.Packages.props" />
</Folder>
<Project Path="clients/Codebreaker.GameAPIs.Client.Tests/Codebreaker.GameAPIs.Client.Tests.csproj" />
<Project Path="clients/Codebreaker.GameAPIs.Client/Codebreaker.GameAPIs.Client.csproj" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageIcon>codebreaker.jpeg</PackageIcon>
<Version>3.9.0</Version>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,7 +31,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net9.0'">
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.5" />
</ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.9" />
</ItemGroup>

</Project>
41 changes: 27 additions & 14 deletions src/clients/Codebreaker.GameAPIs.Client/GamesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ public class GamesClient(HttpClient httpClient, ILogger<GamesClient> logger) : I
internal const string Version = "1.0.0";
internal static ActivitySource ActivitySource { get; } = new ActivitySource(ActivitySourceName, Version);

private readonly static JsonSerializerOptions s_jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};

/// <summary>
/// Starts a new game.
/// </summary>
Expand All @@ -30,9 +25,9 @@ public class GamesClient(HttpClient httpClient, ILogger<GamesClient> logger) : I
try
{
CreateGameRequest createGameRequest = new(gameType, playerName);
var response = await httpClient.PostAsJsonAsync("/games", createGameRequest, s_jsonOptions, cancellationToken);
var response = await httpClient.PostAsJsonAsync("/games", createGameRequest, GamesClientJsonContext.Default.CreateGameRequest, cancellationToken);
response.EnsureSuccessStatusCode();
var gameResponse = await response.Content.ReadFromJsonAsync<CreateGameResponse>(s_jsonOptions, cancellationToken) ?? throw new InvalidOperationException();
var gameResponse = await response.Content.ReadFromJsonAsync(GamesClientJsonContext.Default.CreateGameResponse, cancellationToken) ?? throw new InvalidOperationException();

logger.GameCreated(gameResponse.Id);
activity?.GameCreatedEvent(gameResponse.Id.ToString(), gameResponse.GameType.ToString());
Expand Down Expand Up @@ -60,7 +55,7 @@ public async Task CancelGameAsync(Guid id, string playerName, GameType gameType,
try
{
var request = new UpdateGameRequest(id, gameType, playerName, 0, true);
var response = await httpClient.PatchAsJsonAsync($"/games/{id}", request, s_jsonOptions, cancellationToken);
var response = await httpClient.PatchAsJsonAsync($"/games/{id}", request, GamesClientJsonContext.Default.UpdateGameRequest, cancellationToken);
response.EnsureSuccessStatusCode();
logger.GameCanceled(id);
activity?.GameCanceledEvent(id.ToString());
Expand Down Expand Up @@ -90,11 +85,11 @@ public async Task<GameInfo> RevealGameAsync(Guid id, string playerName, GameType
{
// First cancel/end the game
var request = new UpdateGameRequest(id, gameType, playerName, 0, End: true);
var cancelResponse = await httpClient.PatchAsJsonAsync($"/games/{id}", request, s_jsonOptions, cancellationToken);
var cancelResponse = await httpClient.PatchAsJsonAsync($"/games/{id}", request, GamesClientJsonContext.Default.UpdateGameRequest, cancellationToken);
cancelResponse.EnsureSuccessStatusCode();

// Then get the full game details
var gameResponse = await httpClient.GetFromJsonAsync<GameInfo>($"/games/{id}", s_jsonOptions, cancellationToken)
var gameResponse = await httpClient.GetFromJsonAsync($"/games/{id}", GamesClientJsonContext.Default.GameInfo, cancellationToken)
?? throw new InvalidOperationException($"Could not retrieve game with ID {id}");

int moveCount = gameResponse.Moves?.Count ?? 0;
Expand Down Expand Up @@ -132,9 +127,9 @@ public async Task<GameInfo> RevealGameAsync(Guid id, string playerName, GameType
{
GuessPegs = guessPegs
};
var response = await httpClient.PatchAsJsonAsync($"/games/{id}", updateGameRequest, s_jsonOptions, cancellationToken);
var response = await httpClient.PatchAsJsonAsync($"/games/{id}", updateGameRequest, GamesClientJsonContext.Default.UpdateGameRequest, cancellationToken);
response.EnsureSuccessStatusCode();
var moveResponse = await response.Content.ReadFromJsonAsync<UpdateGameResponse>(s_jsonOptions, cancellationToken)
var moveResponse = await response.Content.ReadFromJsonAsync(GamesClientJsonContext.Default.UpdateGameResponse, cancellationToken)
?? throw new InvalidOperationException();

logger.MoveSet(id, moveResponse.MoveNumber);
Expand Down Expand Up @@ -168,7 +163,7 @@ public async Task<GameInfo> RevealGameAsync(Guid id, string playerName, GameType
GameInfo? game;
try
{
game = await httpClient.GetFromJsonAsync<GameInfo>($"/games/{id}", s_jsonOptions, cancellationToken);
game = await httpClient.GetFromJsonAsync($"/games/{id}", GamesClientJsonContext.Default.GameInfo, cancellationToken);
logger.GameReceived(id, game?.EndTime != null, game?.LastMoveNumber ?? 0);
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
Expand Down Expand Up @@ -198,7 +193,7 @@ public async Task<IEnumerable<GameInfo>> GetGamesAsync(GamesQuery query, Cancell
try
{
string urlQuery = query.AsUrlQuery();
IEnumerable<GameInfo> games = (await httpClient.GetFromJsonAsync<IEnumerable<GameInfo>>($"/games{urlQuery}", s_jsonOptions, cancellationToken)) ?? [];
IEnumerable<GameInfo> games = (await httpClient.GetFromJsonAsync($"/games{urlQuery}", GamesClientJsonContext.Default.IEnumerableGameInfo, cancellationToken)) ?? [];

int gameCount = games.Count();
logger.GamesReceived(urlQuery, gameCount);
Expand All @@ -219,3 +214,21 @@ public async Task<IEnumerable<GameInfo>> GetGamesAsync(GamesQuery query, Cancell
}
}
}

[JsonSourceGenerationOptions(WriteIndented = true, PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(CreateGameRequest))]
[JsonSerializable(typeof(CreateGameResponse))]
[JsonSerializable(typeof(UpdateGameRequest))]
[JsonSerializable(typeof(UpdateGameResponse))]
[JsonSerializable(typeof(GameInfo))]
[JsonSerializable(typeof(MoveInfo))]
[JsonSerializable(typeof(GamesQuery))]
[JsonSerializable(typeof(GameType))]
[JsonSerializable(typeof(IEnumerable<GameInfo>))]
[JsonSerializable(typeof(IDictionary<string, string[]>))]
[JsonSerializable(typeof(IDictionary<string, IEnumerable<string>>))]
[JsonSerializable(typeof(ICollection<MoveInfo>))]
internal partial class GamesClientJsonContext : JsonSerializerContext
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ namespace Codebreaker.GameAPIs.Client.Models;
/// <summary>
/// The list of possible game types
/// </summary>
#if NET8_0_OR_GREATER
[JsonConverter(typeof(JsonStringEnumConverter<GameType>))]
#else
[JsonConverter(typeof(JsonStringEnumConverter))]
#endif
public enum GameType
{
Game6x4,
Expand Down