42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using HermesSocketLibrary.Requests.Messages;
|
|
using HermesSocketServer.Models;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace HermesSocketServer.Requests
|
|
{
|
|
public class UpdateGroup : IRequest
|
|
{
|
|
public string Name => "update_group";
|
|
public string[] RequiredKeys => ["id", "name", "priority"];
|
|
private ILogger _logger;
|
|
|
|
public UpdateGroup(ILogger logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
|
{
|
|
var id = data["id"].ToString()!;
|
|
string name = data["name"].ToString()!;
|
|
if (!int.TryParse(data["priority"].ToString()!, out var priority))
|
|
return Task.FromResult(RequestResult.Failed("Priority needs to be an integer."));
|
|
|
|
var group = new Group()
|
|
{
|
|
Id = id,
|
|
UserId = channel.Id,
|
|
Name = name,
|
|
Priority = priority,
|
|
};
|
|
|
|
bool result = channel.Groups.Modify(id, group);
|
|
if (result)
|
|
{
|
|
_logger.Information($"Updated group on channel [group id: {id}][name: {name}][priority: {priority}][channel: {channel.Id}]");
|
|
return Task.FromResult(RequestResult.Successful(group));
|
|
}
|
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
|
}
|
|
}
|
|
} |