Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client lib: Rename Game to GameInfo, Move to Move Info #47

Merged
merged 2 commits into from
Aug 5, 2023
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
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
global using Xunit;
global using System.Net;

global using Microsoft.Extensions.Configuration;

global using Moq;
global using Moq.Protected;

global using Xunit;
global using Xunit.Abstractions;
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
using System.Net;

using Microsoft.Extensions.Configuration;

using Moq;
using Moq.Protected;

using Xunit.Abstractions;

namespace Codebreaker.GameAPIs.Client.Tests;

public class TestGamesClient
Expand Down
12 changes: 6 additions & 6 deletions src/clients/common/Codebreaker.GameAPIs.Client/GamesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public GamesClient(HttpClient httpClient)
/// </summary>
/// <param name="gameId">The unique identifier of a game.</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the request early.</param>
/// <returns>The <see cref="Game"/> if it exists, otherwise null.</returns>
/// <returns>The <see cref="GameInfo"/> if it exists, otherwise null.</returns>
/// <exception cref="HttpRequestException"></exception>
public async Task<Game?> GetGameAsync(Guid gameId, CancellationToken cancellationToken = default)
public async Task<GameInfo?> GetGameAsync(Guid gameId, CancellationToken cancellationToken = default)
{
Game? game = default;
GameInfo? game = default;
try
{
game = await _httpClient.GetFromJsonAsync<Game>($"/games/{gameId}", s_jsonOptions, cancellationToken);
game = await _httpClient.GetFromJsonAsync<GameInfo>($"/games/{gameId}", s_jsonOptions, cancellationToken);
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Expand All @@ -95,9 +95,9 @@ public GamesClient(HttpClient httpClient)
/// <param name="cancellationToken">Cancellation token to cancel the request early.</param>
/// <returns>An IEnumerable collection of Game objects that match the specified query.</returns>
/// <exception cref="HttpRequestException"></exception>
public async Task<IEnumerable<Game>> GetGamesAsync(GamesQuery query, CancellationToken cancellationToken = default)
public async Task<IEnumerable<GameInfo>> GetGamesAsync(GamesQuery query, CancellationToken cancellationToken = default)
{
IEnumerable<Game> games = (await _httpClient.GetFromJsonAsync<IEnumerable<Game>>($"/games/{query.AsUrlQuery()}", s_jsonOptions, cancellationToken)) ?? Enumerable.Empty<Game>();
IEnumerable<GameInfo> games = (await _httpClient.GetFromJsonAsync<IEnumerable<GameInfo>>($"/games/{query.AsUrlQuery()}", s_jsonOptions, cancellationToken)) ?? Enumerable.Empty<GameInfo>();
return games;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Codebreaker.GameAPIs.Client;
public interface IGamesClient
{
Task<Game?> GetGameAsync(Guid gameId, CancellationToken cancellationToken = default);
Task<IEnumerable<Game>> GetGamesAsync(GamesQuery query, CancellationToken cancellationToken = default);
Task<GameInfo?> GetGameAsync(Guid gameId, CancellationToken cancellationToken = default);
Task<IEnumerable<GameInfo>> GetGamesAsync(GamesQuery query, CancellationToken cancellationToken = default);
Task<(string[] Results, bool Ended, bool IsVictory)> SetMoveAsync(Guid gameId, string playerName, GameType gameType, int moveNumber, string[] guessPegs, CancellationToken cancellationToken = default);
Task<(Guid GameId, int NumberCodes, int MaxMoves, IDictionary<string, string[]> FieldValues)> StartGameAsync(GameType gameType, string playerName, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace Codebreaker.GameAPIs.Client.Models;

/// <summary>
///
/// Complete information about a single game - including the soltuion and the moves the player made.
/// </summary>
/// <param name="gameId">The unique identifier of the game</param>
/// <param name="gameType"></param>
/// <param name="playerName"></param>
/// <param name="startTime"></param>
/// <param name="numberCodes"></param>
/// <param name="maxMoves"></param>
public class Game(
public class GameInfo(
Guid gameId,
string gameType,
string playerName,
Expand Down Expand Up @@ -85,7 +85,7 @@ public class Game(
/// <summary>
/// A list of moves the player made
/// </summary>
public ICollection<Move> Moves { get; init; } = new List<Move>();
public ICollection<MoveInfo> Moves { get; init; } = new List<MoveInfo>();

public override string ToString() => $"{GameId}:{GameType} - {StartTime}";
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Codebreaker.GameAPIs.Client.Models;

/// <summary>
/// Represents the move within a game <see cref="Game"/ >with the guess pegs and key pegs.
/// Represents the move within a game <see cref="GameInfo"/ >with the guess pegs and key pegs.
/// </summary>
/// <param name="moveId"/>The unique identifier of the move. This is needed to reference the move.
/// <param name="moveNumber"/>The move number for this move within the associated game.
public class Move(Guid moveId, int moveNumber)
public class MoveInfo(Guid moveId, int moveNumber)
{
public Guid MoveId { get; private set; } = moveId;

Expand Down
14 changes: 8 additions & 6 deletions src/clients/common/Codebreaker.GameAPIs.Client/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ The `IGamesClient` class is the main contract to be used for communication to pl

| Method | Description |
|------------|--------------------|
| StartGameAsync | Start a new game |
| SetMoveAsync | Set guesses for a game move |
| GetGameAsync | Get a game by id with all details and moves |
| GetGamesAsync | Get a list of games with all details and moves (use the `GamesQuery` class to define the filter) |
| `StartGameAsync` | Start a new game |
| `SetMoveAsync` | Set guesses for a game move |
| `GetGameAsync` | Get a game by id with all details and moves |
| `GetGamesAsync` | Get a list of games with all details and moves (use the `GamesQuery` class to define the filter) |


The `GamesClient` class implements the `IGamesClient` interface. In the constructor, inject the `HttpClient` class. You can use `Microsoft.Extensions.Http` to configure the `HttpClient` class.
Expand All @@ -26,5 +26,7 @@ The following model types are used to return information about the game.

| Model type | Description |
|------------|-------------|
| Game | Contains the game id, the game status, the game moves and the game result |
| Move | Contains the move number, the guess and the result of the guess |
| `GameType` | Enum value to list different game types |
| `GamesQuery` | Use this class to query for game info lists using `GetGamesAsync` |
| `GameInfo` | Contains the game id, the game status, the game moves and the game result |
| `MoveInfo` | Contains the move number, the guess and the result of the guess. Contained within a `GameInfo` |