Files
Govor/Govor.Console/FriendsClient.cs
T
2025-07-01 20:07:53 +07:00

54 lines
1.7 KiB
C#

using System.Net.Http.Json;
using Govor.Contracts.DTOs;
namespace Govor.ConsoleClient
{
public class FriendsClient
{
private readonly HttpClient _client;
public FriendsClient(HttpClient client)
{
_client = client;
}
public async Task<List<UserDto>> SearchAsync(string query)
{
var response = await _client.GetAsync($"/api/friends/search?query={query}");
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<List<UserDto>>() ?? new List<UserDto>();
}
public async Task SendFriendRequestAsync(Guid targetUserId)
{
var response = await _client.PostAsync($"api/friends/request?targetUserId={targetUserId}", null);
response.EnsureSuccessStatusCode();
}
public async Task<List<FriendshipDto>> GetIncomingRequestsAsync()
{
var response = await _client.GetAsync("/api/friends/requests");
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<List<FriendshipDto>>() ?? new List<FriendshipDto>();
}
public async Task AcceptFriendRequestAsync(Guid requesterId)
{
var content = JsonContent.Create(requesterId);
var response = await _client.PostAsync("/api/friends/accept", content);
response.EnsureSuccessStatusCode();
}
public async Task<List<UserDto>> GetFriendsAsync()
{
var response = await _client.GetAsync("/api/friends");
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<List<UserDto>>() ?? new List<UserDto>();
}
}
}