diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs new file mode 100644 index 0000000..6230876 --- /dev/null +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodeAllocationsController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using MoonCore.Extended.Abstractions; +using Moonlight.ApiServer.App.Helpers; +using MoonlightServers.ApiServer.Database.Entities; +using MoonlightServers.Shared.Http.Requests.Admin.Allocations; +using MoonlightServers.Shared.Http.Responses.Admin.Allocations; + +namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes; + +[ApiController] +[Route("admin/servers/nodes/{rootItem:int}/allocations")] +public class NodeAllocationsController : BaseSubCrudController +{ + public override Func> Property => node => node.Allocations; + + public NodeAllocationsController(DatabaseRepository itemRepository, DatabaseRepository rootItemRepository, IHttpContextAccessor contextAccessor) : base(itemRepository, rootItemRepository, contextAccessor) + { + PermissionPrefix = "admin.servers.nodes.allocations"; + } + + protected override IEnumerable IncludeRelations(IQueryable items) + => items.Include(x => x.Allocations); +} \ No newline at end of file diff --git a/MoonlightServers.ApiServer/Http/Controllers/Admin/NodesController.cs b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs similarity index 96% rename from MoonlightServers.ApiServer/Http/Controllers/Admin/NodesController.cs rename to MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs index 68bb362..3c68529 100644 --- a/MoonlightServers.ApiServer/Http/Controllers/Admin/NodesController.cs +++ b/MoonlightServers.ApiServer/Http/Controllers/Admin/Nodes/NodesController.cs @@ -9,7 +9,7 @@ using MoonlightServers.ApiServer.Database.Entities; using MoonlightServers.Shared.Http.Requests.Admin.Nodes; using MoonlightServers.Shared.Http.Responses.Admin.Nodes; -namespace MoonlightServers.ApiServer.Http.Controllers.Admin; +namespace MoonlightServers.ApiServer.Http.Controllers.Admin.Nodes; [ApiController] [Route("admin/servers/nodes")] @@ -78,7 +78,4 @@ public class NodesController : BaseCrudControllerAllocation editor \ No newline at end of file +@using Moonlight.Client.App.Models.Crud +@using Moonlight.Shared.Http.Resources +@using MoonlightServers.Shared.Http.Requests.Admin.Allocations +@using MoonlightServers.Shared.Http.Responses.Admin.Allocations + +@inject HttpApiClient HttpApiClient + +
+ + + + + + + +
+ +@code +{ + [Parameter] + public int NodeId { get; set; } + + private void OnConfigure(CrudOptions options) + { + options.Loader = async (page, pageSize) + => await HttpApiClient.GetJson>($"admin/servers/nodes/{NodeId}/allocations"); + + options.CreateFunction = async request => await HttpApiClient.Post($"admin/servers/nodes/{NodeId}/allocations", request); + options.UpdateFunction = async (request, item) => await HttpApiClient.Patch($"admin/servers/nodes/{NodeId}/allocations/{item.Id}", request); + options.DeleteFunction = async item => await HttpApiClient.Delete($"admin/servers/nodes/{NodeId}/allocations/{item.Id}"); + + options.OnConfigureCreate = option => + { + option + .DefaultPage + .DefaultSection + .AddProperty(x => x.IpAddress) + .WithColumns(6); + + option + .DefaultPage + .DefaultSection + .AddProperty(x => x.Port) + .WithColumns(6); + }; + + options.OnConfigureUpdate = (option, item) => + { + option + .DefaultPage + .DefaultSection + .AddProperty(x => x.IpAddress) + .WithColumns(6); + + option + .DefaultPage + .DefaultSection + .AddProperty(x => x.Port) + .WithColumns(6); + }; + } +} diff --git a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor index 506d87b..b401824 100644 --- a/MoonlightServers.Client/UI/Views/Admin/Nodes.razor +++ b/MoonlightServers.Client/UI/Views/Admin/Nodes.razor @@ -17,11 +17,25 @@ TCreateForm="CreateNodeRequest" TUpdateForm="UpdateNodeRequest" OnConfigure="OnConfigure"> - + - + + + + + + +

Overview owo

+
+ + + +
+
@@ -38,6 +52,7 @@ options.ShowCreateAsModal = false; options.ShowUpdateAsModal = false; + options.ShowDetailsAsModal = false; options.OnConfigureCreate = option => { @@ -83,11 +98,6 @@ .DefaultPage .DefaultSection .AddProperty(x => x.SslEnabled); - - option - .WithPage("Allocations") - .DefaultSection - .AddComponent(); }; } } diff --git a/MoonlightServers.Shared/Http/Requests/Admin/Allocations/CreateAllocationRequest.cs b/MoonlightServers.Shared/Http/Requests/Admin/Allocations/CreateAllocationRequest.cs new file mode 100644 index 0000000..07ae9f0 --- /dev/null +++ b/MoonlightServers.Shared/Http/Requests/Admin/Allocations/CreateAllocationRequest.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace MoonlightServers.Shared.Http.Requests.Admin.Allocations; + +public class CreateAllocationRequest +{ + [Required(ErrorMessage = "You need to provide an ip address")] + [RegularExpression("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$", ErrorMessage = "You need tp provide a valid ip address")] + public string IpAddress { get; set; } = "0.0.0.0"; + + [Required(ErrorMessage = "You need to provgide a port")] + [Range(1, 65535 , ErrorMessage = "You need to provide a valid port")] + public int Port { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.Shared/Http/Requests/Admin/Allocations/UpdateAllocationRequest.cs b/MoonlightServers.Shared/Http/Requests/Admin/Allocations/UpdateAllocationRequest.cs new file mode 100644 index 0000000..ba97213 --- /dev/null +++ b/MoonlightServers.Shared/Http/Requests/Admin/Allocations/UpdateAllocationRequest.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace MoonlightServers.Shared.Http.Requests.Admin.Allocations; + +public class UpdateAllocationRequest +{ + [Required(ErrorMessage = "You need to provide an ip address")] + [RegularExpression("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$", ErrorMessage = "You need tp provide a valid ip address")] + public string IpAddress { get; set; } = "0.0.0.0"; + + [Required(ErrorMessage = "You need to provgide a port")] + [Range(1, 65535 , ErrorMessage = "You need to provide a valid port")] + public int Port { get; set; } +} \ No newline at end of file diff --git a/MoonlightServers.Shared/Http/Responses/Admin/Allocations/DetailAllocationResponse.cs b/MoonlightServers.Shared/Http/Responses/Admin/Allocations/DetailAllocationResponse.cs new file mode 100644 index 0000000..c8c60be --- /dev/null +++ b/MoonlightServers.Shared/Http/Responses/Admin/Allocations/DetailAllocationResponse.cs @@ -0,0 +1,8 @@ +namespace MoonlightServers.Shared.Http.Responses.Admin.Allocations; + +public class DetailAllocationResponse +{ + public int Id { get; set; } + public string IpAddress { get; set; } = "0.0.0.0"; + public int Port { get; set; } +} \ No newline at end of file