You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Server-Panel/Services/HttpTeamService.cs

50 lines
1.9 KiB

using System.Net.Http.Json;
using AdminPanel.Models;
namespace AdminPanel.Services;
public class HttpTeamService : ITeamService
{
private readonly HttpClient _client;
public HttpTeamService(HttpClient client)
{
this._client = client;
}
private record ListTeamResponse(uint TotalCount, List<Team> Teams);
public async Task<(uint, List<Team>)> ListTeam(uint from, uint count)
{
var httpResponse = await _client.GetAsync($"/api/admin/list-team?start={from}&n={count}");
httpResponse.EnsureSuccessStatusCode();
var response = await httpResponse.Content.ReadFromJsonAsync<ListTeamResponse>()!;
return (response.TotalCount, response.Teams);
}
private record AddTeamDTORequest(string Name, string Picture, string MainColor, string SecondaryColor);
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));
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
}
private record DeleteTeamsDTORequest(List<uint> Teams);
public async Task DeleteTeams(List<uint> teams)
{
var httpResponse = await _client.PostAsJsonAsync($"/api/admin/delete-teams", new DeleteTeamsDTORequest(teams));
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
}
private record UpdateTeamDTORequest(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) );
await ErrorsUtils.EnsureResponseIsOk(httpResponse);
}
}