Files
Govor/Govor.Console/FriendsClient.cs
T
Artemy 42348c863f Add admin friendships controller and improve friend request handling
Introduces FriendshipsController for admin operations, including listing and removing friendships. Updates routing for admin controllers, improves error handling in UsersController, and enhances FriendsController and related services to include requester details in friendship DTOs. Refactors friend request acceptance to use query parameters and updates console client for improved user feedback and local development configuration.
2025-07-06 17:43:10 +07:00

53 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 response = await _client.PostAsync($"/api/friends/accept?friendshipId={requesterId}", null);
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>();
}
}
}