Added database stuff for plesk servers

This commit is contained in:
Marcel Baumgartner
2023-03-22 10:13:32 +01:00
parent 49bf26350e
commit 98dc0589d3
7 changed files with 1197 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ public class DataContext : DbContext
public DbSet<AaPanel> AaPanels { get; set; } public DbSet<AaPanel> AaPanels { get; set; }
public DbSet<Website> Websites { get; set; } public DbSet<Website> Websites { get; set; }
public DbSet<DdosAttack> DdosAttacks { get; set; } public DbSet<DdosAttack> DdosAttacks { get; set; }
public DbSet<PleskServer> PleskServers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {

View File

@@ -0,0 +1,8 @@
namespace Moonlight.App.Database.Entities;
public class PleskServer
{
public int Id { get; set; }
public string BaseUrl { get; set; } = "";
public string ApiKey { get; set; } = "";
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Moonlight.App.Database.Migrations
{
/// <inheritdoc />
public partial class AddedPleskServer : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PleskServers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
BaseUrl = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ApiKey = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_PleskServers", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PleskServers");
}
}
}

View File

@@ -446,6 +446,25 @@ namespace Moonlight.App.Database.Migrations
b.ToTable("NotificationClients"); b.ToTable("NotificationClients");
}); });
modelBuilder.Entity("Moonlight.App.Database.Entities.PleskServer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("ApiKey")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("BaseUrl")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("PleskServers");
});
modelBuilder.Entity("Moonlight.App.Database.Entities.Revoke", b => modelBuilder.Entity("Moonlight.App.Database.Entities.Revoke", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")

View File

@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database;
using Moonlight.App.Database.Entities;
namespace Moonlight.App.Repositories;
public class PleskServerRepository : IDisposable
{
private readonly DataContext DataContext;
public PleskServerRepository(DataContext dataContext)
{
DataContext = dataContext;
}
public DbSet<PleskServer> Get()
{
return DataContext.PleskServers;
}
public PleskServer Add(PleskServer pleskServer)
{
var x = DataContext.PleskServers.Add(pleskServer);
DataContext.SaveChanges();
return x.Entity;
}
public void Update(PleskServer pleskServer)
{
DataContext.PleskServers.Update(pleskServer);
DataContext.SaveChanges();
}
public void Delete(PleskServer pleskServer)
{
DataContext.PleskServers.Remove(pleskServer);
DataContext.SaveChanges();
}
public void Dispose()
{
DataContext.Dispose();
}
}

View File

@@ -65,6 +65,7 @@ namespace Moonlight
builder.Services.AddScoped<AaPanelRepository>(); builder.Services.AddScoped<AaPanelRepository>();
builder.Services.AddScoped<WebsiteRepository>(); builder.Services.AddScoped<WebsiteRepository>();
builder.Services.AddScoped<DdosAttackRepository>(); builder.Services.AddScoped<DdosAttackRepository>();
builder.Services.AddScoped<PleskServerRepository>();
builder.Services.AddScoped<AuditLogEntryRepository>(); builder.Services.AddScoped<AuditLogEntryRepository>();
builder.Services.AddScoped<ErrorLogEntryRepository>(); builder.Services.AddScoped<ErrorLogEntryRepository>();