I refactored Govor.Console to use the command pattern. Here's what I did:

- I implemented a command-based architecture for Govor.Console.
- Each of your actions (e.g., login, send friend request, list friends) is now encapsulated in its own command class inheriting from BaseCommand.
- I integrated friend-related functionalities (search, list, send/accept/reject request, block/unblock) using a mix of SignalR Hub and REST API calls.
- I included admin functionalities for managing friendships (list all, list user's, remove).
- I added a /help (-h) command to display available commands and their usage.
- I refactored Program.cs to handle command parsing and execution.
- I updated FriendsClient.cs, removing methods now handled directly by commands via SignalR.
- I added SignalR event handlers for real-time notifications (friend requests, accepts, etc.).
This commit is contained in:
google-labs-jules[bot]
2025-07-11 05:47:22 +00:00
parent e8e2078514
commit b42c7d6de6
19 changed files with 1030 additions and 202 deletions
@@ -0,0 +1,51 @@
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Govor.ConsoleClient.Commands
{
public class SearchUserCommand : BaseCommand
{
public override async Task ExecuteAsync(string? argument)
{
if (!EnsureLoggedIn()) return;
if (string.IsNullOrWhiteSpace(argument))
{
Console.Write("Введите имя пользователя для поиска: ");
argument = Console.ReadLine();
if (string.IsNullOrWhiteSpace(argument))
{
Console.WriteLine("[Ошибка] Поисковый запрос не может быть пустым.");
return;
}
}
try
{
var foundUsers = await FriendsClient.SearchAsync(argument);
if (foundUsers.Any())
{
Console.WriteLine("Найденные пользователи:");
foreach (var user in foundUsers)
{
Console.WriteLine($"- {user.Username} [{user.Id}]");
}
}
else
{
Console.WriteLine("Пользователи не найдены.");
}
}
catch (Exception ex)
{
Console.WriteLine($"[Ошибка] {ex.Message}");
}
}
public override string GetHelp()
{
return "/search [имя_пользователя] - Найти пользователей по имени. Если имя не указано, запросит ввод.";
}
}
}