Add version field to star entity. Implemented a lot of the star crud

This commit is contained in:
2024-12-06 15:03:28 +01:00
parent 1520d0b2b1
commit de1b54d652
27 changed files with 1448 additions and 194 deletions

View File

@@ -0,0 +1,7 @@
namespace MoonlightServers.Shared.Enums;
public enum FileParsers
{
File = 0,
Properties = 1
}

View File

@@ -1,10 +1,9 @@
using System.ComponentModel.DataAnnotations;
using MoonlightServers.Shared.Enums;
using MoonlightServers.Shared.Interfaces;
namespace MoonlightServers.Shared.Http.Requests.Admin.StarVariables;
public class CreateStarVariableRequest : IStarVariable
public class CreateStarVariableRequest
{
[Required(ErrorMessage = "You need to specify a variable name")]
public string Name { get; set; }

View File

@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.Shared.Http.Requests.Admin.StarVariables;
public class UpdateStarVariableRequest
{
[Required(ErrorMessage = "You need to specify a variable name")]
public string Name { get; set; }
[Required(ErrorMessage = "You need to specify a variable description", AllowEmptyStrings = true)]
public string Description { get; set; } = "";
[Required(ErrorMessage = "You need to specify a variable key")]
public string Key { get; set; }
[Required(ErrorMessage = "You need to specify a variable default value", AllowEmptyStrings = true)]
public string DefaultValue { get; set; } = "";
public bool AllowViewing { get; set; }
public bool AllowEditing { get; set; }
public StarVariableType Type { get; set; } = StarVariableType.Text;
public string? Filter { get; set; } = null;
}

View File

@@ -10,39 +10,4 @@ public class CreateStarRequest
[Required(ErrorMessage = "You need to specify a author")]
public string Author { get; set; }
public string? UpdateUrl { get; set; }
public string? DonateUrl { get; set; }
[Required(ErrorMessage = "You need to specify a startup command")]
public string StartupCommand { get; set; } = "echo Starting up :)";
[Required(ErrorMessage = "You need to specify a stop command")]
public string StopCommand { get; set; } = "^C";
[Required(ErrorMessage = "You need to specify a online detection string")]
public string OnlineDetection { get; set; }
[Required(ErrorMessage = "You need to specify an install shell")]
public string InstallShell { get; set; } = "/bin/bash";
[Required(ErrorMessage = "You need to specify an install docker image")]
[RegularExpression("^(?:(?=[^:\\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\\/)?((?![._-])(?:[a-z0-9._-]*)(?<![._-])(?:\\/(?![._-])[a-z0-9._-]*(?<![._-]))*)(?::(?![.-])[a-zA-Z0-9_.-]{1,128})?$", ErrorMessage = "You need to specify a valid docker image")]
public string InstallDockerImage { get; set; } = "debian:latest";
[Required(ErrorMessage = "You need to specify an install script")]
public string InstallScript { get; set; } = "echo Installing...";
[Range(0, 20, ErrorMessage = "You need to provide a valid amount of allocations")]
public int RequiredAllocations { get; set; } = 1;
public bool AllowDockerImageChange { get; set; } = false;
[Required(ErrorMessage = "You need to provide parse configuration")]
public string ParseConfiguration { get; set; } = "[]";
public List<CreateStarVariableRequest> Variables { get; set; } = new();
}

View File

@@ -1,6 +1,48 @@
using System.ComponentModel.DataAnnotations;
namespace MoonlightServers.Shared.Http.Requests.Admin.Stars;
public class UpdateStarRequest
{
[Required(ErrorMessage = "You need to specify a name")]
public string Name { get; set; }
[Required(ErrorMessage = "You need to specify a version")]
public string Version { get; set; }
[Required(ErrorMessage = "You need to specify a author")]
public string Author { get; set; }
public string? UpdateUrl { get; set; }
public string? DonateUrl { get; set; }
[Required(ErrorMessage = "You need to specify a startup command")]
public string StartupCommand { get; set; }
[Required(ErrorMessage = "You need to specify a stop command")]
public string StopCommand { get; set; }
[Required(ErrorMessage = "You need to specify a online detection string")]
public string OnlineDetection { get; set; }
[Required(ErrorMessage = "You need to specify an install shell")]
public string InstallShell { get; set; }
[Required(ErrorMessage = "You need to specify an install docker image")]
[RegularExpression("^(?:(?=[^:\\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\\/)?((?![._-])(?:[a-z0-9._-]*)(?<![._-])(?:\\/(?![._-])[a-z0-9._-]*(?<![._-]))*)(?::(?![.-])[a-zA-Z0-9_.-]{1,128})?$", ErrorMessage = "You need to specify a valid docker image")]
public string InstallDockerImage { get; set; }
[Required(ErrorMessage = "You need to specify an install script")]
public string InstallScript { get; set; }
[Range(0, 20, ErrorMessage = "You need to provide a valid amount of allocations")]
public int RequiredAllocations { get; set; }
public bool AllowDockerImageChange { get; set; }
[Required(ErrorMessage = "You need to provide parse configuration")]
public string ParseConfiguration { get; set; }
}

View File

@@ -13,6 +13,7 @@ public class StarDetailResponse
// Meta
public string Name { get; set; }
public string Version { get; set; }
public string Author { get; set; }
public string? UpdateUrl { get; set; }
public string? DonateUrl { get; set; }

View File

@@ -1,20 +0,0 @@
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.Shared.Interfaces;
public interface IStarVariable // For a common abstraction between create and update model to use in a shared form component
{
public string Name { get; set; }
public string Description { get; set; }
public string Key { get; set; }
public string DefaultValue { get; set; }
public bool AllowViewing { get; set; }
public bool AllowEditing { get; set; }
public StarVariableType Type { get; set; }
public string? Filter { get; set; }
}

View File

@@ -0,0 +1,17 @@
using MoonlightServers.Shared.Enums;
namespace MoonlightServers.Shared.Models;
public class ParseConfiguration
{
public string File { get; set; }
public FileParsers Parser { get; set; }
public List<ParseConfigurationEntry> Entries { get; set; } = new();
public class ParseConfigurationEntry
{
public string Key { get; set; }
public string Value { get; set; }
}
}