Users
diff --git a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/Guilds.razor b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/Guilds.razor
new file mode 100644
index 00000000..454808b4
--- /dev/null
+++ b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/Guilds.razor
@@ -0,0 +1,80 @@
+@page "/Guilds"
+@using System.Net.Http.Headers
+@using System.Reflection
+@using Spacebar.AdminApi.Models
+@using Spacebar.AdminAPI.TestClient.Services
+@using ArcaneLibs.Blazor.Components
+@using ArcaneLibs.Extensions
+@inject Config Config
+@inject ILocalStorageService LocalStorage
+
+Guilds
+
+
+ Displayed columns
+ @foreach (var column in DisplayedColumns) {
+ var value = column.Value;
+
+ {
+ DisplayedColumns[column.Key] = b;
+ StateHasChanged();
+ })"/>
+ @column.Key.Name
+
+
+ }
+
+
+Got @GuildList.Count guilds.
+
+ @{
+ var columns = DisplayedColumns.Where(kvp => kvp.Value).Select(kvp => kvp.Key).ToList();
+ }
+
+
+ @foreach (var column in columns) {
+ | @column.Name |
+ }
+ Actions |
+
+
+
+ @foreach (var user in GuildList.Where(x => !x.Unavailable).OrderByDescending(x=>x.MessageCount)) {
+
+ @foreach (var column in columns) {
+ | @column.GetValue(user) |
+ }
+
+ Delete
+ |
+
+ }
+
+
+
+@code {
+
+ private Dictionary DisplayedColumns { get; set; } = typeof(GuildModel).GetProperties()
+ .ToDictionary(p => p, p => p.Name == "Name" || p.Name == "Id" || p.Name == "MessageCount");
+
+ private List GuildList { get; set; } = new();
+
+ protected override async Task OnInitializedAsync() {
+ var hc = new StreamingHttpClient();
+ hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Config.AccessToken);
+
+ // var request = new HttpRequestMessage(HttpMethod.Get, Config.AdminUrl + "/_spacebar/admin/users/");
+
+ var response = hc.GetAsyncEnumerableFromJsonAsync(Config.AdminUrl + "/_spacebar/admin/guilds/");
+ // if (!response.IsSuccessStatusCode) throw new Exception(await response.Content.ReadAsStringAsync());
+ // var content = response.Content.ReadFromJsonAsAsyncEnumerable();
+ await foreach (var user in response) {
+ // Console.WriteLine(user.ToJson(indent: false, ignoreNull: true));
+ GuildList.Add(user!);
+ if(GuildList.Count % 1000 == 0)
+ StateHasChanged();
+ }
+ StateHasChanged();
+ }
+
+}
\ No newline at end of file
diff --git a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClient.razor b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClient.razor
new file mode 100644
index 00000000..0be77a99
--- /dev/null
+++ b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClient.razor
@@ -0,0 +1,198 @@
+@page "/HttpTestClient"
+@using System.Collections.Immutable
+@using System.Text.Json
+@using ArcaneLibs.Blazor.Components
+@using ArcaneLibs.Extensions
+@using Spacebar.AdminAPI.TestClient.Classes.OpenAPI
+@using Spacebar.AdminAPI.TestClient.Pages.HttpTestClientParts
+@using Spacebar.AdminAPI.TestClient.Services
+@inject Config Config
+HttpTestClient
+
+@if (OpenApiSchema is not null) {
+ Got OpenAPI schema with @OpenApiSchema.Paths.Count paths.
+ Server:
+
+ var currentIndex = OpenApiSchema.Servers.IndexOf(Server!);
+
+ @for (var index = 0; index < OpenApiSchema.Servers.Count; index++) {
+ var server = OpenApiSchema.Servers[index];
+ var serverOptionName = $"{server.Description} ({server.Url})";
+
+ }
+
+
+
+ Path:
+
+
+
+ @foreach (var method in OpenApiSchema.Paths.SelectMany(x => x.Value.GetAvailableMethods()).Distinct()) {
+
+ }
+
+
+ @if (!string.IsNullOrWhiteSpace(_methodKey)) {
+
+
+ @foreach (var path in OpenApiSchema.Paths.Where(x => x.Value.HasMethod(_methodKey!)).OrderBy(x => x.Key)) {
+
+ }
+
+
+ }
+
+ if (Operation != null) {
+ if (!string.IsNullOrWhiteSpace(Operation.Description)) {
+ @Operation.Description
+ }
+ }
+
+
+ @AllKnownPathParameters.Count known path parameters
+ @foreach (var (param, value) in AllKnownPathParameters) {
+ var _key = param;
+ // if (Operation?.Parameters?.Any(x => x.Name == param.Name && x.In == param.In) ?? false)
+ // continue;
+
+
+ }
+
+
+ @AllKnownQueryParameters.Count known query parameters
+ @foreach (var (param, value) in AllKnownQueryParameters) {
+ var _key = param;
+ // if (Operation?.Parameters?.Any(x => x.Name == param.Name && x.In == param.In) ?? false)
+ // continue;
+
+
+ }
+
+
+ @if (Operation != null) {
+ if (Operation.Parameters?.Any() ?? false) {
+ var pathParams = Operation.Parameters.Where(x => x.In == "path").ToList();
+ if (pathParams.Any()) {
+ Path parameters
+
+ foreach (var key in pathParams) {
+ Path parameter
+
+
+ }
+ }
+
+ var queryParams = Operation.Parameters.Except(pathParams).Where(x => x.In == "query").ToList();
+ if (queryParams.Any()) {
+ Query parameters
+
+ foreach (var key in queryParams) {
+ Query parameter
+
+
+ }
+ }
+
+ var otherParams = Operation.Parameters.Except(pathParams).Except(queryParams).ToList();
+ if (otherParams.Any()) {
+ Other parameters
+
+ foreach (var key in otherParams) {
+ Other parameter
+
+
+ }
+ }
+ }
+
+ if(Operation.RequestBody is not null) {
+ Request body
+
+ @Operation.RequestBody.Content.ApplicationJson?.Schema.ToJson()
+ }
+ }
+
+ Execute
+ @ResultContent
+}
+
+@code {
+ private string? _pathKey;
+ private string? _methodKey;
+
+ private OpenApiSchema? OpenApiSchema { get; set; }
+ private OpenApiServer? Server { get; set; }
+ private Dictionary AllKnownPathParameters { get; set; } = [];
+ private Dictionary AllKnownQueryParameters { get; set; } = [];
+
+ private OpenApiPath? Path => string.IsNullOrWhiteSpace(_pathKey) ? null : OpenApiSchema?.Paths.GetValueOrDefault(_pathKey);
+ private OpenApiPath.OpenApiOperation? Operation => Path is null || string.IsNullOrWhiteSpace(_methodKey) ? null : Path.GetOperation(_methodKey);
+
+ private string? ResultContent { get; set; }
+ private readonly StreamingHttpClient _httpClient = new();
+
+ protected override async Task OnInitializedAsync() {
+ _httpClient.DefaultRequestHeaders.Authorization = new("Bearer", Config.AccessToken);
+
+ OpenApiSchema = await _httpClient.GetFromJsonAsync($"{Config.ApiUrl}/_spacebar/api/openapi.json");
+ OpenApiSchema!.Servers.Insert(0, Server = new() {
+ Description = "Current server (config)",
+ Url = Config.ApiUrl + "/api/v9"
+ });
+ SetCurrentServer(0);
+
+ AllKnownPathParameters = OpenApiSchema.Paths.Values
+ .SelectMany(x => x.GetAvailableMethods().Select(y => x.GetOperation(y)!.Parameters ?? []))
+ .SelectMany(x => x)
+ .Where(x => x.In == "path")
+ .DistinctBy(x => x.ToJson())
+ .OrderBy(x => x.Name)
+ .ToDictionary(x => x, _ => "");
+
+ AllKnownQueryParameters = OpenApiSchema.Paths.Values
+ .SelectMany(x => x.GetAvailableMethods().Select(y => x.GetOperation(y)!.Parameters ?? []))
+ .SelectMany(x => x)
+ .Where(x => x.In == "query")
+ .DistinctBy(x => x.ToJson())
+ .OrderBy(x => x.Name)
+ .ToDictionary(x => x, _ => "");
+ }
+
+ protected override bool ShouldRender() {
+ if (string.IsNullOrWhiteSpace(_methodKey))
+ _pathKey = null;
+ return base.ShouldRender();
+ }
+
+ private void SetCurrentServer(int index) {
+ Server = OpenApiSchema!.Servers[index];
+ _httpClient.BaseAddress = new Uri(Server.Url);
+ StateHasChanged();
+ }
+
+ private async Task Execute() {
+ var url = _pathKey!.TrimStart('/');
+ if (Operation?.Parameters?.Any(x => x.In == "path") ?? false) {
+ foreach (var param in Operation.Parameters.Where(x => x.In == "path")) {
+ if (!AllKnownPathParameters.TryGetValue(param, out var value) || string.IsNullOrWhiteSpace(value))
+ throw new Exception($"Path parameter {param.Name} not set");
+ url = url.Replace($"{{{param.Name}}}", value!);
+ }
+ }
+
+ var request = new HttpRequestMessage(new HttpMethod(_methodKey!), url);
+ try {
+ var response = await _httpClient.SendAsync(request);
+ ResultContent = response.Content.GetType().Name + "\n" + response.Content switch {
+ { Headers: { ContentType: { MediaType: "application/json" } } } => (await response.Content.ReadFromJsonAsync()).ToJson(true),
+ _ => await response.Content.ReadAsStringAsync()
+ };
+ }
+ catch (Exception ex) {
+ ResultContent = ex.ToString();
+ }
+
+ StateHasChanged();
+ }
+
+}
diff --git a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClientParts/OpenAPIParameterDescription.razor b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClientParts/OpenAPIParameterDescription.razor
new file mode 100644
index 00000000..89222453
--- /dev/null
+++ b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Pages/HttpTestClientParts/OpenAPIParameterDescription.razor
@@ -0,0 +1,21 @@
+@using ArcaneLibs.Extensions
+@using Spacebar.AdminAPI.TestClient.Classes.OpenAPI
+@Summary
+@if (Parameter.Name != Parameter.Description && !string.IsNullOrWhiteSpace(Parameter.Description)) {
+ - @Parameter.Description
+}
+
+@code {
+
+ private string Summary { get; set; } = "Unbound parameter";
+
+ [Parameter]
+ public required OpenApiPath.OpenApiOperation.OpenApiParameter Parameter {
+ get;
+ set {
+ field = value;
+ Summary = $"{Parameter.Name}{(Parameter.Required ? "*" : "")} ({Parameter.Schema.Type})";
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Spacebar.AdminAPI.TestClient.csproj b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Spacebar.AdminAPI.TestClient.csproj
index d9aeb06a..34ad6fa2 100644
--- a/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Spacebar.AdminAPI.TestClient.csproj
+++ b/extra/admin-api/Utilities/Spacebar.AdminAPI.TestClient/Spacebar.AdminAPI.TestClient.csproj
@@ -17,8 +17,8 @@
-
-
+
+
diff --git a/extra/admin-api/Utilities/Spacebar.AdminApi.PrepareTestData/Spacebar.AdminApi.PrepareTestData.csproj b/extra/admin-api/Utilities/Spacebar.AdminApi.PrepareTestData/Spacebar.AdminApi.PrepareTestData.csproj
index de3115ae..ff2d5c4c 100644
--- a/extra/admin-api/Utilities/Spacebar.AdminApi.PrepareTestData/Spacebar.AdminApi.PrepareTestData.csproj
+++ b/extra/admin-api/Utilities/Spacebar.AdminApi.PrepareTestData/Spacebar.AdminApi.PrepareTestData.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/RabbitMQService.cs b/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/RabbitMQService.cs
index 22255942..0eab6f90 100644
--- a/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/RabbitMQService.cs
+++ b/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/RabbitMQService.cs
@@ -3,11 +3,11 @@
namespace Spacebar.RabbitMqUtilities;
public interface IRabbitMQService {
- IConnection CreateChannel();
+ Task CreateChannel();
}
public class RabbitMQService(RabbitMQConfiguration config) : IRabbitMQService {
- public IConnection CreateChannel() {
+ public async Task CreateChannel() {
var connection = new ConnectionFactory {
UserName = config.Username,
Password = config.Password,
@@ -15,7 +15,7 @@ public class RabbitMQService(RabbitMQConfiguration config) : IRabbitMQService {
// DispatchConsumersAsync = true
};
- var channel = connection.CreateConnection();
+ var channel = await connection.CreateConnectionAsync();
return channel;
}
}
\ No newline at end of file
diff --git a/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/Spacebar.RabbitMqUtilities.csproj b/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/Spacebar.RabbitMqUtilities.csproj
index be1f4a77..dfd797ea 100644
--- a/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/Spacebar.RabbitMqUtilities.csproj
+++ b/extra/admin-api/Utilities/Spacebar.RabbitMqUtilities/Spacebar.RabbitMqUtilities.csproj
@@ -11,7 +11,7 @@
-
+