+
+
+
+
+
diff --git a/Moonlight.Api/Http/Controllers/Admin/SetupController.cs b/Moonlight.Api/Admin/Setup/SetupController.cs
similarity index 84%
rename from Moonlight.Api/Http/Controllers/Admin/SetupController.cs
rename to Moonlight.Api/Admin/Setup/SetupController.cs
index b68f350b..e1866d75 100644
--- a/Moonlight.Api/Http/Controllers/Admin/SetupController.cs
+++ b/Moonlight.Api/Admin/Setup/SetupController.cs
@@ -1,23 +1,22 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Services;
+using Moonlight.Api.Admin.Sys.Settings;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests.Seup;
+using Moonlight.Shared.Admin.Setup;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Setup;
[ApiController]
[Route("api/admin/setup")]
public class SetupController : Controller
{
+ private const string StateSettingsKey = "Moonlight.Api.Setup.State";
+ private readonly DatabaseRepository RolesRepository;
private readonly SettingsService SettingsService;
private readonly DatabaseRepository UsersRepository;
- private readonly DatabaseRepository RolesRepository;
-
- private const string StateSettingsKey = "Moonlight.Api.Setup.State";
public SetupController(
SettingsService settingsService,
@@ -51,41 +50,40 @@ public class SetupController : Controller
.FirstOrDefaultAsync(x => x.Name == "Administrators");
if (adminRole == null)
- {
- adminRole = await RolesRepository.AddAsync(new Role()
+ adminRole = await RolesRepository.AddAsync(new Role
{
Name = "Administrators",
Description = "Automatically generated group for full administrator permissions",
- Permissions = [
+ Permissions =
+ [
Permissions.ApiKeys.View,
Permissions.ApiKeys.Create,
Permissions.ApiKeys.Edit,
Permissions.ApiKeys.Delete,
-
+
Permissions.Roles.View,
Permissions.Roles.Create,
Permissions.Roles.Edit,
Permissions.Roles.Delete,
Permissions.Roles.Members,
-
+
Permissions.Users.View,
Permissions.Users.Create,
Permissions.Users.Edit,
Permissions.Users.Delete,
Permissions.Users.Logout,
-
+
Permissions.Themes.View,
Permissions.Themes.Create,
Permissions.Themes.Edit,
Permissions.Themes.Delete,
-
+
Permissions.System.Info,
Permissions.System.Diagnose,
Permissions.System.Versions,
- Permissions.System.Instance,
+ Permissions.System.Instance
]
});
- }
var user = await UsersRepository
@@ -94,12 +92,13 @@ public class SetupController : Controller
if (user == null)
{
- await UsersRepository.AddAsync(new User()
+ await UsersRepository.AddAsync(new User
{
Email = dto.AdminEmail,
Username = dto.AdminUsername,
- RoleMemberships = [
- new RoleMember()
+ RoleMemberships =
+ [
+ new RoleMember
{
Role = adminRole,
CreatedAt = DateTimeOffset.UtcNow,
@@ -112,16 +111,16 @@ public class SetupController : Controller
}
else
{
- user.RoleMemberships.Add(new RoleMember()
+ user.RoleMemberships.Add(new RoleMember
{
Role = adminRole,
CreatedAt = DateTimeOffset.UtcNow,
UpdatedAt = DateTimeOffset.UtcNow
});
-
+
await UsersRepository.UpdateAsync(user);
}
-
+
await SettingsService.SetValueAsync(StateSettingsKey, true);
return NoContent();
diff --git a/Moonlight.Api/Http/Controllers/Admin/ApiKeyController.cs b/Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyController.cs
similarity index 89%
rename from Moonlight.Api/Http/Controllers/Admin/ApiKeyController.cs
rename to Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyController.cs
index 2ff16560..5763b6c5 100644
--- a/Moonlight.Api/Http/Controllers/Admin/ApiKeyController.cs
+++ b/Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyController.cs
@@ -2,25 +2,22 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Implementations.ApiKeyScheme;
-using Moonlight.Api.Mappers;
+using Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests;
-using Moonlight.Shared.Http.Requests.Admin.ApiKeys;
-using Moonlight.Shared.Http.Responses;
-using Moonlight.Shared.Http.Responses.Admin.ApiKeys;
+using Moonlight.Shared.Admin.Sys.ApiKeys;
+using Moonlight.Shared.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Sys.ApiKeys;
[Authorize]
[ApiController]
[Route("api/admin/apiKeys")]
public class ApiKeyController : Controller
{
- private readonly DatabaseRepository KeyRepository;
private readonly HybridCache HybridCache;
+ private readonly DatabaseRepository KeyRepository;
public ApiKeyController(DatabaseRepository keyRepository, HybridCache hybridCache)
{
@@ -48,9 +45,7 @@ public class ApiKeyController : Controller
// Filters
if (filterOptions != null)
- {
foreach (var filterOption in filterOptions.Filters)
- {
query = filterOption.Key switch
{
nameof(ApiKey.Name) =>
@@ -61,8 +56,6 @@ public class ApiKeyController : Controller
_ => query
};
- }
- }
// Pagination
var data = await query
@@ -96,7 +89,7 @@ public class ApiKeyController : Controller
public async Task> CreateAsync([FromBody] CreateApiKeyDto request)
{
var apiKey = ApiKeyMapper.ToEntity(request);
-
+
apiKey.Key = Guid.NewGuid().ToString("N").Substring(0, 32);
var finalKey = await KeyRepository.AddAsync(apiKey);
@@ -135,9 +128,9 @@ public class ApiKeyController : Controller
return Problem("No API key with this id found", statusCode: 404);
await KeyRepository.RemoveAsync(apiKey);
-
+
await HybridCache.RemoveAsync(string.Format(ApiKeySchemeHandler.CacheKeyFormat, apiKey.Key));
-
+
return NoContent();
}
}
\ No newline at end of file
diff --git a/Moonlight.Api/Mappers/ApiKeyMapper.cs b/Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyMapper.cs
similarity index 77%
rename from Moonlight.Api/Mappers/ApiKeyMapper.cs
rename to Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyMapper.cs
index 55dd62e1..487d82d3 100644
--- a/Moonlight.Api/Mappers/ApiKeyMapper.cs
+++ b/Moonlight.Api/Admin/Sys/ApiKeys/ApiKeyMapper.cs
@@ -1,10 +1,9 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Shared.Http.Requests.Admin.ApiKeys;
-using Moonlight.Shared.Http.Responses.Admin.ApiKeys;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Shared.Admin.Sys.ApiKeys;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Sys.ApiKeys;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
diff --git a/Moonlight.Api/Configuration/ApiOptions.cs b/Moonlight.Api/Admin/Sys/ApiKeys/ApiOptions.cs
similarity index 81%
rename from Moonlight.Api/Configuration/ApiOptions.cs
rename to Moonlight.Api/Admin/Sys/ApiKeys/ApiOptions.cs
index 87959c7e..bba19781 100644
--- a/Moonlight.Api/Configuration/ApiOptions.cs
+++ b/Moonlight.Api/Admin/Sys/ApiKeys/ApiOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Sys.ApiKeys;
public class ApiOptions
{
diff --git a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs b/Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeHandler.cs
similarity index 91%
rename from Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs
rename to Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeHandler.cs
index 4f37e81d..33f4b586 100644
--- a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs
+++ b/Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeHandler.cs
@@ -5,19 +5,18 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-namespace Moonlight.Api.Implementations.ApiKeyScheme;
+namespace Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
public class ApiKeySchemeHandler : AuthenticationHandler
{
+ public const string CacheKeyFormat = $"Moonlight.Api.{nameof(ApiKeySchemeHandler)}.{{0}}";
private readonly DatabaseRepository ApiKeyRepository;
private readonly HybridCache HybridCache;
- public const string CacheKeyFormat = $"Moonlight.Api.{nameof(ApiKeySchemeHandler)}.{{0}}";
-
public ApiKeySchemeHandler(
IOptionsMonitor options,
ILoggerFactory logger,
@@ -50,9 +49,9 @@ public class ApiKeySchemeHandler : AuthenticationHandler
.Query()
.Where(x => x.Key == authHeaderValue)
.Select(x => new ApiKeySession(x.Permissions, x.ValidUntil))
- .FirstOrDefaultAsync(cancellationToken: ct);
+ .FirstOrDefaultAsync(ct);
},
- new HybridCacheEntryOptions()
+ new HybridCacheEntryOptions
{
LocalCacheExpiration = Options.LookupL1CacheTime,
Expiration = Options.LookupL2CacheTime
diff --git a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeOptions.cs b/Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeOptions.cs
similarity index 79%
rename from Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeOptions.cs
rename to Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeOptions.cs
index 0057f976..548bdff9 100644
--- a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeOptions.cs
+++ b/Moonlight.Api/Admin/Sys/ApiKeys/Scheme/ApiKeySchemeOptions.cs
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authentication;
-namespace Moonlight.Api.Implementations.ApiKeyScheme;
+namespace Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
public class ApiKeySchemeOptions : AuthenticationSchemeOptions
{
diff --git a/Moonlight.Api/Services/ApplicationService.cs b/Moonlight.Api/Admin/Sys/ApplicationService.cs
similarity index 87%
rename from Moonlight.Api/Services/ApplicationService.cs
rename to Moonlight.Api/Admin/Sys/ApplicationService.cs
index ce99cbdc..cef2606f 100644
--- a/Moonlight.Api/Services/ApplicationService.cs
+++ b/Moonlight.Api/Admin/Sys/ApplicationService.cs
@@ -1,24 +1,61 @@
using System.Diagnostics;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
-using Moonlight.Api.Helpers;
+using VersionService = Moonlight.Api.Admin.Sys.Versions.VersionService;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Sys;
public class ApplicationService : IHostedService
{
- private readonly VersionService VersionService;
private readonly ILogger Logger;
+ private readonly VersionService VersionService;
+
+ public ApplicationService(VersionService versionService, ILogger logger)
+ {
+ VersionService = versionService;
+ Logger = logger;
+ }
public DateTimeOffset StartedAt { get; private set; }
public string VersionName { get; private set; } = "N/A";
public bool IsUpToDate { get; set; } = true;
public string OperatingSystem { get; private set; } = "N/A";
- public ApplicationService(VersionService versionService, ILogger logger)
+ public async Task StartAsync(CancellationToken cancellationToken)
{
- VersionService = versionService;
- Logger = logger;
+ StartedAt = DateTimeOffset.UtcNow;
+
+ OperatingSystem = OsHelper.GetName();
+
+ try
+ {
+ var currentVersion = await VersionService.GetInstanceVersionAsync();
+ var latestVersion = await VersionService.GetLatestVersionAsync();
+
+ VersionName = currentVersion.Identifier;
+ IsUpToDate = latestVersion == null || currentVersion.Identifier == latestVersion.Identifier;
+
+ Logger.LogInformation("Running Moonlight Panel {version} on {operatingSystem}", VersionName,
+ OperatingSystem);
+
+ if (!IsUpToDate)
+ Logger.LogWarning("Your instance is not up-to-date");
+
+ if (currentVersion.IsDevelopment)
+ Logger.LogWarning("Your instance is running a development version");
+
+ if (currentVersion.IsPreRelease)
+ Logger.LogWarning("Your instance is running a pre-release version");
+ }
+ catch (Exception e)
+ {
+ Logger.LogError(e, "An unhandled exception occurred while fetching version details");
+ }
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
}
public Task GetMemoryUsageAsync()
@@ -45,41 +82,8 @@ public class ApplicationService : IHostedService
// Calculate CPU usage
var cpuUsedMs = (endCpuTime - startCpuTime).TotalMilliseconds;
var totalMsPassed = (endTime - startTime).TotalMilliseconds;
- var cpuUsagePercent = (cpuUsedMs / (Environment.ProcessorCount * totalMsPassed)) * 100;
+ var cpuUsagePercent = cpuUsedMs / (Environment.ProcessorCount * totalMsPassed) * 100;
return Math.Round(cpuUsagePercent, 2);
}
-
- public async Task StartAsync(CancellationToken cancellationToken)
- {
- StartedAt = DateTimeOffset.UtcNow;
-
- OperatingSystem = OsHelper.GetName();
-
- try
- {
- var currentVersion = await VersionService.GetInstanceVersionAsync();
- var latestVersion = await VersionService.GetLatestVersionAsync();
-
- VersionName = currentVersion.Identifier;
- IsUpToDate = latestVersion == null || currentVersion.Identifier == latestVersion.Identifier;
-
- Logger.LogInformation("Running Moonlight Panel {version} on {operatingSystem}", VersionName, OperatingSystem);
-
- if (!IsUpToDate)
- Logger.LogWarning("Your instance is not up-to-date");
-
- if (currentVersion.IsDevelopment)
- Logger.LogWarning("Your instance is running a development version");
-
- if (currentVersion.IsPreRelease)
- Logger.LogWarning("Your instance is running a pre-release version");
- }
- catch (Exception e)
- {
- Logger.LogError(e, "An unhandled exception occurred while fetching version details");
- }
- }
-
- public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Controllers/Admin/ContainerHelperController.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperController.cs
similarity index 83%
rename from Moonlight.Api/Http/Controllers/Admin/ContainerHelperController.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperController.cs
index fa61a329..23a7d72c 100644
--- a/Moonlight.Api/Http/Controllers/Admin/ContainerHelperController.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperController.cs
@@ -2,14 +2,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Services;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests.Admin.ContainerHelper;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys.ContainerHelper;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper;
[ApiController]
[Route("api/admin/ch")]
@@ -19,7 +15,8 @@ public class ContainerHelperController : Controller
private readonly ContainerHelperService ContainerHelperService;
private readonly IOptions Options;
- public ContainerHelperController(ContainerHelperService containerHelperService, IOptions options)
+ public ContainerHelperController(ContainerHelperService containerHelperService,
+ IOptions options)
{
ContainerHelperService = containerHelperService;
Options = options;
diff --git a/Moonlight.Api/Mappers/ContainerHelperMapper.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperMapper.cs
similarity index 60%
rename from Moonlight.Api/Mappers/ContainerHelperMapper.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperMapper.cs
index 26cc39b4..b293871f 100644
--- a/Moonlight.Api/Mappers/ContainerHelperMapper.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperMapper.cs
@@ -1,13 +1,13 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Shared.Http.Events;
+using Moonlight.Shared.Admin.Sys.ContainerHelper;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
[SuppressMessage("Mapper", "RMG012:No members are mapped in an object mapping")]
public static partial class ContainerHelperMapper
{
- public static partial RebuildEventDto ToDto(Http.Services.ContainerHelper.Events.RebuildEventDto rebuildEventDto);
+ public static partial RebuildEventDto ToDto(Models.Events.RebuildEventDto rebuildEventDto);
}
\ No newline at end of file
diff --git a/Moonlight.Api/Configuration/ContainerHelperOptions.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperOptions.cs
similarity index 72%
rename from Moonlight.Api/Configuration/ContainerHelperOptions.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperOptions.cs
index 42f89bd7..f2685952 100644
--- a/Moonlight.Api/Configuration/ContainerHelperOptions.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper;
public class ContainerHelperOptions
{
diff --git a/Moonlight.Api/Services/ContainerHelperService.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperService.cs
similarity index 86%
rename from Moonlight.Api/Services/ContainerHelperService.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperService.cs
index 2ce921a7..1c04a077 100644
--- a/Moonlight.Api/Services/ContainerHelperService.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/ContainerHelperService.cs
@@ -1,10 +1,10 @@
using System.Net.Http.Json;
using System.Text.Json;
-using Moonlight.Api.Http.Services.ContainerHelper;
-using Moonlight.Api.Http.Services.ContainerHelper.Requests;
-using Moonlight.Api.Http.Services.ContainerHelper.Events;
+using Moonlight.Api.Admin.Sys.ContainerHelper.Models;
+using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
+using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper;
public class ContainerHelperService
{
@@ -53,7 +53,7 @@ public class ContainerHelperService
{
var responseText = await response.Content.ReadAsStringAsync();
- yield return new RebuildEventDto()
+ yield return new RebuildEventDto
{
Type = RebuildEventType.Failed,
Data = responseText
@@ -76,7 +76,8 @@ public class ContainerHelperService
continue;
var data = line.Trim("data: ");
- var deserializedData = JsonSerializer.Deserialize(data, SerializationContext.Default.Options);
+ var deserializedData =
+ JsonSerializer.Deserialize(data, SerializationContext.Default.Options);
yield return deserializedData;
@@ -85,7 +86,7 @@ public class ContainerHelperService
yield break;
} while (true);
- yield return new RebuildEventDto()
+ yield return new RebuildEventDto
{
Type = RebuildEventType.Succeeded,
Data = string.Empty
diff --git a/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Events/RebuildEventDto.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Events/RebuildEventDto.cs
new file mode 100644
index 00000000..1d544723
--- /dev/null
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Events/RebuildEventDto.cs
@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+
+namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
+
+public struct RebuildEventDto
+{
+ [JsonPropertyName("type")] public RebuildEventType Type { get; set; }
+
+ [JsonPropertyName("data")] public string Data { get; set; }
+}
+
+public enum RebuildEventType
+{
+ Log = 0,
+ Failed = 1,
+ Succeeded = 2,
+ Step = 3
+}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Services/ContainerHelper/ProblemDetails.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/ProblemDetails.cs
similarity index 80%
rename from Moonlight.Api/Http/Services/ContainerHelper/ProblemDetails.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/Models/ProblemDetails.cs
index 925672c6..ea59d88d 100644
--- a/Moonlight.Api/Http/Services/ContainerHelper/ProblemDetails.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/ProblemDetails.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Http.Services.ContainerHelper;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models;
public class ProblemDetails
{
diff --git a/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/RequestRebuildDto.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/RequestRebuildDto.cs
new file mode 100644
index 00000000..22d0b37f
--- /dev/null
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/RequestRebuildDto.cs
@@ -0,0 +1,3 @@
+namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
+
+public record RequestRebuildDto(bool NoBuildCache);
\ No newline at end of file
diff --git a/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/SetVersionDto.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/SetVersionDto.cs
new file mode 100644
index 00000000..acec1902
--- /dev/null
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/Requests/SetVersionDto.cs
@@ -0,0 +1,3 @@
+namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
+
+public record SetVersionDto(string Version);
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Services/ContainerHelper/SerializationContext.cs b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/SerializationContext.cs
similarity index 66%
rename from Moonlight.Api/Http/Services/ContainerHelper/SerializationContext.cs
rename to Moonlight.Api/Admin/Sys/ContainerHelper/Models/SerializationContext.cs
index d7674b6c..df7c3a71 100644
--- a/Moonlight.Api/Http/Services/ContainerHelper/SerializationContext.cs
+++ b/Moonlight.Api/Admin/Sys/ContainerHelper/Models/SerializationContext.cs
@@ -1,17 +1,15 @@
using System.Text.Json;
using System.Text.Json.Serialization;
-using Moonlight.Api.Http.Services.ContainerHelper.Events;
-using Moonlight.Api.Http.Services.ContainerHelper.Requests;
+using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Events;
+using Moonlight.Api.Admin.Sys.ContainerHelper.Models.Requests;
-namespace Moonlight.Api.Http.Services.ContainerHelper;
+namespace Moonlight.Api.Admin.Sys.ContainerHelper.Models;
[JsonSerializable(typeof(SetVersionDto))]
[JsonSerializable(typeof(ProblemDetails))]
[JsonSerializable(typeof(RebuildEventDto))]
[JsonSerializable(typeof(RequestRebuildDto))]
-
[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
public partial class SerializationContext : JsonSerializerContext
{
-
}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Controllers/Admin/DiagnoseController.cs b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseController.cs
similarity index 81%
rename from Moonlight.Api/Http/Controllers/Admin/DiagnoseController.cs
rename to Moonlight.Api/Admin/Sys/Diagnose/DiagnoseController.cs
index 598f6368..8a4e4fec 100644
--- a/Moonlight.Api/Http/Controllers/Admin/DiagnoseController.cs
+++ b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseController.cs
@@ -1,11 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Services;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys.Diagnose;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Sys.Diagnose;
[ApiController]
[Authorize(Policy = Permissions.System.Diagnose)]
diff --git a/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResult.cs b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResult.cs
new file mode 100644
index 00000000..53482fec
--- /dev/null
+++ b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResult.cs
@@ -0,0 +1,17 @@
+namespace Moonlight.Api.Admin.Sys.Diagnose;
+
+public record DiagnoseResult(
+ DiagnoseLevel Level,
+ string Title,
+ string[] Tags,
+ string? Message,
+ string? StackStrace,
+ string? SolutionUrl,
+ string? ReportUrl);
+
+public enum DiagnoseLevel
+{
+ Error = 0,
+ Warning = 1,
+ Healthy = 2
+}
\ No newline at end of file
diff --git a/Moonlight.Api/Mappers/DiagnoseResultMapper.cs b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResultMapper.cs
similarity index 79%
rename from Moonlight.Api/Mappers/DiagnoseResultMapper.cs
rename to Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResultMapper.cs
index ffa91e04..9320f825 100644
--- a/Moonlight.Api/Mappers/DiagnoseResultMapper.cs
+++ b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseResultMapper.cs
@@ -1,9 +1,8 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Models;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys.Diagnose;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Sys.Diagnose;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
diff --git a/Moonlight.Api/Services/DiagnoseService.cs b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseService.cs
similarity index 88%
rename from Moonlight.Api/Services/DiagnoseService.cs
rename to Moonlight.Api/Admin/Sys/Diagnose/DiagnoseService.cs
index 0cfdf77b..02026fc4 100644
--- a/Moonlight.Api/Services/DiagnoseService.cs
+++ b/Moonlight.Api/Admin/Sys/Diagnose/DiagnoseService.cs
@@ -1,13 +1,12 @@
using Microsoft.Extensions.Logging;
-using Moonlight.Api.Interfaces;
-using Moonlight.Api.Models;
+using Moonlight.Api.Infrastructure.Hooks;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Sys.Diagnose;
public class DiagnoseService
{
- private readonly IEnumerable Providers;
private readonly ILogger Logger;
+ private readonly IEnumerable Providers;
public DiagnoseService(IEnumerable providers, ILogger logger)
{
@@ -20,7 +19,6 @@ public class DiagnoseService
var results = new List();
foreach (var provider in Providers)
- {
try
{
results.AddRange(
@@ -31,7 +29,6 @@ public class DiagnoseService
{
Logger.LogError(e, "An unhandled error occured while processing provider");
}
- }
return results.ToArray();
}
diff --git a/Moonlight.Api/Helpers/OsHelper.cs b/Moonlight.Api/Admin/Sys/OsHelper.cs
similarity index 84%
rename from Moonlight.Api/Helpers/OsHelper.cs
rename to Moonlight.Api/Admin/Sys/OsHelper.cs
index c53c37bf..c8aed9a2 100644
--- a/Moonlight.Api/Helpers/OsHelper.cs
+++ b/Moonlight.Api/Admin/Sys/OsHelper.cs
@@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
-namespace Moonlight.Api.Helpers;
+namespace Moonlight.Api.Admin.Sys;
public class OsHelper
{
@@ -53,17 +53,12 @@ public class OsHelper
string? version = null;
foreach (var line in lines)
- {
if (line.StartsWith("NAME="))
name = line.Substring(5).Trim('"');
else if (line.StartsWith("VERSION_ID="))
version = line.Substring(11).Trim('"');
- }
- if (!string.IsNullOrEmpty(name))
- {
- return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
- }
+ if (!string.IsNullOrEmpty(name)) return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
}
//If for some weird reason it still uses lsb release
@@ -74,17 +69,12 @@ public class OsHelper
string? version = null;
foreach (var line in lines)
- {
if (line.StartsWith("DISTRIB_ID="))
name = line.Substring(11);
else if (line.StartsWith("DISTRIB_RELEASE="))
version = line.Substring(16);
- }
- if (!string.IsNullOrEmpty(name))
- {
- return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
- }
+ if (!string.IsNullOrEmpty(name)) return string.IsNullOrEmpty(version) ? name : $"{name} {version}";
}
}
catch
diff --git a/Moonlight.Api/Configuration/SettingsOptions.cs b/Moonlight.Api/Admin/Sys/Settings/SettingsOptions.cs
similarity index 80%
rename from Moonlight.Api/Configuration/SettingsOptions.cs
rename to Moonlight.Api/Admin/Sys/Settings/SettingsOptions.cs
index 758e0374..2538a6d6 100644
--- a/Moonlight.Api/Configuration/SettingsOptions.cs
+++ b/Moonlight.Api/Admin/Sys/Settings/SettingsOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Sys.Settings;
public class SettingsOptions
{
diff --git a/Moonlight.Api/Services/SettingsService.cs b/Moonlight.Api/Admin/Sys/Settings/SettingsService.cs
similarity index 86%
rename from Moonlight.Api/Services/SettingsService.cs
rename to Moonlight.Api/Admin/Sys/Settings/SettingsService.cs
index c30cce2b..3e095cba 100644
--- a/Moonlight.Api/Services/SettingsService.cs
+++ b/Moonlight.Api/Admin/Sys/Settings/SettingsService.cs
@@ -2,25 +2,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Sys.Settings;
public class SettingsService
{
- private readonly DatabaseRepository Repository;
- private readonly IOptions Options;
- private readonly HybridCache HybridCache;
-
private const string CacheKey = "Moonlight.Api.SettingsService.{0}";
+ private readonly HybridCache HybridCache;
+ private readonly IOptions Options;
+ private readonly DatabaseRepository Repository;
public SettingsService(
DatabaseRepository repository,
IOptions options,
HybridCache hybridCache
- )
+ )
{
Repository = repository;
HybridCache = hybridCache;
@@ -39,9 +37,9 @@ public class SettingsService
.Query()
.Where(x => x.Key == key)
.Select(o => o.ValueJson)
- .FirstOrDefaultAsync(cancellationToken: ct);
+ .FirstOrDefaultAsync(ct);
},
- new HybridCacheEntryOptions()
+ new HybridCacheEntryOptions
{
LocalCacheExpiration = Options.Value.LookupL1CacheTime,
Expiration = Options.Value.LookupL2CacheTime
@@ -57,13 +55,13 @@ public class SettingsService
public async Task SetValueAsync(string key, T value)
{
var cacheKey = string.Format(CacheKey, key);
-
+
var option = await Repository
.Query()
.FirstOrDefaultAsync(x => x.Key == key);
var json = JsonSerializer.Serialize(value);
-
+
if (option != null)
{
option.ValueJson = json;
@@ -71,12 +69,12 @@ public class SettingsService
}
else
{
- option = new SettingsOption()
+ option = new SettingsOption
{
Key = key,
ValueJson = json
};
-
+
await Repository.AddAsync(option);
}
diff --git a/Moonlight.Api/Http/Controllers/Admin/Settings/WhiteLabelingController.cs b/Moonlight.Api/Admin/Sys/Settings/WhiteLabelingController.cs
similarity index 84%
rename from Moonlight.Api/Http/Controllers/Admin/Settings/WhiteLabelingController.cs
rename to Moonlight.Api/Admin/Sys/Settings/WhiteLabelingController.cs
index 1fee7384..2261e68a 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Settings/WhiteLabelingController.cs
+++ b/Moonlight.Api/Admin/Sys/Settings/WhiteLabelingController.cs
@@ -1,20 +1,18 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Api.Constants;
-using Moonlight.Api.Services;
+using Moonlight.Api.Shared.Frontend;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests.Admin.Settings;
-using Moonlight.Shared.Http.Responses.Admin.Settings;
+using Moonlight.Shared.Admin.Sys.Settings;
-namespace Moonlight.Api.Http.Controllers.Admin.Settings;
+namespace Moonlight.Api.Admin.Sys.Settings;
[ApiController]
[Authorize(Policy = Permissions.System.Settings)]
[Route("api/admin/system/settings/whiteLabeling")]
public class WhiteLabelingController : Controller
{
- private readonly SettingsService SettingsService;
private readonly FrontendService FrontendService;
+ private readonly SettingsService SettingsService;
public WhiteLabelingController(SettingsService settingsService, FrontendService frontendService)
{
@@ -38,7 +36,7 @@ public class WhiteLabelingController : Controller
{
await SettingsService.SetValueAsync(FrontendSettingConstants.Name, request.Name);
await FrontendService.ResetCacheAsync();
-
+
var dto = new WhiteLabelingDto
{
Name = await SettingsService.GetValueAsync(FrontendSettingConstants.Name) ?? "Moonlight"
diff --git a/Moonlight.Api/Http/Controllers/Admin/SystemController.cs b/Moonlight.Api/Admin/Sys/SystemController.cs
similarity index 88%
rename from Moonlight.Api/Http/Controllers/Admin/SystemController.cs
rename to Moonlight.Api/Admin/Sys/SystemController.cs
index 50d74229..9a24a1d4 100644
--- a/Moonlight.Api/Http/Controllers/Admin/SystemController.cs
+++ b/Moonlight.Api/Admin/Sys/SystemController.cs
@@ -1,10 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Api.Services;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Sys;
[ApiController]
[Route("api/admin/system")]
diff --git a/Moonlight.Api/Mappers/ThemeMapper.cs b/Moonlight.Api/Admin/Sys/Themes/ThemeMapper.cs
similarity index 77%
rename from Moonlight.Api/Mappers/ThemeMapper.cs
rename to Moonlight.Api/Admin/Sys/Themes/ThemeMapper.cs
index 4496a329..7eb29e1f 100644
--- a/Moonlight.Api/Mappers/ThemeMapper.cs
+++ b/Moonlight.Api/Admin/Sys/Themes/ThemeMapper.cs
@@ -1,10 +1,9 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Shared.Http.Requests.Admin.Themes;
-using Moonlight.Shared.Http.Responses.Admin.Themes;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Shared.Admin.Sys.Themes;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Sys.Themes;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
diff --git a/Moonlight.Api/Models/ThemeTransferModel.cs b/Moonlight.Api/Admin/Sys/Themes/ThemeTransferModel.cs
similarity index 85%
rename from Moonlight.Api/Models/ThemeTransferModel.cs
rename to Moonlight.Api/Admin/Sys/Themes/ThemeTransferModel.cs
index af816550..7fe3d836 100644
--- a/Moonlight.Api/Models/ThemeTransferModel.cs
+++ b/Moonlight.Api/Admin/Sys/Themes/ThemeTransferModel.cs
@@ -1,6 +1,6 @@
using VYaml.Annotations;
-namespace Moonlight.Api.Models;
+namespace Moonlight.Api.Admin.Sys.Themes;
[YamlObject]
public partial class ThemeTransferModel
diff --git a/Moonlight.Api/Http/Controllers/Admin/Themes/ThemesController.cs b/Moonlight.Api/Admin/Sys/Themes/ThemesController.cs
similarity index 90%
rename from Moonlight.Api/Http/Controllers/Admin/Themes/ThemesController.cs
rename to Moonlight.Api/Admin/Sys/Themes/ThemesController.cs
index ef8bac6a..0a9d4e6c 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Themes/ThemesController.cs
+++ b/Moonlight.Api/Admin/Sys/Themes/ThemesController.cs
@@ -1,24 +1,21 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Services;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Api.Shared.Frontend;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests;
-using Moonlight.Shared.Http.Requests.Admin.Themes;
-using Moonlight.Shared.Http.Responses;
-using Moonlight.Shared.Http.Responses.Admin.Themes;
+using Moonlight.Shared.Admin.Sys.Themes;
+using Moonlight.Shared.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin.Themes;
+namespace Moonlight.Api.Admin.Sys.Themes;
[ApiController]
[Route("api/admin/themes")]
public class ThemesController : Controller
{
- private readonly DatabaseRepository ThemeRepository;
private readonly FrontendService FrontendService;
+ private readonly DatabaseRepository ThemeRepository;
public ThemesController(DatabaseRepository themeRepository, FrontendService frontendService)
{
@@ -48,9 +45,7 @@ public class ThemesController : Controller
// Filters
if (filterOptions != null)
- {
foreach (var filterOption in filterOptions.Filters)
- {
query = filterOption.Key switch
{
nameof(Theme.Name) =>
@@ -64,8 +59,6 @@ public class ThemesController : Controller
_ => query
};
- }
- }
// Pagination
var data = await query
@@ -116,7 +109,7 @@ public class ThemesController : Controller
if (theme == null)
return Problem("No theme with this id found", statusCode: 404);
-
+
ThemeMapper.Merge(theme, request);
await ThemeRepository.UpdateAsync(theme);
@@ -137,9 +130,9 @@ public class ThemesController : Controller
return Problem("No theme with this id found", statusCode: 404);
await ThemeRepository.RemoveAsync(theme);
-
+
await FrontendService.ResetCacheAsync();
-
+
return NoContent();
}
}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Controllers/Admin/Themes/TransferController.cs b/Moonlight.Api/Admin/Sys/Themes/TransferController.cs
similarity index 89%
rename from Moonlight.Api/Http/Controllers/Admin/Themes/TransferController.cs
rename to Moonlight.Api/Admin/Sys/Themes/TransferController.cs
index 448aba94..7566eed4 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Themes/TransferController.cs
+++ b/Moonlight.Api/Admin/Sys/Themes/TransferController.cs
@@ -1,15 +1,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Models;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Responses.Admin.Themes;
+using Moonlight.Shared.Admin.Sys.Themes;
using VYaml.Serialization;
-namespace Moonlight.Api.Http.Controllers.Admin.Themes;
+namespace Moonlight.Api.Admin.Sys.Themes;
[ApiController]
[Route("api/admin/themes")]
@@ -33,7 +31,7 @@ public class TransferController : Controller
if (theme == null)
return Problem("No theme with that id found", statusCode: 404);
- var yml = YamlSerializer.Serialize(new ThemeTransferModel()
+ var yml = YamlSerializer.Serialize(new ThemeTransferModel
{
Name = theme.Name,
Author = theme.Author,
@@ -55,7 +53,7 @@ public class TransferController : Controller
if (existingTheme == null)
{
- var finalTheme = await ThemeRepository.AddAsync(new Theme()
+ var finalTheme = await ThemeRepository.AddAsync(new Theme
{
Name = themeToImport.Name,
Author = themeToImport.Author,
diff --git a/Moonlight.Api/Configuration/FrontendOptions.cs b/Moonlight.Api/Admin/Sys/Versions/FrontendOptions.cs
similarity index 74%
rename from Moonlight.Api/Configuration/FrontendOptions.cs
rename to Moonlight.Api/Admin/Sys/Versions/FrontendOptions.cs
index 7f417f0c..353366c3 100644
--- a/Moonlight.Api/Configuration/FrontendOptions.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/FrontendOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Sys.Versions;
public class FrontendOptions
{
diff --git a/Moonlight.Api/Models/MoonlightVersion.cs b/Moonlight.Api/Admin/Sys/Versions/MoonlightVersion.cs
similarity index 85%
rename from Moonlight.Api/Models/MoonlightVersion.cs
rename to Moonlight.Api/Admin/Sys/Versions/MoonlightVersion.cs
index 3d76c95f..4c9b9636 100644
--- a/Moonlight.Api/Models/MoonlightVersion.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/MoonlightVersion.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Models;
+namespace Moonlight.Api.Admin.Sys.Versions;
// Notes:
// Identifier - This needs to be the branch to clone to build this version if
diff --git a/Moonlight.Api/Mappers/VersionMapper.cs b/Moonlight.Api/Admin/Sys/Versions/VersionMapper.cs
similarity index 81%
rename from Moonlight.Api/Mappers/VersionMapper.cs
rename to Moonlight.Api/Admin/Sys/Versions/VersionMapper.cs
index 1477b1c3..749f9114 100644
--- a/Moonlight.Api/Mappers/VersionMapper.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/VersionMapper.cs
@@ -1,9 +1,8 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Models;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys.Versions;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Sys.Versions;
[Mapper]
[SuppressMessage("Mapper", "RMG020:Source member is not mapped to any target member")]
diff --git a/Moonlight.Api/Configuration/VersionOptions.cs b/Moonlight.Api/Admin/Sys/Versions/VersionOptions.cs
similarity index 73%
rename from Moonlight.Api/Configuration/VersionOptions.cs
rename to Moonlight.Api/Admin/Sys/Versions/VersionOptions.cs
index 341e2e85..9ba8901c 100644
--- a/Moonlight.Api/Configuration/VersionOptions.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/VersionOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Sys.Versions;
public class VersionOptions
{
diff --git a/Moonlight.Api/Services/VersionService.cs b/Moonlight.Api/Admin/Sys/Versions/VersionService.cs
similarity index 93%
rename from Moonlight.Api/Services/VersionService.cs
rename to Moonlight.Api/Admin/Sys/Versions/VersionService.cs
index fd5b6d2e..5f53cfe0 100644
--- a/Moonlight.Api/Services/VersionService.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/VersionService.cs
@@ -1,22 +1,16 @@
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Models;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Sys.Versions;
public partial class VersionService
{
- private readonly IOptions Options;
- private readonly IHttpClientFactory HttpClientFactory;
-
private const string VersionPath = "/app/version";
private const string GiteaServer = "https://git.battlestati.one";
private const string GiteaRepository = "Moonlight-Panel/Moonlight";
-
- [GeneratedRegex(@"^v(?!1(\.|$))\d+\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$")]
- private static partial Regex RegexFilter();
+ private readonly IHttpClientFactory HttpClientFactory;
+ private readonly IOptions Options;
public VersionService(
IOptions options,
@@ -27,11 +21,14 @@ public partial class VersionService
HttpClientFactory = httpClientFactory;
}
+ [GeneratedRegex(@"^v(?!1(\.|$))\d+\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$")]
+ private static partial Regex RegexFilter();
+
public async Task GetVersionsAsync()
{
if (Options.Value.OfflineMode)
return [];
-
+
var versions = new List();
var httpClient = HttpClientFactory.CreateClient();
@@ -42,7 +39,6 @@ public partial class VersionService
var tagsJson = await JsonNode.ParseAsync(tagsJsonStream);
if (tagsJson != null)
- {
foreach (var node in tagsJson.AsArray())
{
if (node == null)
@@ -50,8 +46,8 @@ public partial class VersionService
var name = node["name"]?.GetValue() ?? "N/A";
var createdAt = node["createdAt"]?.GetValue() ?? DateTimeOffset.MinValue;
-
- if(!RegexFilter().IsMatch(name))
+
+ if (!RegexFilter().IsMatch(name))
continue;
versions.Add(new MoonlightVersion(
@@ -61,8 +57,7 @@ public partial class VersionService
createdAt
));
}
- }
-
+
// Branches
const string branchesPath = $"{GiteaServer}/api/v1/repos/{GiteaRepository}/branches";
@@ -70,7 +65,6 @@ public partial class VersionService
var branchesJson = await JsonNode.ParseAsync(branchesJsonStream);
if (branchesJson != null)
- {
foreach (var node in branchesJson.AsArray())
{
if (node == null)
@@ -83,8 +77,8 @@ public partial class VersionService
continue;
var createdAt = commit["timestamp"]?.GetValue() ?? DateTimeOffset.MinValue;
-
- if(!RegexFilter().IsMatch(name))
+
+ if (!RegexFilter().IsMatch(name))
continue;
versions.Add(new MoonlightVersion(
@@ -94,7 +88,6 @@ public partial class VersionService
createdAt
));
}
- }
return versions.ToArray();
}
@@ -106,7 +99,9 @@ public partial class VersionService
string versionIdentifier;
if (!string.IsNullOrWhiteSpace(Options.Value.CurrentOverride))
+ {
versionIdentifier = Options.Value.CurrentOverride;
+ }
else
{
if (File.Exists(VersionPath))
diff --git a/Moonlight.Api/Http/Controllers/Admin/VersionsController.cs b/Moonlight.Api/Admin/Sys/Versions/VersionsController.cs
similarity index 85%
rename from Moonlight.Api/Http/Controllers/Admin/VersionsController.cs
rename to Moonlight.Api/Admin/Sys/Versions/VersionsController.cs
index bfa2f488..61bea381 100644
--- a/Moonlight.Api/Http/Controllers/Admin/VersionsController.cs
+++ b/Moonlight.Api/Admin/Sys/Versions/VersionsController.cs
@@ -1,11 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Services;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Sys.Versions;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Sys.Versions;
[ApiController]
[Route("api/admin/versions")]
@@ -37,8 +35,8 @@ public class VersionsController : Controller
public async Task> GetLatestAsync()
{
var version = await VersionService.GetLatestVersionAsync();
-
- if(version == null)
+
+ if (version == null)
return Problem("Unable to retrieve latest version", statusCode: 404);
return VersionMapper.ToDto(version);
diff --git a/Moonlight.Api/Mappers/RoleMapper.cs b/Moonlight.Api/Admin/Users/Roles/RoleMapper.cs
similarity index 80%
rename from Moonlight.Api/Mappers/RoleMapper.cs
rename to Moonlight.Api/Admin/Users/Roles/RoleMapper.cs
index b4a4e0ad..88fd1233 100644
--- a/Moonlight.Api/Mappers/RoleMapper.cs
+++ b/Moonlight.Api/Admin/Users/Roles/RoleMapper.cs
@@ -1,10 +1,9 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Shared.Http.Requests.Admin.Roles;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Shared.Admin.Users.Roles;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Users.Roles;
[Mapper]
[SuppressMessage("Mapper", "RMG020:Source member is not mapped to any target member")]
@@ -13,6 +12,7 @@ public static partial class RoleMapper
{
[MapProperty([nameof(Role.Members), nameof(Role.Members.Count)], nameof(RoleDto.MemberCount))]
public static partial RoleDto ToDto(Role role);
+
public static partial Role ToEntity(CreateRoleDto request);
public static partial void Merge([MappingTarget] Role role, UpdateRoleDto request);
diff --git a/Moonlight.Api/Http/Controllers/Admin/RoleMembersController.cs b/Moonlight.Api/Admin/Users/Roles/RoleMembersController.cs
similarity index 89%
rename from Moonlight.Api/Http/Controllers/Admin/RoleMembersController.cs
rename to Moonlight.Api/Admin/Users/Roles/RoleMembersController.cs
index ea2619c0..c42ac238 100644
--- a/Moonlight.Api/Http/Controllers/Admin/RoleMembersController.cs
+++ b/Moonlight.Api/Admin/Users/Roles/RoleMembersController.cs
@@ -1,23 +1,23 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Mappers;
+using Moonlight.Api.Admin.Users.Users;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Responses;
-using Moonlight.Shared.Http.Responses.Admin.Users;
+using Moonlight.Shared.Admin.Users.Users;
+using Moonlight.Shared.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Users.Roles;
[ApiController]
[Authorize(Policy = Permissions.Roles.Members)]
[Route("api/admin/roles/{roleId:int}/members")]
public class RoleMembersController : Controller
{
- private readonly DatabaseRepository UsersRepository;
- private readonly DatabaseRepository RolesRepository;
private readonly DatabaseRepository RoleMembersRepository;
+ private readonly DatabaseRepository RolesRepository;
+ private readonly DatabaseRepository UsersRepository;
public RoleMembersController(
DatabaseRepository usersRepository,
@@ -53,19 +53,16 @@ public class RoleMembersController : Controller
// Filtering
if (!string.IsNullOrWhiteSpace(searchTerm))
- {
query = query.Where(x =>
EF.Functions.ILike(x.Username, $"%{searchTerm}%") ||
EF.Functions.ILike(x.Email, $"%{searchTerm}%")
);
- }
// Pagination
- var items = query
- .OrderBy(x => x.Id)
- .Skip(startIndex)
- .Take(length)
- .ProjectToDto()
+ var items = UserMapper.ProjectToDto(query
+ .OrderBy(x => x.Id)
+ .Skip(startIndex)
+ .Take(length))
.ToArray();
var totalCount = await query.CountAsync();
@@ -95,19 +92,16 @@ public class RoleMembersController : Controller
// Filtering
if (!string.IsNullOrWhiteSpace(searchTerm))
- {
query = query.Where(x =>
EF.Functions.ILike(x.Username, $"%{searchTerm}%") ||
EF.Functions.ILike(x.Email, $"%{searchTerm}%")
);
- }
// Pagination
- var items = query
- .OrderBy(x => x.Id)
- .Skip(startIndex)
- .Take(length)
- .ProjectToDto()
+ var items = UserMapper.ProjectToDto(query
+ .OrderBy(x => x.Id)
+ .Skip(startIndex)
+ .Take(length))
.ToArray();
var totalCount = await query.CountAsync();
diff --git a/Moonlight.Api/Http/Controllers/Admin/RolesController.cs b/Moonlight.Api/Admin/Users/Roles/RolesController.cs
similarity index 89%
rename from Moonlight.Api/Http/Controllers/Admin/RolesController.cs
rename to Moonlight.Api/Admin/Users/Roles/RolesController.cs
index af1bdbff..595b4b9d 100644
--- a/Moonlight.Api/Http/Controllers/Admin/RolesController.cs
+++ b/Moonlight.Api/Admin/Users/Roles/RolesController.cs
@@ -1,16 +1,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Mappers;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests;
-using Moonlight.Shared.Http.Requests.Admin.Roles;
-using Moonlight.Shared.Http.Responses;
-using Moonlight.Shared.Http.Responses.Admin;
+using Moonlight.Shared.Admin.Users.Roles;
+using Moonlight.Shared.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin;
+namespace Moonlight.Api.Admin.Users.Roles;
[ApiController]
[Route("api/admin/roles")]
@@ -39,15 +36,13 @@ public class RolesController : Controller
return Problem("Invalid length specified");
// Query building
-
+
var query = RoleRepository
.Query();
// Filters
if (filterOptions != null)
- {
foreach (var filterOption in filterOptions.Filters)
- {
query = filterOption.Key switch
{
nameof(Role.Name) =>
@@ -55,8 +50,6 @@ public class RolesController : Controller
_ => query
};
- }
- }
// Pagination
var data = await query
@@ -106,7 +99,7 @@ public class RolesController : Controller
if (role == null)
return Problem("No role with this id found", statusCode: 404);
-
+
RoleMapper.Merge(role, request);
await RoleRepository.UpdateAsync(role);
diff --git a/Moonlight.Api/Services/UserAuthService.cs b/Moonlight.Api/Admin/Users/Users/UserAuthService.cs
similarity index 93%
rename from Moonlight.Api/Services/UserAuthService.cs
rename to Moonlight.Api/Admin/Users/Users/UserAuthService.cs
index 9a9a27c2..55a7883c 100644
--- a/Moonlight.Api/Services/UserAuthService.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserAuthService.cs
@@ -3,26 +3,24 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Interfaces;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Api.Infrastructure.Hooks;
using Moonlight.Shared;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Users.Users;
public class UserAuthService
{
- private readonly DatabaseRepository UserRepository;
- private readonly ILogger Logger;
- private readonly IOptions Options;
- private readonly IEnumerable Hooks;
- private readonly HybridCache HybridCache;
-
private const string UserIdClaim = "UserId";
private const string IssuedAtClaim = "IssuedAt";
public const string CacheKeyPattern = $"Moonlight.{nameof(UserAuthService)}.{nameof(ValidateAsync)}-{{0}}";
+ private readonly IEnumerable Hooks;
+ private readonly HybridCache HybridCache;
+ private readonly ILogger Logger;
+ private readonly IOptions Options;
+ private readonly DatabaseRepository UserRepository;
public UserAuthService(
DatabaseRepository userRepository,
@@ -60,7 +58,7 @@ public class UserAuthService
if (user == null) // Sync user if not already existing in the database
{
- user = await UserRepository.AddAsync(new User()
+ user = await UserRepository.AddAsync(new User
{
Username = username,
Email = email,
@@ -80,11 +78,9 @@ public class UserAuthService
]);
foreach (var hook in Hooks)
- {
// Run every hook, and if any returns false, we return false as well
if (!await hook.SyncAsync(principal, user))
return false;
- }
return true;
}
@@ -114,9 +110,9 @@ public class UserAuthService
u.InvalidateTimestamp,
u.RoleMemberships.SelectMany(x => x.Role.Permissions).ToArray())
)
- .FirstOrDefaultAsync(cancellationToken: ct);
+ .FirstOrDefaultAsync(ct);
},
- new HybridCacheEntryOptions()
+ new HybridCacheEntryOptions
{
LocalCacheExpiration = Options.Value.ValidationCacheL1Expiry,
Expiration = Options.Value.ValidationCacheL2Expiry
@@ -146,11 +142,9 @@ public class UserAuthService
);
foreach (var hook in Hooks)
- {
// Run every hook, and if any returns false we return false as well
if (!await hook.ValidateAsync(principal, userId))
return false;
- }
return true;
}
diff --git a/Moonlight.Api/Http/Controllers/Admin/Users/UserDeletionController.cs b/Moonlight.Api/Admin/Users/Users/UserDeletionController.cs
similarity index 84%
rename from Moonlight.Api/Http/Controllers/Admin/Users/UserDeletionController.cs
rename to Moonlight.Api/Admin/Users/Users/UserDeletionController.cs
index 48a5080f..eb30f38f 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Users/UserDeletionController.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserDeletionController.cs
@@ -1,21 +1,19 @@
-using System.Collections.Frozen;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Services;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin.Users;
+namespace Moonlight.Api.Admin.Users.Users;
[ApiController]
[Route("api/admin/users")]
[Authorize(Policy = Permissions.Users.Delete)]
public class UserDeletionController : Controller
{
- private readonly UserDeletionService UserDeletionService;
private readonly DatabaseRepository Repository;
+ private readonly UserDeletionService UserDeletionService;
public UserDeletionController(UserDeletionService userDeletionService, DatabaseRepository repository)
{
@@ -36,10 +34,9 @@ public class UserDeletionController : Controller
var validationResult = await UserDeletionService.ValidateAsync(id);
if (!validationResult.IsValid)
- {
return ValidationProblem(
new ValidationProblemDetails(
- new Dictionary()
+ new Dictionary
{
{
string.Empty,
@@ -48,8 +45,7 @@ public class UserDeletionController : Controller
}
)
);
- }
-
+
await UserDeletionService.DeleteAsync(id);
return NoContent();
}
diff --git a/Moonlight.Api/Services/UserDeletionService.cs b/Moonlight.Api/Admin/Users/Users/UserDeletionService.cs
similarity index 86%
rename from Moonlight.Api/Services/UserDeletionService.cs
rename to Moonlight.Api/Admin/Users/Users/UserDeletionService.cs
index 6253bbab..1bb13e89 100644
--- a/Moonlight.Api/Services/UserDeletionService.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserDeletionService.cs
@@ -1,22 +1,22 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Interfaces;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Api.Infrastructure.Hooks;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Users.Users;
public class UserDeletionService
{
- private readonly DatabaseRepository Repository;
private readonly IEnumerable Hooks;
private readonly HybridCache HybridCache;
+ private readonly DatabaseRepository Repository;
public UserDeletionService(
DatabaseRepository repository,
IEnumerable hooks,
HybridCache hybridCache
- )
+ )
{
Repository = repository;
Hooks = hooks;
@@ -28,20 +28,20 @@ public class UserDeletionService
var user = await Repository
.Query()
.FirstOrDefaultAsync(x => x.Id == userId);
-
- if(user == null)
+
+ if (user == null)
throw new AggregateException($"User with id {userId} not found");
-
+
var errorMessages = new List();
foreach (var hook in Hooks)
{
if (await hook.ValidateAsync(user, errorMessages))
continue;
-
+
return new UserDeletionValidationResult(false, errorMessages);
}
-
+
return new UserDeletionValidationResult(true, []);
}
@@ -50,13 +50,13 @@ public class UserDeletionService
var user = await Repository
.Query()
.FirstOrDefaultAsync(x => x.Id == userId);
-
- if(user == null)
+
+ if (user == null)
throw new AggregateException($"User with id {userId} not found");
-
+
foreach (var hook in Hooks)
await hook.ExecuteAsync(user);
-
+
await Repository.RemoveAsync(user);
await HybridCache.RemoveAsync(string.Format(UserAuthService.CacheKeyPattern, user.Id));
diff --git a/Moonlight.Api/Http/Controllers/Admin/Users/UserLogoutController.cs b/Moonlight.Api/Admin/Users/Users/UserLogoutController.cs
similarity index 86%
rename from Moonlight.Api/Http/Controllers/Admin/Users/UserLogoutController.cs
rename to Moonlight.Api/Admin/Users/Users/UserLogoutController.cs
index 20046ba8..69205060 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Users/UserLogoutController.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserLogoutController.cs
@@ -1,12 +1,11 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Services;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin.Users;
+namespace Moonlight.Api.Admin.Users.Users;
[ApiController]
[Route("api/admin/users/{id:int}/logout")]
diff --git a/Moonlight.Api/Services/UserLogoutService.cs b/Moonlight.Api/Admin/Users/Users/UserLogoutService.cs
similarity index 85%
rename from Moonlight.Api/Services/UserLogoutService.cs
rename to Moonlight.Api/Admin/Users/Users/UserLogoutService.cs
index 59b87257..20b79b57 100644
--- a/Moonlight.Api/Services/UserLogoutService.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserLogoutService.cs
@@ -1,16 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Hybrid;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Interfaces;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Api.Infrastructure.Hooks;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Admin.Users.Users;
public class UserLogoutService
{
- private readonly DatabaseRepository Repository;
private readonly IEnumerable Hooks;
private readonly HybridCache HybridCache;
+ private readonly DatabaseRepository Repository;
public UserLogoutService(
DatabaseRepository repository,
diff --git a/Moonlight.Api/Mappers/UserMapper.cs b/Moonlight.Api/Admin/Users/Users/UserMapper.cs
similarity index 77%
rename from Moonlight.Api/Mappers/UserMapper.cs
rename to Moonlight.Api/Admin/Users/Users/UserMapper.cs
index ef9673d3..5a312cad 100644
--- a/Moonlight.Api/Mappers/UserMapper.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserMapper.cs
@@ -1,10 +1,9 @@
using System.Diagnostics.CodeAnalysis;
+using Moonlight.Api.Infrastructure.Database.Entities;
+using Moonlight.Shared.Admin.Users.Users;
using Riok.Mapperly.Abstractions;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Shared.Http.Requests.Admin.Users;
-using Moonlight.Shared.Http.Responses.Admin.Users;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Admin.Users.Users;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
diff --git a/Moonlight.Api/Configuration/UserOptions.cs b/Moonlight.Api/Admin/Users/Users/UserOptions.cs
similarity index 81%
rename from Moonlight.Api/Configuration/UserOptions.cs
rename to Moonlight.Api/Admin/Users/Users/UserOptions.cs
index 84e8aac3..fefc937e 100644
--- a/Moonlight.Api/Configuration/UserOptions.cs
+++ b/Moonlight.Api/Admin/Users/Users/UserOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Admin.Users.Users;
public class UserOptions
{
diff --git a/Moonlight.Api/Http/Controllers/Admin/Users/UsersController.cs b/Moonlight.Api/Admin/Users/Users/UsersController.cs
similarity index 85%
rename from Moonlight.Api/Http/Controllers/Admin/Users/UsersController.cs
rename to Moonlight.Api/Admin/Users/Users/UsersController.cs
index e90ea5ed..d14b1fee 100644
--- a/Moonlight.Api/Http/Controllers/Admin/Users/UsersController.cs
+++ b/Moonlight.Api/Admin/Users/Users/UsersController.cs
@@ -1,16 +1,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Mappers;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
using Moonlight.Shared;
-using Moonlight.Shared.Http.Requests;
-using Moonlight.Shared.Http.Requests.Admin.Users;
-using Moonlight.Shared.Http.Responses;
-using Moonlight.Shared.Http.Responses.Admin.Users;
+using Moonlight.Shared.Admin.Users.Users;
+using Moonlight.Shared.Shared;
-namespace Moonlight.Api.Http.Controllers.Admin.Users;
+namespace Moonlight.Api.Admin.Users.Users;
[Authorize]
[ApiController]
@@ -40,27 +37,23 @@ public class UsersController : Controller
return Problem("Invalid length specified");
// Query building
-
+
var query = UserRepository
.Query();
// Filters
if (filterOptions != null)
- {
foreach (var filterOption in filterOptions.Filters)
- {
query = filterOption.Key switch
{
- nameof(Database.Entities.User.Email) =>
+ nameof(Infrastructure.Database.Entities.User.Email) =>
query.Where(user => EF.Functions.ILike(user.Email, $"%{filterOption.Value}%")),
- nameof(Database.Entities.User.Username) =>
+ nameof(Infrastructure.Database.Entities.User.Username) =>
query.Where(user => EF.Functions.ILike(user.Username, $"%{filterOption.Value}%")),
_ => query
};
- }
- }
// Pagination
var data = await query
diff --git a/Moonlight.Api/Database/Entities/Theme.cs b/Moonlight.Api/Database/Entities/Theme.cs
deleted file mode 100644
index bbaf6e32..00000000
--- a/Moonlight.Api/Database/Entities/Theme.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.ComponentModel.DataAnnotations;
-
-namespace Moonlight.Api.Database.Entities;
-
-public class Theme
-{
- public int Id { get; set; }
-
- [MaxLength(30)]
- public required string Name { get; set; }
-
- [MaxLength(30)]
- public required string Version { get; set; }
-
- [MaxLength(30)]
- public required string Author { get; set; }
- public bool IsEnabled { get; set; }
-
- [MaxLength(20_000)]
- public required string CssContent { get; set; }
-}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Services/ContainerHelper/Events/RebuildEventDto.cs b/Moonlight.Api/Http/Services/ContainerHelper/Events/RebuildEventDto.cs
deleted file mode 100644
index 1742b643..00000000
--- a/Moonlight.Api/Http/Services/ContainerHelper/Events/RebuildEventDto.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Text.Json.Serialization;
-
-namespace Moonlight.Api.Http.Services.ContainerHelper.Events;
-
-public struct RebuildEventDto
-{
- [JsonPropertyName("type")]
- public RebuildEventType Type { get; set; }
-
- [JsonPropertyName("data")]
- public string Data { get; set; }
-}
-
-public enum RebuildEventType
-{
- Log = 0,
- Failed = 1,
- Succeeded = 2,
- Step = 3
-}
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Services/ContainerHelper/Requests/RequestRebuildDto.cs b/Moonlight.Api/Http/Services/ContainerHelper/Requests/RequestRebuildDto.cs
deleted file mode 100644
index c7dda283..00000000
--- a/Moonlight.Api/Http/Services/ContainerHelper/Requests/RequestRebuildDto.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace Moonlight.Api.Http.Services.ContainerHelper.Requests;
-
-public record RequestRebuildDto(bool NoBuildCache);
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Services/ContainerHelper/Requests/SetVersionDto.cs b/Moonlight.Api/Http/Services/ContainerHelper/Requests/SetVersionDto.cs
deleted file mode 100644
index 4c462fbc..00000000
--- a/Moonlight.Api/Http/Services/ContainerHelper/Requests/SetVersionDto.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace Moonlight.Api.Http.Services.ContainerHelper.Requests;
-
-public record SetVersionDto(string Version);
\ No newline at end of file
diff --git a/Moonlight.Api/Configuration/CacheOptions.cs b/Moonlight.Api/Infrastructure/Configuration/CacheOptions.cs
similarity index 56%
rename from Moonlight.Api/Configuration/CacheOptions.cs
rename to Moonlight.Api/Infrastructure/Configuration/CacheOptions.cs
index 1d166b4f..72b8ed32 100644
--- a/Moonlight.Api/Configuration/CacheOptions.cs
+++ b/Moonlight.Api/Infrastructure/Configuration/CacheOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Infrastructure.Configuration;
public class CacheOptions
{
diff --git a/Moonlight.Api/Configuration/OidcOptions.cs b/Moonlight.Api/Infrastructure/Configuration/OidcOptions.cs
similarity index 86%
rename from Moonlight.Api/Configuration/OidcOptions.cs
rename to Moonlight.Api/Infrastructure/Configuration/OidcOptions.cs
index bf7c0625..145f1572 100644
--- a/Moonlight.Api/Configuration/OidcOptions.cs
+++ b/Moonlight.Api/Infrastructure/Configuration/OidcOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Infrastructure.Configuration;
public class OidcOptions
{
diff --git a/Moonlight.Api/Configuration/RedisOptions.cs b/Moonlight.Api/Infrastructure/Configuration/RedisOptions.cs
similarity index 67%
rename from Moonlight.Api/Configuration/RedisOptions.cs
rename to Moonlight.Api/Infrastructure/Configuration/RedisOptions.cs
index 37935ff7..9b51810a 100644
--- a/Moonlight.Api/Configuration/RedisOptions.cs
+++ b/Moonlight.Api/Infrastructure/Configuration/RedisOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Infrastructure.Configuration;
public class RedisOptions
{
diff --git a/Moonlight.Api/Database/DataContext.cs b/Moonlight.Api/Infrastructure/Database/DataContext.cs
similarity index 76%
rename from Moonlight.Api/Database/DataContext.cs
rename to Moonlight.Api/Infrastructure/Database/DataContext.cs
index 36c7d758..f71a4444 100644
--- a/Moonlight.Api/Database/DataContext.cs
+++ b/Moonlight.Api/Infrastructure/Database/DataContext.cs
@@ -1,19 +1,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Database.Entities;
+using Moonlight.Api.Infrastructure.Database.Entities;
-namespace Moonlight.Api.Database;
+namespace Moonlight.Api.Infrastructure.Database;
public class DataContext : DbContext
{
- public DbSet Users { get; set; }
- public DbSet SettingsOptions { get; set; }
- public DbSet Roles { get; set; }
- public DbSet RoleMembers { get; set; }
- public DbSet ApiKeys { get; set; }
- public DbSet Themes { get; set; }
-
private readonly IOptions Options;
public DataContext(IOptions options)
@@ -21,24 +13,36 @@ public class DataContext : DbContext
Options = options;
}
+ public DbSet Users { get; set; }
+ public DbSet SettingsOptions { get; set; }
+ public DbSet Roles { get; set; }
+ public DbSet RoleMembers { get; set; }
+ public DbSet ApiKeys { get; set; }
+ public DbSet Themes { get; set; }
+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured)
return;
-
+
optionsBuilder.UseNpgsql(
$"Host={Options.Value.Host};" +
$"Port={Options.Value.Port};" +
$"Username={Options.Value.Username};" +
$"Password={Options.Value.Password};" +
- $"Database={Options.Value.Database}"
+ $"Database={Options.Value.Database}",
+ builder =>
+ {
+ builder.MigrationsAssembly(typeof(DataContext).Assembly);
+ builder.MigrationsHistoryTable("MigrationsHistory", "core");
+ }
);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("core");
-
+
base.OnModelCreating(modelBuilder);
}
}
\ No newline at end of file
diff --git a/Moonlight.Api/Configuration/DatabaseOptions.cs b/Moonlight.Api/Infrastructure/Database/DatabaseOptions.cs
similarity index 81%
rename from Moonlight.Api/Configuration/DatabaseOptions.cs
rename to Moonlight.Api/Infrastructure/Database/DatabaseOptions.cs
index 4685d628..22074dde 100644
--- a/Moonlight.Api/Configuration/DatabaseOptions.cs
+++ b/Moonlight.Api/Infrastructure/Database/DatabaseOptions.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Configuration;
+namespace Moonlight.Api.Infrastructure.Database;
public class DatabaseOptions
{
diff --git a/Moonlight.Api/Database/DatabaseRepository.cs b/Moonlight.Api/Infrastructure/Database/DatabaseRepository.cs
similarity index 86%
rename from Moonlight.Api/Database/DatabaseRepository.cs
rename to Moonlight.Api/Infrastructure/Database/DatabaseRepository.cs
index 4dcdcc8f..709e31d4 100644
--- a/Moonlight.Api/Database/DatabaseRepository.cs
+++ b/Moonlight.Api/Infrastructure/Database/DatabaseRepository.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
-using Moonlight.Api.Database.Interfaces;
+using Moonlight.Api.Infrastructure.Database.Interfaces;
-namespace Moonlight.Api.Database;
+namespace Moonlight.Api.Infrastructure.Database;
public class DatabaseRepository where T : class
{
@@ -14,7 +14,10 @@ public class DatabaseRepository where T : class
Set = DataContext.Set();
}
- public IQueryable Query() => Set;
+ public IQueryable Query()
+ {
+ return Set;
+ }
public async Task AddAsync(T entity)
{
@@ -23,7 +26,7 @@ public class DatabaseRepository where T : class
actionTimestamps.CreatedAt = DateTimeOffset.UtcNow;
actionTimestamps.UpdatedAt = DateTimeOffset.UtcNow;
}
-
+
var final = Set.Add(entity);
await DataContext.SaveChangesAsync();
return final.Entity;
@@ -33,7 +36,7 @@ public class DatabaseRepository where T : class
{
if (entity is IActionTimestamps actionTimestamps)
actionTimestamps.UpdatedAt = DateTimeOffset.UtcNow;
-
+
Set.Update(entity);
await DataContext.SaveChangesAsync();
}
diff --git a/Moonlight.Api/Services/DbMigrationService.cs b/Moonlight.Api/Infrastructure/Database/DbMigrationService.cs
similarity index 78%
rename from Moonlight.Api/Services/DbMigrationService.cs
rename to Moonlight.Api/Infrastructure/Database/DbMigrationService.cs
index 4d300a47..631b1bb1 100644
--- a/Moonlight.Api/Services/DbMigrationService.cs
+++ b/Moonlight.Api/Infrastructure/Database/DbMigrationService.cs
@@ -2,9 +2,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
-using Moonlight.Api.Database;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Infrastructure.Database;
public class DbMigrationService : IHostedLifecycleService
{
@@ -41,9 +40,28 @@ public class DbMigrationService : IHostedLifecycleService
Logger.LogInformation("Migration complete");
}
- public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
- public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
- public Task StartedAsync(CancellationToken cancellationToken) => Task.CompletedTask;
- public Task StoppedAsync(CancellationToken cancellationToken) => Task.CompletedTask;
- public Task StoppingAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+ public Task StartAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task StartedAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task StoppedAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task StoppingAsync(CancellationToken cancellationToken)
+ {
+ return Task.CompletedTask;
+ }
}
\ No newline at end of file
diff --git a/Moonlight.Api/Database/Entities/ApiKey.cs b/Moonlight.Api/Infrastructure/Database/Entities/ApiKey.cs
similarity index 53%
rename from Moonlight.Api/Database/Entities/ApiKey.cs
rename to Moonlight.Api/Infrastructure/Database/Entities/ApiKey.cs
index 3073f0c6..ea0a2c39 100644
--- a/Moonlight.Api/Database/Entities/ApiKey.cs
+++ b/Moonlight.Api/Infrastructure/Database/Entities/ApiKey.cs
@@ -1,24 +1,21 @@
using System.ComponentModel.DataAnnotations;
-using Moonlight.Api.Database.Interfaces;
+using Moonlight.Api.Infrastructure.Database.Interfaces;
-namespace Moonlight.Api.Database.Entities;
+namespace Moonlight.Api.Infrastructure.Database.Entities;
public class ApiKey : IActionTimestamps
{
public int Id { get; set; }
- [MaxLength(30)]
- public required string Name { get; set; }
-
- [MaxLength(300)]
- public required string Description { get; set; }
-
+ [MaxLength(30)] public required string Name { get; set; }
+
+ [MaxLength(300)] public required string Description { get; set; }
+
public string[] Permissions { get; set; } = [];
public DateTimeOffset ValidUntil { get; set; }
-
- [MaxLength(32)]
- public string Key { get; set; }
-
+
+ [MaxLength(32)] public string Key { get; set; }
+
// Action timestamps
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
diff --git a/Moonlight.Api/Database/Entities/Role.cs b/Moonlight.Api/Infrastructure/Database/Entities/Role.cs
similarity index 59%
rename from Moonlight.Api/Database/Entities/Role.cs
rename to Moonlight.Api/Infrastructure/Database/Entities/Role.cs
index a38ccd13..e19a629c 100644
--- a/Moonlight.Api/Database/Entities/Role.cs
+++ b/Moonlight.Api/Infrastructure/Database/Entities/Role.cs
@@ -1,23 +1,21 @@
using System.ComponentModel.DataAnnotations;
-using Moonlight.Api.Database.Interfaces;
+using Moonlight.Api.Infrastructure.Database.Interfaces;
-namespace Moonlight.Api.Database.Entities;
+namespace Moonlight.Api.Infrastructure.Database.Entities;
public class Role : IActionTimestamps
{
public int Id { get; set; }
- [MaxLength(30)]
- public required string Name { get; set; }
-
- [MaxLength(300)]
- public required string Description { get; set; }
+ [MaxLength(30)] public required string Name { get; set; }
+
+ [MaxLength(300)] public required string Description { get; set; }
public string[] Permissions { get; set; } = [];
-
+
// Relations
public List Members { get; set; } = [];
-
+
// Action timestamps
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
diff --git a/Moonlight.Api/Database/Entities/RoleMember.cs b/Moonlight.Api/Infrastructure/Database/Entities/RoleMember.cs
similarity index 70%
rename from Moonlight.Api/Database/Entities/RoleMember.cs
rename to Moonlight.Api/Infrastructure/Database/Entities/RoleMember.cs
index 5363689a..4315e1fd 100644
--- a/Moonlight.Api/Database/Entities/RoleMember.cs
+++ b/Moonlight.Api/Infrastructure/Database/Entities/RoleMember.cs
@@ -1,6 +1,6 @@
-using Moonlight.Api.Database.Interfaces;
+using Moonlight.Api.Infrastructure.Database.Interfaces;
-namespace Moonlight.Api.Database.Entities;
+namespace Moonlight.Api.Infrastructure.Database.Entities;
public class RoleMember : IActionTimestamps
{
@@ -8,7 +8,7 @@ public class RoleMember : IActionTimestamps
public Role Role { get; set; }
public User User { get; set; }
-
+
// Action timestamps
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
diff --git a/Moonlight.Api/Database/Entities/SettingsOption.cs b/Moonlight.Api/Infrastructure/Database/Entities/SettingsOption.cs
similarity index 68%
rename from Moonlight.Api/Database/Entities/SettingsOption.cs
rename to Moonlight.Api/Infrastructure/Database/Entities/SettingsOption.cs
index 74cf210a..d23d22e9 100644
--- a/Moonlight.Api/Database/Entities/SettingsOption.cs
+++ b/Moonlight.Api/Infrastructure/Database/Entities/SettingsOption.cs
@@ -1,15 +1,14 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
-namespace Moonlight.Api.Database.Entities;
+namespace Moonlight.Api.Infrastructure.Database.Entities;
public class SettingsOption
{
public int Id { get; set; }
- [MaxLength(256)]
- public required string Key { get; set; }
-
+ [MaxLength(256)] public required string Key { get; set; }
+
[MaxLength(4096)]
[Column(TypeName = "jsonb")]
public required string ValueJson { get; set; }
diff --git a/Moonlight.Api/Infrastructure/Database/Entities/Theme.cs b/Moonlight.Api/Infrastructure/Database/Entities/Theme.cs
new file mode 100644
index 00000000..e054a1cd
--- /dev/null
+++ b/Moonlight.Api/Infrastructure/Database/Entities/Theme.cs
@@ -0,0 +1,18 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace Moonlight.Api.Infrastructure.Database.Entities;
+
+public class Theme
+{
+ public int Id { get; set; }
+
+ [MaxLength(30)] public required string Name { get; set; }
+
+ [MaxLength(30)] public required string Version { get; set; }
+
+ [MaxLength(30)] public required string Author { get; set; }
+
+ public bool IsEnabled { get; set; }
+
+ [MaxLength(20_000)] public required string CssContent { get; set; }
+}
\ No newline at end of file
diff --git a/Moonlight.Api/Database/Entities/User.cs b/Moonlight.Api/Infrastructure/Database/Entities/User.cs
similarity index 64%
rename from Moonlight.Api/Database/Entities/User.cs
rename to Moonlight.Api/Infrastructure/Database/Entities/User.cs
index 54d04f2d..fefb10e0 100644
--- a/Moonlight.Api/Database/Entities/User.cs
+++ b/Moonlight.Api/Infrastructure/Database/Entities/User.cs
@@ -1,25 +1,23 @@
using System.ComponentModel.DataAnnotations;
-using Moonlight.Api.Database.Interfaces;
+using Moonlight.Api.Infrastructure.Database.Interfaces;
-namespace Moonlight.Api.Database.Entities;
+namespace Moonlight.Api.Infrastructure.Database.Entities;
public class User : IActionTimestamps
{
public int Id { get; set; }
// Base information
- [MaxLength(50)]
- public required string Username { get; set; }
-
- [MaxLength(254)]
- public required string Email { get; set; }
+ [MaxLength(50)] public required string Username { get; set; }
+
+ [MaxLength(254)] public required string Email { get; set; }
// Authentication
public DateTimeOffset InvalidateTimestamp { get; set; }
// Relations
public List RoleMemberships { get; set; } = [];
-
+
// Action timestamps
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
diff --git a/Moonlight.Api/Database/Interfaces/IActionTimestamps.cs b/Moonlight.Api/Infrastructure/Database/Interfaces/IActionTimestamps.cs
similarity index 70%
rename from Moonlight.Api/Database/Interfaces/IActionTimestamps.cs
rename to Moonlight.Api/Infrastructure/Database/Interfaces/IActionTimestamps.cs
index 616383e1..764ed307 100644
--- a/Moonlight.Api/Database/Interfaces/IActionTimestamps.cs
+++ b/Moonlight.Api/Infrastructure/Database/Interfaces/IActionTimestamps.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Database.Interfaces;
+namespace Moonlight.Api.Infrastructure.Database.Interfaces;
internal interface IActionTimestamps
{
diff --git a/Moonlight.Api/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
similarity index 98%
rename from Moonlight.Api/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
index 0c7f92c8..59fb569b 100644
--- a/Moonlight.Api/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20251225202335_AddedUsersAndSettings.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20251225202335_AddedUsersAndSettings.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20251225202335_AddedUsersAndSettings.cs
diff --git a/Moonlight.Api/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs
index 4421d15c..c886ca64 100644
--- a/Moonlight.Api/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20251230200748_AddedRolesAndActionTimestamps.cs
diff --git a/Moonlight.Api/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
index 5a99596d..d3caa5e0 100644
--- a/Moonlight.Api/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20260116133404_AddedApiKeys.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20260116133404_AddedApiKeys.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260116133404_AddedApiKeys.cs
diff --git a/Moonlight.Api/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs
index 11979c0b..4f190d81 100644
--- a/Moonlight.Api/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260116134322_AdjustedLenghtsOfRoleAndApiKeyStrings.cs
diff --git a/Moonlight.Api/Database/Migrations/20260118005634_AddedThemes.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20260118005634_AddedThemes.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.Designer.cs
index 6b189b36..ccf5ce7f 100644
--- a/Moonlight.Api/Database/Migrations/20260118005634_AddedThemes.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20260118005634_AddedThemes.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20260118005634_AddedThemes.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260118005634_AddedThemes.cs
diff --git a/Moonlight.Api/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs
index 97ae800d..295be88b 100644
--- a/Moonlight.Api/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260129134620_SwitchedToJsonForSettingsOption.cs
diff --git a/Moonlight.Api/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs
index 03bdc39f..205335a6 100644
--- a/Moonlight.Api/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.Designer.cs
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.cs b/Moonlight.Api/Infrastructure/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.cs
similarity index 100%
rename from Moonlight.Api/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/20260209114238_AddedValidUntilToApiKeys.cs
diff --git a/Moonlight.Api/Database/Migrations/DataContextModelSnapshot.cs b/Moonlight.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs
similarity index 99%
rename from Moonlight.Api/Database/Migrations/DataContextModelSnapshot.cs
rename to Moonlight.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs
index 2945a90c..94786c5b 100644
--- a/Moonlight.Api/Database/Migrations/DataContextModelSnapshot.cs
+++ b/Moonlight.Api/Infrastructure/Database/Migrations/DataContextModelSnapshot.cs
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Moonlight.Api.Database;
+using Moonlight.Api.Infrastructure.Database;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
diff --git a/Moonlight.Api/Helpers/AppConsoleFormatter.cs b/Moonlight.Api/Infrastructure/Helpers/AppConsoleFormatter.cs
similarity index 97%
rename from Moonlight.Api/Helpers/AppConsoleFormatter.cs
rename to Moonlight.Api/Infrastructure/Helpers/AppConsoleFormatter.cs
index d5b7136a..b384e92a 100644
--- a/Moonlight.Api/Helpers/AppConsoleFormatter.cs
+++ b/Moonlight.Api/Infrastructure/Helpers/AppConsoleFormatter.cs
@@ -2,7 +2,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Console;
-namespace Moonlight.Api.Helpers;
+namespace Moonlight.Api.Infrastructure.Helpers;
public class AppConsoleFormatter : ConsoleFormatter
{
@@ -58,7 +58,9 @@ public class AppConsoleFormatter : ConsoleFormatter
textWriter.WriteLine(logEntry.Exception.ToString());
}
else
+ {
textWriter.WriteLine();
+ }
}
private static (string text, string color) GetLevelInfo(LogLevel logLevel)
diff --git a/Moonlight.Api/Interfaces/IDiagnoseProvider.cs b/Moonlight.Api/Infrastructure/Hooks/IDiagnoseProvider.cs
similarity index 51%
rename from Moonlight.Api/Interfaces/IDiagnoseProvider.cs
rename to Moonlight.Api/Infrastructure/Hooks/IDiagnoseProvider.cs
index e5d0a4a6..726e4397 100644
--- a/Moonlight.Api/Interfaces/IDiagnoseProvider.cs
+++ b/Moonlight.Api/Infrastructure/Hooks/IDiagnoseProvider.cs
@@ -1,6 +1,6 @@
-using Moonlight.Api.Models;
+using Moonlight.Api.Admin.Sys.Diagnose;
-namespace Moonlight.Api.Interfaces;
+namespace Moonlight.Api.Infrastructure.Hooks;
public interface IDiagnoseProvider
{
diff --git a/Moonlight.Api/Interfaces/IUserAuthHook.cs b/Moonlight.Api/Infrastructure/Hooks/IUserAuthHook.cs
similarity index 77%
rename from Moonlight.Api/Interfaces/IUserAuthHook.cs
rename to Moonlight.Api/Infrastructure/Hooks/IUserAuthHook.cs
index d434e16c..a71db3f8 100644
--- a/Moonlight.Api/Interfaces/IUserAuthHook.cs
+++ b/Moonlight.Api/Infrastructure/Hooks/IUserAuthHook.cs
@@ -1,12 +1,12 @@
using System.Security.Claims;
-using Moonlight.Api.Database.Entities;
+using Moonlight.Api.Infrastructure.Database.Entities;
-namespace Moonlight.Api.Interfaces;
+namespace Moonlight.Api.Infrastructure.Hooks;
public interface IUserAuthHook
{
public Task SyncAsync(ClaimsPrincipal principal, User trackedUser);
-
+
// Every implementation of this function should execute as fast as possible
// as this directly impacts every api call
public Task ValidateAsync(ClaimsPrincipal principal, int userId);
diff --git a/Moonlight.Api/Interfaces/IUserDeletionHook.cs b/Moonlight.Api/Infrastructure/Hooks/IUserDeletionHook.cs
similarity index 60%
rename from Moonlight.Api/Interfaces/IUserDeletionHook.cs
rename to Moonlight.Api/Infrastructure/Hooks/IUserDeletionHook.cs
index 15710996..842668bd 100644
--- a/Moonlight.Api/Interfaces/IUserDeletionHook.cs
+++ b/Moonlight.Api/Infrastructure/Hooks/IUserDeletionHook.cs
@@ -1,6 +1,6 @@
-using Moonlight.Api.Database.Entities;
+using Moonlight.Api.Infrastructure.Database.Entities;
-namespace Moonlight.Api.Interfaces;
+namespace Moonlight.Api.Infrastructure.Hooks;
public interface IUserDeletionHook
{
diff --git a/Moonlight.Api/Infrastructure/Hooks/IUserLogoutHook.cs b/Moonlight.Api/Infrastructure/Hooks/IUserLogoutHook.cs
new file mode 100644
index 00000000..a26ebce6
--- /dev/null
+++ b/Moonlight.Api/Infrastructure/Hooks/IUserLogoutHook.cs
@@ -0,0 +1,8 @@
+using Moonlight.Api.Infrastructure.Database.Entities;
+
+namespace Moonlight.Api.Infrastructure.Hooks;
+
+public interface IUserLogoutHook
+{
+ public Task ExecuteAsync(User user);
+}
\ No newline at end of file
diff --git a/Moonlight.Api/Implementations/PermissionAuthorizationHandler.cs b/Moonlight.Api/Infrastructure/Implementations/PermissionAuthorizationHandler.cs
similarity index 94%
rename from Moonlight.Api/Implementations/PermissionAuthorizationHandler.cs
rename to Moonlight.Api/Infrastructure/Implementations/PermissionAuthorizationHandler.cs
index dd378d57..11e98a2d 100644
--- a/Moonlight.Api/Implementations/PermissionAuthorizationHandler.cs
+++ b/Moonlight.Api/Infrastructure/Implementations/PermissionAuthorizationHandler.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Moonlight.Shared;
-namespace Moonlight.Api.Implementations;
+namespace Moonlight.Api.Infrastructure.Implementations;
public class PermissionAuthorizationHandler : AuthorizationHandler
{
diff --git a/Moonlight.Api/Implementations/PermissionPolicyProvider.cs b/Moonlight.Api/Infrastructure/Implementations/PermissionPolicyProvider.cs
similarity index 85%
rename from Moonlight.Api/Implementations/PermissionPolicyProvider.cs
rename to Moonlight.Api/Infrastructure/Implementations/PermissionPolicyProvider.cs
index 217c868e..127afba3 100644
--- a/Moonlight.Api/Implementations/PermissionPolicyProvider.cs
+++ b/Moonlight.Api/Infrastructure/Implementations/PermissionPolicyProvider.cs
@@ -2,22 +2,22 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using Moonlight.Shared;
-namespace Moonlight.Api.Implementations;
+namespace Moonlight.Api.Infrastructure.Implementations;
public class PermissionPolicyProvider : IAuthorizationPolicyProvider
{
private readonly DefaultAuthorizationPolicyProvider FallbackProvider;
-
+
public PermissionPolicyProvider(IOptions options)
{
FallbackProvider = new DefaultAuthorizationPolicyProvider(options);
}
-
+
public async Task GetPolicyAsync(string policyName)
{
if (!policyName.StartsWith(Permissions.Prefix, StringComparison.OrdinalIgnoreCase))
return await FallbackProvider.GetPolicyAsync(policyName);
-
+
var policy = new AuthorizationPolicyBuilder();
policy.AddRequirements(new PermissionRequirement(policyName));
@@ -25,18 +25,22 @@ public class PermissionPolicyProvider : IAuthorizationPolicyProvider
}
public Task GetDefaultPolicyAsync()
- => FallbackProvider.GetDefaultPolicyAsync();
+ {
+ return FallbackProvider.GetDefaultPolicyAsync();
+ }
public Task GetFallbackPolicyAsync()
- => FallbackProvider.GetFallbackPolicyAsync();
+ {
+ return FallbackProvider.GetFallbackPolicyAsync();
+ }
}
public class PermissionRequirement : IAuthorizationRequirement
{
- public string Identifier { get; }
-
public PermissionRequirement(string identifier)
{
Identifier = identifier;
}
+
+ public string Identifier { get; }
}
\ No newline at end of file
diff --git a/Moonlight.Api/Implementations/UpdateDiagnoseProvider.cs b/Moonlight.Api/Infrastructure/Implementations/UpdateDiagnoseProvider.cs
similarity index 84%
rename from Moonlight.Api/Implementations/UpdateDiagnoseProvider.cs
rename to Moonlight.Api/Infrastructure/Implementations/UpdateDiagnoseProvider.cs
index cf1b99e8..43d77632 100644
--- a/Moonlight.Api/Implementations/UpdateDiagnoseProvider.cs
+++ b/Moonlight.Api/Infrastructure/Implementations/UpdateDiagnoseProvider.cs
@@ -1,8 +1,8 @@
-using Moonlight.Api.Interfaces;
-using Moonlight.Api.Models;
-using Moonlight.Api.Services;
+using Moonlight.Api.Admin.Sys;
+using Moonlight.Api.Admin.Sys.Diagnose;
+using Moonlight.Api.Infrastructure.Hooks;
-namespace Moonlight.Api.Implementations;
+namespace Moonlight.Api.Infrastructure.Implementations;
public sealed class UpdateDiagnoseProvider : IDiagnoseProvider
{
diff --git a/Moonlight.Api/Interfaces/IUserLogoutHook.cs b/Moonlight.Api/Interfaces/IUserLogoutHook.cs
deleted file mode 100644
index 4516af69..00000000
--- a/Moonlight.Api/Interfaces/IUserLogoutHook.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using Moonlight.Api.Database.Entities;
-
-namespace Moonlight.Api.Interfaces;
-
-public interface IUserLogoutHook
-{
- public Task ExecuteAsync(User user);
-}
\ No newline at end of file
diff --git a/Moonlight.Api/Models/DiagnoseResult.cs b/Moonlight.Api/Models/DiagnoseResult.cs
deleted file mode 100644
index c968ab92..00000000
--- a/Moonlight.Api/Models/DiagnoseResult.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Moonlight.Api.Models;
-
-public record DiagnoseResult(DiagnoseLevel Level, string Title, string[] Tags, string? Message, string? StackStrace, string? SolutionUrl, string? ReportUrl);
-
-public enum DiagnoseLevel
-{
- Error = 0,
- Warning = 1,
- Healthy = 2
-}
\ No newline at end of file
diff --git a/Moonlight.Api/Moonlight.Api.csproj b/Moonlight.Api/Moonlight.Api.csproj
index eae99e8c..8ff7dd74 100644
--- a/Moonlight.Api/Moonlight.Api.csproj
+++ b/Moonlight.Api/Moonlight.Api.csproj
@@ -6,7 +6,7 @@
enableLinux
-
+
2.1.0Moonlight.Api
@@ -27,12 +27,12 @@
-
-
+
+
-
-
+
+
@@ -42,6 +42,6 @@
-
+
\ No newline at end of file
diff --git a/Moonlight.Api/MoonlightPlugin.cs b/Moonlight.Api/MoonlightPlugin.cs
index 2b5441fd..570f5146 100644
--- a/Moonlight.Api/MoonlightPlugin.cs
+++ b/Moonlight.Api/MoonlightPlugin.cs
@@ -1,6 +1,4 @@
-using System.Reflection;
-using System.Text.Json.Serialization;
-using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Builder;
using SimplePlugin.Abstractions;
namespace Moonlight.Api;
@@ -13,7 +11,7 @@ public abstract class MoonlightPlugin : IPluginModule
{
Plugins = plugins;
}
-
+
public virtual void PreBuild(WebApplicationBuilder builder)
{
}
diff --git a/Moonlight.Api/Http/Controllers/AuthController.cs b/Moonlight.Api/Shared/Auth/AuthController.cs
similarity index 89%
rename from Moonlight.Api/Http/Controllers/AuthController.cs
rename to Moonlight.Api/Shared/Auth/AuthController.cs
index 34dc18e7..931394b4 100644
--- a/Moonlight.Api/Http/Controllers/AuthController.cs
+++ b/Moonlight.Api/Shared/Auth/AuthController.cs
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Shared.Http.Responses.Admin.Auth;
+using Moonlight.Shared.Shared.Auth;
-namespace Moonlight.Api.Http.Controllers;
+namespace Moonlight.Api.Shared.Auth;
[ApiController]
[Route("api/auth")]
@@ -35,7 +35,7 @@ public class AuthController : Controller
if (scheme == null || string.IsNullOrWhiteSpace(scheme.DisplayName))
return Problem("Invalid authentication scheme name", statusCode: 400);
- return Challenge(new AuthenticationProperties()
+ return Challenge(new AuthenticationProperties
{
RedirectUri = "/"
}, scheme.Name);
@@ -56,7 +56,7 @@ public class AuthController : Controller
public Task LogoutAsync()
{
return Task.FromResult(
- SignOut(new AuthenticationProperties()
+ SignOut(new AuthenticationProperties
{
RedirectUri = "/"
})
diff --git a/Moonlight.Api/Mappers/FrontendConfigMapper.cs b/Moonlight.Api/Shared/Frontend/FrontendConfigMapper.cs
similarity index 77%
rename from Moonlight.Api/Mappers/FrontendConfigMapper.cs
rename to Moonlight.Api/Shared/Frontend/FrontendConfigMapper.cs
index e731d714..b9945b8b 100644
--- a/Moonlight.Api/Mappers/FrontendConfigMapper.cs
+++ b/Moonlight.Api/Shared/Frontend/FrontendConfigMapper.cs
@@ -1,9 +1,8 @@
using System.Diagnostics.CodeAnalysis;
-using Moonlight.Api.Models;
-using Moonlight.Shared.Http.Responses.Admin.Frontend;
+using Moonlight.Shared.Shared.Frontend;
using Riok.Mapperly.Abstractions;
-namespace Moonlight.Api.Mappers;
+namespace Moonlight.Api.Shared.Frontend;
[Mapper]
[SuppressMessage("Mapper", "RMG020:No members are mapped in an object mapping")]
diff --git a/Moonlight.Api/Models/FrontendConfiguration.cs b/Moonlight.Api/Shared/Frontend/FrontendConfiguration.cs
similarity index 62%
rename from Moonlight.Api/Models/FrontendConfiguration.cs
rename to Moonlight.Api/Shared/Frontend/FrontendConfiguration.cs
index 853bf545..9300bbba 100644
--- a/Moonlight.Api/Models/FrontendConfiguration.cs
+++ b/Moonlight.Api/Shared/Frontend/FrontendConfiguration.cs
@@ -1,3 +1,3 @@
-namespace Moonlight.Api.Models;
+namespace Moonlight.Api.Shared.Frontend;
public record FrontendConfiguration(string Name, string? ThemeCss);
\ No newline at end of file
diff --git a/Moonlight.Api/Http/Controllers/FrontendController.cs b/Moonlight.Api/Shared/Frontend/FrontendController.cs
similarity index 77%
rename from Moonlight.Api/Http/Controllers/FrontendController.cs
rename to Moonlight.Api/Shared/Frontend/FrontendController.cs
index 6fffb0aa..4f4b982a 100644
--- a/Moonlight.Api/Http/Controllers/FrontendController.cs
+++ b/Moonlight.Api/Shared/Frontend/FrontendController.cs
@@ -1,9 +1,7 @@
using Microsoft.AspNetCore.Mvc;
-using Moonlight.Api.Mappers;
-using Moonlight.Api.Services;
-using Moonlight.Shared.Http.Responses.Admin.Frontend;
+using Moonlight.Shared.Shared.Frontend;
-namespace Moonlight.Api.Http.Controllers;
+namespace Moonlight.Api.Shared.Frontend;
[ApiController]
[Route("api/frontend")]
diff --git a/Moonlight.Api/Services/FrontendService.cs b/Moonlight.Api/Shared/Frontend/FrontendService.cs
similarity index 81%
rename from Moonlight.Api/Services/FrontendService.cs
rename to Moonlight.Api/Shared/Frontend/FrontendService.cs
index f3fa3eb4..e44eeae6 100644
--- a/Moonlight.Api/Services/FrontendService.cs
+++ b/Moonlight.Api/Shared/Frontend/FrontendService.cs
@@ -1,24 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Constants;
-using Moonlight.Api.Database;
-using Moonlight.Api.Database.Entities;
-using Moonlight.Api.Models;
+using Moonlight.Api.Admin.Sys.Settings;
+using Moonlight.Api.Admin.Sys.Versions;
+using Moonlight.Api.Infrastructure.Database;
+using Moonlight.Api.Infrastructure.Database.Entities;
-namespace Moonlight.Api.Services;
+namespace Moonlight.Api.Shared.Frontend;
public class FrontendService
{
+ private const string CacheKey = $"Moonlight.{nameof(FrontendService)}.{nameof(GetConfigurationAsync)}";
private readonly IMemoryCache Cache;
- private readonly DatabaseRepository ThemeRepository;
private readonly IOptions Options;
private readonly SettingsService SettingsService;
-
- private const string CacheKey = $"Moonlight.{nameof(FrontendService)}.{nameof(GetConfigurationAsync)}";
+ private readonly DatabaseRepository ThemeRepository;
- public FrontendService(IMemoryCache cache, DatabaseRepository themeRepository, IOptions options, SettingsService settingsService)
+ public FrontendService(IMemoryCache cache, DatabaseRepository themeRepository,
+ IOptions options, SettingsService settingsService)
{
Cache = cache;
ThemeRepository = themeRepository;
@@ -29,17 +28,15 @@ public class FrontendService
public async Task GetConfigurationAsync()
{
if (Cache.TryGetValue(CacheKey, out FrontendConfiguration? value))
- {
if (value != null)
return value;
- }
var theme = await ThemeRepository
.Query()
.FirstOrDefaultAsync(x => x.IsEnabled);
var name = await SettingsService.GetValueAsync(FrontendSettingConstants.Name);
-
+
var config = new FrontendConfiguration(name ?? "Moonlight", theme?.CssContent);
Cache.Set(CacheKey, config, TimeSpan.FromMinutes(Options.Value.CacheMinutes));
diff --git a/Moonlight.Api/Constants/FrontendSettingConstants.cs b/Moonlight.Api/Shared/Frontend/FrontendSettingConstants.cs
similarity index 70%
rename from Moonlight.Api/Constants/FrontendSettingConstants.cs
rename to Moonlight.Api/Shared/Frontend/FrontendSettingConstants.cs
index 1c4e81aa..1b463306 100644
--- a/Moonlight.Api/Constants/FrontendSettingConstants.cs
+++ b/Moonlight.Api/Shared/Frontend/FrontendSettingConstants.cs
@@ -1,4 +1,4 @@
-namespace Moonlight.Api.Constants;
+namespace Moonlight.Api.Shared.Frontend;
public class FrontendSettingConstants
{
diff --git a/Moonlight.Api/Http/Controllers/PingController.cs b/Moonlight.Api/Shared/PingController.cs
similarity index 65%
rename from Moonlight.Api/Http/Controllers/PingController.cs
rename to Moonlight.Api/Shared/PingController.cs
index 8de46960..934da371 100644
--- a/Moonlight.Api/Http/Controllers/PingController.cs
+++ b/Moonlight.Api/Shared/PingController.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
-namespace Moonlight.Api.Http.Controllers;
+namespace Moonlight.Api.Shared;
[ApiController]
[Route("api/ping")]
@@ -9,5 +9,8 @@ public class PingController : Controller
{
[HttpGet]
[AllowAnonymous]
- public IActionResult Get() => Ok("Pong");
+ public IActionResult Get()
+ {
+ return Ok("Pong");
+ }
}
\ No newline at end of file
diff --git a/Moonlight.Api/Startup/Startup.Auth.cs b/Moonlight.Api/Startup/Startup.Auth.cs
index 7d404c56..14c724b4 100644
--- a/Moonlight.Api/Startup/Startup.Auth.cs
+++ b/Moonlight.Api/Startup/Startup.Auth.cs
@@ -6,10 +6,11 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Implementations;
-using Moonlight.Api.Implementations.ApiKeyScheme;
-using Moonlight.Api.Services;
+using Moonlight.Api.Admin.Sys.ApiKeys;
+using Moonlight.Api.Admin.Sys.ApiKeys.Scheme;
+using Moonlight.Api.Admin.Users.Users;
+using Moonlight.Api.Infrastructure.Configuration;
+using Moonlight.Api.Infrastructure.Implementations;
namespace Moonlight.Api.Startup;
@@ -25,7 +26,7 @@ public partial class Startup
var apiKeyOptions = new ApiOptions();
builder.Configuration.GetSection("Moonlight:Api").Bind(apiKeyOptions);
builder.Services.AddOptions().BindConfiguration("Moonlight:Api");
-
+
// Session
builder.Services.AddOptions().BindConfiguration("Moonlight:User");
@@ -67,7 +68,7 @@ public partial class Startup
context.RejectPrincipal();
};
- options.Cookie = new CookieBuilder()
+ options.Cookie = new CookieBuilder
{
Name = "token",
Path = "/",
@@ -109,7 +110,7 @@ public partial class Startup
options.LookupL1CacheTime = apiKeyOptions.LookupCacheL1Expiry;
options.LookupL2CacheTime = apiKeyOptions.LookupCacheL2Expiry;
});
-
+
// Authorization
builder.Services.AddAuthorization();
@@ -119,7 +120,7 @@ public partial class Startup
// Custom permission handling using named policies
builder.Services.AddSingleton();
builder.Services.AddSingleton();
-
+
builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped();
diff --git a/Moonlight.Api/Startup/Startup.Base.cs b/Moonlight.Api/Startup/Startup.Base.cs
index daa0c912..588b13f1 100644
--- a/Moonlight.Api/Startup/Startup.Base.cs
+++ b/Moonlight.Api/Startup/Startup.Base.cs
@@ -5,12 +5,18 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Options;
-using Moonlight.Api.Configuration;
-using Moonlight.Shared.Http;
-using Moonlight.Api.Helpers;
-using Moonlight.Api.Implementations;
-using Moonlight.Api.Interfaces;
-using Moonlight.Api.Services;
+using Moonlight.Api.Admin.Sys;
+using Moonlight.Api.Admin.Sys.ContainerHelper;
+using Moonlight.Api.Admin.Sys.Diagnose;
+using Moonlight.Api.Admin.Sys.Settings;
+using Moonlight.Api.Admin.Sys.Versions;
+using Moonlight.Api.Admin.Users.Users;
+using Moonlight.Api.Infrastructure.Helpers;
+using Moonlight.Api.Infrastructure.Hooks;
+using Moonlight.Api.Infrastructure.Implementations;
+using Moonlight.Api.Shared.Frontend;
+using SerializationContext = Moonlight.Shared.SerializationContext;
+using VersionService = Moonlight.Api.Admin.Sys.Versions.VersionService;
namespace Moonlight.Api.Startup;
diff --git a/Moonlight.Api/Startup/Startup.Cache.cs b/Moonlight.Api/Startup/Startup.Cache.cs
index 9d642ff5..90a3ab4e 100644
--- a/Moonlight.Api/Startup/Startup.Cache.cs
+++ b/Moonlight.Api/Startup/Startup.Cache.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Moonlight.Api.Configuration;
+using Moonlight.Api.Infrastructure.Configuration;
namespace Moonlight.Api.Startup;
@@ -22,9 +22,9 @@ public partial class Startup
var redisOptions = new RedisOptions();
builder.Configuration.GetSection("Moonlight:Redis").Bind(redisOptions);
- if(!redisOptions.Enable)
+ if (!redisOptions.Enable)
return;
-
+
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = redisOptions.ConnectionString;
diff --git a/Moonlight.Api/Startup/Startup.Database.cs b/Moonlight.Api/Startup/Startup.Database.cs
index 04a9c3bc..c022a4b0 100644
--- a/Moonlight.Api/Startup/Startup.Database.cs
+++ b/Moonlight.Api/Startup/Startup.Database.cs
@@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
-using Moonlight.Api.Configuration;
-using Moonlight.Api.Database;
-using Moonlight.Api.Services;
+using Moonlight.Api.Infrastructure.Database;
namespace Moonlight.Api.Startup;
diff --git a/Moonlight.Api/Startup/Startup.cs b/Moonlight.Api/Startup/Startup.cs
index 6844ebcb..a396f9db 100644
--- a/Moonlight.Api/Startup/Startup.cs
+++ b/Moonlight.Api/Startup/Startup.cs
@@ -1,7 +1,4 @@
-using System.Reflection;
-using System.Text.Json.Serialization;
-using Microsoft.AspNetCore.Builder;
-using Moonlight.Shared.Http;
+using Microsoft.AspNetCore.Builder;
using SimplePlugin.Abstractions;
namespace Moonlight.Api.Startup;
diff --git a/Moonlight.Api/StartupHandler.cs b/Moonlight.Api/StartupHandler.cs
index 3495e373..d49886f0 100644
--- a/Moonlight.Api/StartupHandler.cs
+++ b/Moonlight.Api/StartupHandler.cs
@@ -8,7 +8,7 @@ public static class StartupHandler
public static async Task RunAsync(string[] args, MoonlightPlugin[] plugins)
{
Console.WriteLine($"Starting with: {string.Join(", ", plugins.Select(x => x.GetType().FullName))}");
-
+
var builder = WebApplication.CreateBuilder(args);
// Setting up context
diff --git a/Moonlight.Frontend/UI/Shared/Components/Setup.razor b/Moonlight.Frontend/Admin/Setup/Setup.razor
similarity index 89%
rename from Moonlight.Frontend/UI/Shared/Components/Setup.razor
rename to Moonlight.Frontend/Admin/Setup/Setup.razor
index 7cb3adba..87189bf1 100644
--- a/Moonlight.Frontend/UI/Shared/Components/Setup.razor
+++ b/Moonlight.Frontend/Admin/Setup/Setup.razor
@@ -1,11 +1,10 @@
@using LucideBlazor
-@using Moonlight.Shared.Http.Requests.Seup
-@using ShadcnBlazor.Cards
-@using ShadcnBlazor.Spinners
+@using Moonlight.Shared.Admin.Setup
@using ShadcnBlazor.Buttons
+@using ShadcnBlazor.Cards
@using ShadcnBlazor.Inputs
@using ShadcnBlazor.Labels
-
+@using ShadcnBlazor.Spinners
@inject HttpClient HttpClient
@inject NavigationManager Navigation
@@ -18,13 +17,14 @@
{
-
+
Welcome to Moonlight Panel
- You successfully installed moonlight. Now you are ready to perform some initial steps to complete your installation
+ You successfully installed moonlight. Now you are ready to perform some initial steps to
+ complete your installation
}
@@ -32,17 +32,19 @@
{
-
+
-
+
Admin Account Creation
- To continue please fill in the account details of the user you want to use as the initial administrator account.
- If you use an external OIDC provider, these details need to match with your desired OIDC account
+ To continue please fill in the account details of the user you want to use as the initial
+ administrator account.
+ If you use an external OIDC provider, these details need to match with your desired OIDC
+ account