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.
This commit is contained in:
Artemy
2025-07-06 17:43:10 +07:00
parent 857751f0ad
commit 42348c863f
8 changed files with 134 additions and 16 deletions
+1 -2
View File
@@ -36,8 +36,7 @@ namespace Govor.ConsoleClient
public async Task AcceptFriendRequestAsync(Guid requesterId)
{
var content = JsonContent.Create(requesterId);
var response = await _client.PostAsync("/api/friends/accept", content);
var response = await _client.PostAsync($"/api/friends/accept?friendshipId={requesterId}", null);
response.EnsureSuccessStatusCode();
}
+8 -6
View File
@@ -25,8 +25,10 @@ namespace Govor.ConsoleClient
{
class Program
{
//static string baseUrl = "https://govor-team-govor-88b3.twc1.net";
static string baseUrl = "https://localhost:7155";
static string? AuthToken = null;
static HttpClientService HttpService = new("https://govor-team-govor-88b3.twc1.net"); // поменяй URL на свой
static HttpClientService HttpService = new(baseUrl); // поменяй URL на свой
private static FriendsClient? friendsClient;
static HubConnection? _hubConnection;
static Dictionary<string, List<string>> ChatHistory = new();
@@ -72,7 +74,7 @@ namespace Govor.ConsoleClient
{
AuthToken = await HttpService.LoginAsync(loginUsername, loginPassword);
HttpClient sharedClient = new();
sharedClient.BaseAddress = new Uri("https://govor-team-govor-88b3.twc1.net");
sharedClient.BaseAddress = new Uri(baseUrl);
sharedClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthToken);
friendsClient = new FriendsClient(sharedClient);
@@ -98,7 +100,7 @@ namespace Govor.ConsoleClient
{
AuthToken = await HttpService.RegisterAsync(regUsername, regPassword, inviteCode);
HttpClient sharedClient = new();
sharedClient.BaseAddress = new Uri("https://govor-team-govor-88b3.twc1.net");
sharedClient.BaseAddress = new Uri(baseUrl);
sharedClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthToken);
friendsClient = new FriendsClient(sharedClient);
@@ -165,7 +167,7 @@ namespace Govor.ConsoleClient
Console.WriteLine("[Ошибка] Сначала войдите в систему.");
break;
}
Console.Write("Введите ID пользователя, чью заявку принимаете: ");
Console.Write("Введите ID заявки, которую хотите принять принимаете: ");
var acceptId = Guid.Parse(Console.ReadLine());
await friendsClient.AcceptFriendRequestAsync(acceptId);
Console.WriteLine("Принято");
@@ -179,7 +181,7 @@ namespace Govor.ConsoleClient
var requests = await friendsClient.GetIncomingRequestsAsync();
foreach (var r in requests)
{
Console.WriteLine($"Запрос от: {r.RequesterId} (добавьте через /accept {r.RequesterId})");
Console.WriteLine($"Запрос от: {r.Requester.Username}| {r.RequesterId} | Был онлайн: {r.Requester.WasOnline} (добавьте через /accept {r.Id})");
}
break;
case "/chat":
@@ -221,7 +223,7 @@ namespace Govor.ConsoleClient
}
_hubConnection = new HubConnectionBuilder()
.WithUrl("https://govor-team-govor-88b3.twc1.net/api/chats", options =>
.WithUrl($"{baseUrl}/api/chats", options =>
{
options.AccessTokenProvider = () => Task.FromResult(AuthToken);
})