diff --git a/extra/admin-api/DataMappings/Spacebar.DataMappings.Generic/Member.cs b/extra/admin-api/DataMappings/Spacebar.DataMappings.Generic/Member.cs
index 2650fc38..2a61b75a 100644
--- a/extra/admin-api/DataMappings/Spacebar.DataMappings.Generic/Member.cs
+++ b/extra/admin-api/DataMappings/Spacebar.DataMappings.Generic/Member.cs
@@ -2,9 +2,9 @@ using Spacebar.Models.Generic;
namespace Spacebar.DataMappings.Generic;
-public static class Member
+public static class MemberExtensions
{
- public static Models.Generic.Member ToPublicMember(this Models.Db.Models.Member member, PartialUser? partialUser = null)
+ public static Member ToPublicMember(this Models.Db.Models.Member member, PartialUser? partialUser = null)
{
return new()
{
@@ -15,7 +15,8 @@ public static class Member
Collectibles = member.Collectibles,
DisplayNameStyles = member.DisplayNameStyles,
Bio = string.IsNullOrWhiteSpace(member.Bio) ? null : member.Bio,
- Nick = string.IsNullOrWhiteSpace(member.Nick) ? null : member.Nick
+ Nick = string.IsNullOrWhiteSpace(member.Nick) ? null : member.Nick,
+ Roles = member.Roles.Select(x=>x.Id).ToList()
};
}
}
\ No newline at end of file
diff --git a/extra/admin-api/Models/Spacebar.Models.Generic/Member.cs b/extra/admin-api/Models/Spacebar.Models.Generic/Member.cs
index cb47dc66..9ead9559 100644
--- a/extra/admin-api/Models/Spacebar.Models.Generic/Member.cs
+++ b/extra/admin-api/Models/Spacebar.Models.Generic/Member.cs
@@ -28,6 +28,9 @@ public class Member {
[JsonPropertyName("bio")]
public string? Bio { get; set; }
+
+ [JsonPropertyName("roles")]
+ public List<string>? Roles { get; set; }
}
// Unsure if this is used anywhere outside of op14...?
diff --git a/extra/admin-api/Spacebar.UApi/Controllers/GuildMembersController.cs b/extra/admin-api/Spacebar.UApi/Controllers/GuildMembersController.cs
new file mode 100644
index 00000000..ac8c1d40
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/Controllers/GuildMembersController.cs
@@ -0,0 +1,36 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Spacebar.Interop.Authentication.AspNetCore;
+using Spacebar.Models.Db.Contexts;
+using Spacebar.DataMappings.Generic;
+using Spacebar.Models.Generic;
+
+namespace Spacebar.UApi.Controllers;
+
+[Route("/api/v{_}/guilds/{guildId}/members/")]
+public class GuildMembersController(ILogger<GuildMembersController> logger, SpacebarDbContext db, SpacebarAspNetAuthenticationService authService) : ControllerBase {
+ /// <summary>
+ /// Get a guild member by ID
+ /// </summary>
+ /// <param name="guildId">Guild ID</param>
+ /// <param name="memberId">Member ID</param>
+ /// <returns>The public member projection</returns>
+ /// <exception cref="InvalidOperationException">An error has occured</exception>
+ [HttpGet("{memberId}")]
+ public async Task<Member> GetMemberAsync(string guildId, string memberId) {
+ var user = await authService.GetCurrentUserAsync(Request);
+ var cmember = db.Members.SingleOrDefault(x => x.Id == user.Id && x.GuildId == guildId);
+ if (cmember is null)
+ throw new InvalidOperationException("You are not a member of this guild.");
+
+ var member = db.Members
+ .Include(x => x.IdNavigation) // User object
+ .Include(x => x.Roles)
+ .SingleOrDefault(x => x.Id == user.Id && x.GuildId == guildId);
+
+ if (member is null)
+ throw new InvalidOperationException("Member not found");
+
+ return member.ToPublicMember();
+ }
+}
\ No newline at end of file
diff --git a/extra/admin-api/Spacebar.UApi/Program.cs b/extra/admin-api/Spacebar.UApi/Program.cs
new file mode 100644
index 00000000..4695b7ab
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/Program.cs
@@ -0,0 +1,83 @@
+using System.Text.Json.Serialization;
+using ArcaneLibs;
+using Microsoft.EntityFrameworkCore;
+using Spacebar.Interop.Authentication;
+using Spacebar.Interop.Authentication.AspNetCore;
+using Spacebar.Models.Db.Contexts;
+
+var builder = WebApplication.CreateBuilder(args);
+if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")))
+ builder.Configuration.AddJsonFile(Environment.GetEnvironmentVariable("APPSETTINGS_PATH")!);
+
+// Add services to the container.
+
+builder.Services.AddControllers(options => {
+ options.MaxValidationDepth = null;
+ // options.MaxIAsyncEnumerableBufferLimit = 1;
+}).AddJsonOptions(options => {
+ options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
+ options.JsonSerializerOptions.WriteIndented = true;
+ options.JsonSerializerOptions.MaxDepth = 100;
+ // options.JsonSerializerOptions.DefaultBufferSize = ;
+}).AddMvcOptions(o => { o.SuppressOutputFormatterBuffering = true; });
+// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
+builder.Services.AddOpenApi();
+
+builder.Services.AddDbContextPool<SpacebarDbContext>(options => {
+ options
+ .UseNpgsql(builder.Configuration.GetConnectionString("Spacebar"))
+ .EnableDetailedErrors();
+});
+
+builder.Services.AddSingleton<SpacebarAuthenticationConfiguration>();
+builder.Services.AddScoped<SpacebarAuthenticationService>();
+builder.Services.AddScoped<SpacebarAspNetAuthenticationService>();
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+if (app.Environment.IsDevelopment()) {
+ app.MapOpenApi();
+}
+
+app.UseAuthorization();
+
+app.MapControllers();
+app.Use((context, next) => {
+ context.Response.Headers["Access-Control-Allow-Origin"] = "*";
+ context.Response.Headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS";
+ context.Response.Headers["Access-Control-Allow-Headers"] = "*, Authorization";
+ if (context.Request.Method == "OPTIONS") {
+ context.Response.StatusCode = 200;
+ return Task.CompletedTask;
+ }
+
+ return next();
+});
+
+// fallback to proxy in case we dont have a specific endpoint...
+// TODO config
+app.MapFallback("{*_}", async context => {
+ var client = new StreamingHttpClient();
+ var requestMessage = new HttpRequestMessage(
+ new HttpMethod(context.Request.Method),
+ "http://api.old.server.spacebar.chat" + context.Request.Path + context.Request.QueryString
+ ) {
+ Content = new StreamContent(context.Request.Body)
+ };
+ Console.WriteLine(requestMessage.RequestUri);
+
+ foreach (var header in context.Request.Headers)
+ if (header.Key is not ("Accept-Encoding" or "Host"))
+ requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
+
+ var responseMessage = await client.SendUnhandledAsync(requestMessage, CancellationToken.None);
+ context.Response.StatusCode = (int)responseMessage.StatusCode;
+
+ foreach (var header in responseMessage.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
+ foreach (var header in responseMessage.Content.Headers) context.Response.Headers[header.Key] = header.Value.ToArray();
+
+ await responseMessage.Content.CopyToAsync(context.Response.Body);
+});
+
+app.Run();
\ No newline at end of file
diff --git a/extra/admin-api/Spacebar.UApi/Properties/launchSettings.json b/extra/admin-api/Spacebar.UApi/Properties/launchSettings.json
new file mode 100644
index 00000000..6871efac
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/Properties/launchSettings.json
@@ -0,0 +1,14 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": false,
+ "applicationUrl": "http://localhost:5085",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/extra/admin-api/Spacebar.UApi/Spacebar.UApi.csproj b/extra/admin-api/Spacebar.UApi/Spacebar.UApi.csproj
new file mode 100644
index 00000000..1fe9c799
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/Spacebar.UApi.csproj
@@ -0,0 +1,32 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+ <PropertyGroup>
+ <TargetFramework>net10.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <GenerateDocumentationFile>true</GenerateDocumentationFile>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="ArcaneLibs" Version="1.0.1-preview.20260126-091403"/>
+ <PackageReference Include="ArcaneLibs.StringNormalisation" Version="1.0.1-preview.20260126-091403"/>
+ <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2"/>
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\DataMappings\Spacebar.DataMappings.Generic\Spacebar.DataMappings.Generic.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.DataMappings.Generic" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Interop\Spacebar.Interop.Authentication.AspNetCore\Spacebar.Interop.Authentication.AspNetCore.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Interop.Authentication.AspNetCore" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Interop\Spacebar.Interop.Replication.UnixSocket\Spacebar.Interop.Replication.UnixSocket.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Interop.Replication.UnixSocket" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Models\Spacebar.Models.AdminApi\Spacebar.Models.AdminApi.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Models.AdminApi" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Models\Spacebar.Models.Config\Spacebar.Models.Config.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Models.Config" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Models\Spacebar.Models.Db\Spacebar.Models.Db.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Models.Db" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ <ProjectReference Include="..\Models\Spacebar.Models.Generic\Spacebar.Models.Generic.csproj" Condition="'$(ContinuousIntegrationBuild)'!='true'"/>
+ <PackageReference Include="Spacebar.Models.Generic" Version="*-preview*" Condition="'$(ContinuousIntegrationBuild)'=='true'"/>
+ </ItemGroup>
+</Project>
diff --git a/extra/admin-api/Spacebar.UApi/Spacebar.UApi.http b/extra/admin-api/Spacebar.UApi/Spacebar.UApi.http
new file mode 100644
index 00000000..aae3b7c3
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/Spacebar.UApi.http
@@ -0,0 +1,6 @@
+@Spacebar.UApi_HostAddress = http://localhost:5085
+
+GET {{Spacebar.UApi_HostAddress}}/weatherforecast/
+Accept: application/json
+
+###
diff --git a/extra/admin-api/Spacebar.UApi/appsettings.Development.json b/extra/admin-api/Spacebar.UApi/appsettings.Development.json
new file mode 100644
index 00000000..0c208ae9
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/extra/admin-api/Spacebar.UApi/appsettings.json b/extra/admin-api/Spacebar.UApi/appsettings.json
new file mode 100644
index 00000000..10f68b8c
--- /dev/null
+++ b/extra/admin-api/Spacebar.UApi/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/extra/admin-api/SpacebarAdminAPI.slnx b/extra/admin-api/SpacebarAdminAPI.slnx
index d628c2d7..56b9e332 100644
--- a/extra/admin-api/SpacebarAdminAPI.slnx
+++ b/extra/admin-api/SpacebarAdminAPI.slnx
@@ -36,4 +36,5 @@
<Project Path="Spacebar.AdminApi/Spacebar.AdminApi.csproj" />
<Project Path="Spacebar.Cdn/Spacebar.Cdn.csproj" />
<Project Path="Spacebar.GatewayOffload/Spacebar.GatewayOffload.csproj" />
+ <Project Path="Spacebar.UApi/Spacebar.UApi.csproj" />
</Solution>
|