From 39c6442126742d4aeae38c4440246087bfbcd9aa Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 15 Aug 2024 22:15:54 +0000 Subject: [PATCH] Added support to fetch connections linked to account --- Requests/GetConnections.cs | 42 ++++++++++++++++++++++++++++++++++++++ Startup.cs | 1 + 2 files changed, 43 insertions(+) create mode 100644 Requests/GetConnections.cs diff --git a/Requests/GetConnections.cs b/Requests/GetConnections.cs new file mode 100644 index 0000000..d55f944 --- /dev/null +++ b/Requests/GetConnections.cs @@ -0,0 +1,42 @@ +using HermesSocketLibrary.db; +using HermesSocketLibrary.Requests; +using HermesSocketLibrary.Socket.Data; + +namespace HermesSocketServer.Requests +{ + public class GetConnections : IRequest + { + public string Name => "get_connections"; + + private Database _database; + private Serilog.ILogger _logger; + + public GetConnections(Database database, Serilog.ILogger logger) + { + _database = database; + _logger = logger; + } + + public async Task Grant(string sender, IDictionary? data) + { + var temp = new Dictionary() { { "user", sender } }; + + var connections = new List(); + string sql3 = "select \"name\", \"type\", \"clientId\", \"accessToken\", \"grantType\", \"scope\", \"expiresAt\", \"default\" from \"Connection\" where \"userId\" = @user"; + await _database.Execute(sql3, temp, sql => + connections.Add(new Connection() + { + Name = sql.GetString(0), + Type = sql.GetString(1), + ClientId = sql.GetString(2), + AccessToken = sql.GetString(3), + GrantType = sql.GetString(4), + Scope = sql.GetString(5), + ExpiresAt = sql.GetDateTime(6), + Default = sql.GetBoolean(7) + }) + ); + return new RequestResult(true, connections, false); + } + } +} \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index f75437b..8046e02 100644 --- a/Startup.cs +++ b/Startup.cs @@ -82,6 +82,7 @@ s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); +s.AddSingleton(); s.AddSingleton(); s.AddSingleton(); s.AddSingleton();