Skip to content

Commit 4a665c5

Browse files
committed
Add gamer name suggestion client and interface
1 parent 23d00dc commit 4a665c5

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using CodeBreaker.Blazor.Client.Services;
2+
3+
namespace CodeBreaker.Blazor.Client.Contracts.Services;
4+
5+
public interface IGamerNameSuggestionClient
6+
{
7+
Task<GamerNameSuggestionsResult> GetGamerNameSuggestionsAsync(int count = 10, CancellationToken cancellationToken = default);
8+
}
9+
10+
public record GamerNameSuggestionsResult(string[] Suggestions);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Net.Http.Json;
2+
using CodeBreaker.Blazor.Client.Contracts.Services;
3+
4+
namespace CodeBreaker.Blazor.Client.Services;
5+
6+
public class GamerNameSuggestionClient(HttpClient httpClient) : IGamerNameSuggestionClient
7+
{
8+
public async Task<GamerNameSuggestionsResult> GetGamerNameSuggestionsAsync(int count = 10, CancellationToken cancellationToken = default)
9+
{
10+
var response = await httpClient.GetAsync($"/gamer-names/suggestions?count={count}", cancellationToken);
11+
response.EnsureSuccessStatusCode();
12+
return await response.Content.ReadFromJsonAsync<GamerNameSuggestionsResult>(cancellationToken) ?? new ([]);
13+
}
14+
}

0 commit comments

Comments
 (0)