feat: world joining

This commit is contained in:
CyberL1 2024-02-13 11:54:29 +01:00
parent bc86311a09
commit 5dd9a261fe
6 changed files with 270 additions and 0 deletions

View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Controllers
{
[Route("worlds/v1/{worldId}/join/pc")]
[ApiController]
public class JoinController : ControllerBase
{
private readonly DataContext _context;
public JoinController(DataContext context)
{
_context = context;
}
[HttpGet()]
public ActionResult<Connection> Join(int worldId)
{
var connection = _context.Connections.FirstOrDefault(x => x.World.Id == worldId);
return Ok(connection);
}
}
}

View File

@ -7,5 +7,6 @@ namespace Minecraft_Realms_Emulator.Data
{ {
public DbSet<World> Worlds { get; set; } public DbSet<World> Worlds { get; set; }
public DbSet<Subscription> Subscriptions { get; set; } public DbSet<Subscription> Subscriptions { get; set; }
public DbSet<Connection> Connections { get; set; }
} }
} }

View File

@ -0,0 +1,12 @@
using Microsoft.EntityFrameworkCore;
namespace Minecraft_Realms_Emulator.Entities
{
[Keyless]
public class Connection
{
public World World { get; set; }
public string Address { get; set; } = string.Empty;
public bool PendingUpdate { get; set; }
}
}

View File

@ -0,0 +1,159 @@
// <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("20240213104200_Connections")]
partial class Connections
{
/// <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.Connection", b =>
{
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("DaysLeft")
.HasColumnType("integer");
b.Property<string>("RemoteId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartDate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SubscriptionType")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
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>("DaysLeft")
.HasColumnType("integer");
b.Property<bool>("Expired")
.HasColumnType("boolean");
b.Property<bool>("ExpiredTrial")
.HasColumnType("boolean");
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<string[]>("Players")
.IsRequired()
.HasColumnType("text[]");
b.Property<string>("RemoteSubscriptionId")
.IsRequired()
.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.Connection", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany()
.HasForeignKey("WorldId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("World");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Connections : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Connections",
columns: table => new
{
WorldId = table.Column<int>(type: "integer", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
PendingUpdate = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.ForeignKey(
name: "FK_Connections_Worlds_WorldId",
column: x => x.WorldId,
principalTable: "Worlds",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Connections_WorldId",
table: "Connections",
column: "WorldId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Connections");
}
}
}

View File

@ -23,6 +23,23 @@ namespace Minecraft_Realms_Emulator.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Connection", b =>
{
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("PendingUpdate")
.HasColumnType("boolean");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasIndex("WorldId");
b.ToTable("Connections");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b => modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Subscription", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -122,6 +139,17 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Worlds"); b.ToTable("Worlds");
}); });
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");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }