|
|
|
@ -5,7 +5,6 @@ namespace AdminPanel.Services;
|
|
|
|
|
|
|
|
|
|
public class HttpTeamService : ITeamService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
|
|
|
|
|
public HttpTeamService(HttpClient client)
|
|
|
|
@ -13,38 +12,46 @@ public class HttpTeamService : ITeamService
|
|
|
|
|
this._client = client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private record ListTeamResponse(uint TotalCount, List<Team> Teams);
|
|
|
|
|
|
|
|
|
|
private record CountTeamsResponse(uint Value);
|
|
|
|
|
|
|
|
|
|
public async Task<(uint, List<Team>)> ListTeam(uint from, uint count)
|
|
|
|
|
{
|
|
|
|
|
var httpResponse = await _client.GetAsync($"/api/admin/list-team?start={from}&n={count}");
|
|
|
|
|
var httpResponse = await _client.GetAsync($"/admin/teams?start={from}&n={count}");
|
|
|
|
|
httpResponse.EnsureSuccessStatusCode();
|
|
|
|
|
var response = await httpResponse.Content.ReadFromJsonAsync<ListTeamResponse>()!;
|
|
|
|
|
var teams = (await httpResponse.Content.ReadFromJsonAsync<List<Team>>())!;
|
|
|
|
|
|
|
|
|
|
httpResponse =
|
|
|
|
|
await _client.GetAsync($"/admin/teams/count");
|
|
|
|
|
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
|
|
|
|
|
|
|
|
|
|
return (response.TotalCount, response.Teams);
|
|
|
|
|
var countResponse = await httpResponse.Content.ReadFromJsonAsync<CountTeamsResponse>();
|
|
|
|
|
|
|
|
|
|
return (countResponse!.Value, teams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private record AddTeamDTORequest(string Name, string Picture, string MainColor, string SecondaryColor);
|
|
|
|
|
private record AddTeamRequest(string Name, string Picture, string FirstColor, string SecondColor);
|
|
|
|
|
|
|
|
|
|
public async Task AddTeam(string name, string picture, string mainColor, string secondaryColor)
|
|
|
|
|
{
|
|
|
|
|
var httpResponse = await _client.PostAsJsonAsync($"/api/admin/add-team", new AddTeamDTORequest(name,picture,mainColor,secondaryColor));
|
|
|
|
|
var httpResponse = await _client.PostAsJsonAsync($"/admin/teams",
|
|
|
|
|
new AddTeamRequest(name, picture, mainColor, secondaryColor));
|
|
|
|
|
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private record DeleteTeamsDTORequest(List<uint> Teams);
|
|
|
|
|
private record DeleteTeamsRequest(List<uint> Teams);
|
|
|
|
|
|
|
|
|
|
public async Task DeleteTeams(List<uint> teams)
|
|
|
|
|
{
|
|
|
|
|
var httpResponse = await _client.PostAsJsonAsync($"/api/admin/delete-teams", new DeleteTeamsDTORequest(teams));
|
|
|
|
|
var httpResponse = await _client.PostAsJsonAsync($"/admin/teams/remove-all", new DeleteTeamsRequest(teams));
|
|
|
|
|
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private record UpdateTeamDTORequest(uint Id, string Name, string Picture, string MainColor, string SecondaryColor);
|
|
|
|
|
private record UpdateTeamRequest(uint Id, string Name, string Picture, string MainColor, string SecondaryColor);
|
|
|
|
|
|
|
|
|
|
public async Task UpdateTeam(Team team)
|
|
|
|
|
{
|
|
|
|
|
var httpResponse = await _client.PostAsJsonAsync($"/api/admin/team/{team.Id}/update",
|
|
|
|
|
new UpdateTeamDTORequest(team.Id, team.Name, team.Picture, team.MainColor, team.SecondColor) );
|
|
|
|
|
var httpResponse = await _client.PutAsJsonAsync($"/admin/teams/{team.Id}",
|
|
|
|
|
new UpdateTeamRequest(team.Id, team.Name, team.Picture, team.MainColor, team.SecondColor));
|
|
|
|
|
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|