feat: add trial mode configuration

This commit is contained in:
CyberL1 2024-04-14 08:47:22 +02:00
parent 08b698f099
commit f1cc6cc128
8 changed files with 376 additions and 17 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Data;
namespace Minecraft_Realms_Emulator.Controllers
{
@ -6,9 +7,16 @@ namespace Minecraft_Realms_Emulator.Controllers
[ApiController]
public class TrialController : ControllerBase
{
private readonly DataContext _context;
public TrialController(DataContext context)
{
_context = context;
}
[HttpGet(Name = "GetTrial")]
public bool Get() {
return true;
return bool.Parse(_context.Configuration.FirstOrDefault(x => x.Key == "trialMode").Value);
}
}
}

View File

@ -2,8 +2,6 @@
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
namespace Minecraft_Realms_Emulator.Controllers
{

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Minecraft_Realms_Emulator.Entities
{
@ -6,6 +7,7 @@ namespace Minecraft_Realms_Emulator.Entities
public class Configuration
{
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
[Column(TypeName = "jsonb")]
public dynamic Value { get; set; } = string.Empty;
}
}

View File

@ -18,7 +18,7 @@ namespace Minecraft_Realms_Emulator.Helpers
var newsLink = new Configuration
{
Key = "newsLink",
Value = "https://github.com/CyberL1/Minecraft-Realms-Emulator"
Value = "\"https://github.com/CyberL1/Minecraft-Realms-Emulator\""
};
db.Configuration.Add(newsLink);
@ -29,12 +29,23 @@ namespace Minecraft_Realms_Emulator.Helpers
var defaultServerAddress = new Configuration
{
Key = "defaultServerAddress",
Value = "127.0.0.1"
Value = "\"127.0.0.1\""
};
db.Configuration.Add(defaultServerAddress);
}
if (db.Configuration.FirstOrDefault(x => x.Key == "trialMode") == null)
{
var trialMode = new Configuration
{
Key = "trialMode",
Value = true
};
db.Configuration.Add(trialMode);
}
db.SaveChanges();
}
}

View File

@ -0,0 +1,313 @@
// <auto-generated />
using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Minecraft_Realms_Emulator.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20240414062222_Configuration_Json")]
partial class Configuration_Json
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("BackupId")
.IsRequired()
.HasColumnType("text");
b.Property<long>("LastModifiedDate")
.HasColumnType("bigint");
b.Property<JsonDocument>("Metadata")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("Size")
.HasColumnType("integer");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<object>("Value")
.IsRequired()
.HasColumnType("jsonb");
b.HasKey("Key");
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("InvitationId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecipeintUUID")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("Accepted")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("Online")
.HasColumnType("boolean");
b.Property<bool>("Operator")
.HasColumnType("boolean");
b.Property<string>("Permission")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Uuid")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId")
.IsUnique();
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ActiveSlot")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<bool>("Member")
.HasColumnType("boolean");
b.Property<int?>("MinigameId")
.HasColumnType("integer");
b.Property<string>("MinigameImage")
.HasColumnType("text");
b.Property<string>("MinigameName")
.HasColumnType("text");
b.Property<string>("Motd")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("OwnerUUID")
.HasColumnType("text");
b.Property<JsonDocument[]>("Slots")
.IsRequired()
.HasColumnType("jsonb[]");
b.Property<string>("State")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WorldType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Worlds");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany()
.HasForeignKey("WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany()
.HasForeignKey("WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany()
.HasForeignKey("WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany("Players")
.HasForeignKey("WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithOne("Subscription")
.HasForeignKey("Minecraft_Realms_Emulator.Entities.Subscription", "WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
{
b.Navigation("Players");
b.Navigation("Subscription");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Configuration_Json : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE jsonb USING \"Value\"::jsonb");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("ALTER TABLE \"Configuration\" ALTER COLUMN \"Value\" TYPE text USING \"Value\"::text");
}
}
}

View File

@ -52,7 +52,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasIndex("WorldId");
b.ToTable("Backups", (string)null);
b.ToTable("Backups");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Configuration", b =>
@ -60,13 +60,13 @@ namespace Minecraft_Realms_Emulator.Migrations
b.Property<string>("Key")
.HasColumnType("text");
b.Property<string>("Value")
b.Property<object>("Value")
.IsRequired()
.HasColumnType("text");
.HasColumnType("jsonb");
b.HasKey("Key");
b.ToTable("Configuration", (string)null);
b.ToTable("Configuration");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
@ -91,7 +91,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasIndex("WorldId");
b.ToTable("Connections", (string)null);
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Invite", b =>
@ -120,7 +120,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasIndex("WorldId");
b.ToTable("Invites", (string)null);
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
@ -159,7 +159,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasIndex("WorldId");
b.ToTable("Players", (string)null);
b.ToTable("Players");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
@ -185,7 +185,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasIndex("WorldId")
.IsUnique();
b.ToTable("Subscriptions", (string)null);
b.ToTable("Subscriptions");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.World", b =>
@ -240,7 +240,7 @@ namespace Minecraft_Realms_Emulator.Migrations
b.HasKey("Id");
b.ToTable("Worlds", (string)null);
b.ToTable("Worlds");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Backup", b =>

View File

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Helpers;
using Npgsql;
var builder = WebApplication.CreateBuilder(args);
DotNetEnv.Env.Load();
@ -18,9 +19,13 @@ builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.Re
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var dataSourceBuilder = new NpgsqlDataSourceBuilder(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
dataSourceBuilder.EnableDynamicJson();
await using var dataSource = dataSourceBuilder.Build();
builder.Services.AddDbContext<DataContext>(options =>
{
options.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
options.UseNpgsql(dataSource);
});
var app = builder.Build();