32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using HermesSocketServer.Models;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace HermesSocketServer.Requests
|
|
{
|
|
public class DeleteConnection : IRequest
|
|
{
|
|
public string Name => "delete_connection";
|
|
public string[] RequiredKeys => ["id"];
|
|
private ILogger _logger;
|
|
|
|
public DeleteConnection(ILogger logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
|
{
|
|
var connectionId = data["id"].ToString()!;
|
|
|
|
var result = channel.Connections.Remove(connectionId);
|
|
if (result)
|
|
{
|
|
_logger.Information($"Deleted a connection by id [connection id: {connectionId}]");
|
|
return Task.FromResult(RequestResult.Successful(null));
|
|
}
|
|
|
|
_logger.Warning($"Connection Id does not exist [connection id: {connectionId}]");
|
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
|
}
|
|
}
|
|
} |