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 Teams); public async Task<(uint, List)> 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()!; 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 Teams); public async Task DeleteTeams(List 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); } }