32 lines
983 B
C#
32 lines
983 B
C#
|
using HermesSocketServer.Models;
|
||
|
using ILogger = Serilog.ILogger;
|
||
|
|
||
|
namespace HermesSocketServer.Requests
|
||
|
{
|
||
|
public class DeleteRedemption : IRequest
|
||
|
{
|
||
|
public string Name => "delete_redemption";
|
||
|
public string[] RequiredKeys => ["id"];
|
||
|
private ILogger _logger;
|
||
|
|
||
|
public DeleteRedemption(ILogger logger)
|
||
|
{
|
||
|
_logger = logger;
|
||
|
}
|
||
|
|
||
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||
|
{
|
||
|
string id = data["id"].ToString()!;
|
||
|
var result = channel.Redemptions.Remove(id);
|
||
|
|
||
|
if (result)
|
||
|
{
|
||
|
_logger.Information($"Deleted a redemption by id [id: {id}]");
|
||
|
return Task.FromResult(RequestResult.Successful(null));
|
||
|
}
|
||
|
|
||
|
_logger.Warning($"Redemption ID does not exist [id: {id}]");
|
||
|
return Task.FromResult(RequestResult.Failed("Redemption ID does not exist."));
|
||
|
}
|
||
|
}
|
||
|
}
|