feat: notifications

This commit is contained in:
CyberL1 2024-06-11 22:41:05 +02:00
parent ece3d3825f
commit afb6a4730c
8 changed files with 689 additions and 0 deletions

View File

@ -14,5 +14,6 @@ namespace Minecraft_Realms_Emulator.Data
public DbSet<Configuration> Configuration { get; set; }
public DbSet<Slot> Slots { get; set; }
public DbSet<Template> Templates { get; set; }
public DbSet<Notification> Notifications { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System.Text.Json;
namespace Minecraft_Realms_Emulator.Entities
{
public class Notification
{
public int Id { get; set; }
public string NotificationUuid { get; set; } = null!;
public bool Dismissable { get; set; }
public string Type { get; set; } = null!;
public JsonDocument? Title { get; set; } = null!;
public JsonDocument Message { get; set; } = null!;
public string? Image { get; set; } = null!;
public JsonDocument? UrlButton { get; set; } = null!;
public string? Url { get; set; } = null!;
public JsonDocument? ButtonText { get; set; } = null!;
}
}

View File

@ -0,0 +1,465 @@
// <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("20240611201421_Notifications")]
partial class Notifications
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.5")
.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.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
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.Slot", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<bool>("CommandBlocks")
.HasColumnType("boolean");
b.Property<int>("Difficulty")
.HasColumnType("integer");
b.Property<bool>("ForceGameMode")
.HasColumnType("boolean");
b.Property<int>("GameMode")
.HasColumnType("integer");
b.Property<bool>("Pvp")
.HasColumnType("boolean");
b.Property<int>("SlotId")
.HasColumnType("integer");
b.Property<string>("SlotName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("SpawnAnimals")
.HasColumnType("boolean");
b.Property<bool>("SpawnMonsters")
.HasColumnType("boolean");
b.Property<bool>("SpawnNPCs")
.HasColumnType("boolean");
b.Property<int>("SpawnProtection")
.HasColumnType("integer");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorldId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("WorldId");
b.ToTable("Slots");
});
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.Template", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<string>("Link")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RecommendedPlayers")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Trailer")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Version")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Templates");
});
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<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.Slot", b =>
{
b.HasOne("Minecraft_Realms_Emulator.Entities.World", "World")
.WithMany("Slots")
.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("Slots");
b.Navigation("Subscription");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,44 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Minecraft_Realms_Emulator.Migrations
{
/// <inheritdoc />
public partial class Notifications : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Notifications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NotificationUuid = table.Column<string>(type: "text", nullable: false),
Dismissable = table.Column<bool>(type: "boolean", nullable: false),
Type = table.Column<string>(type: "text", nullable: false),
Title = table.Column<JsonDocument>(type: "jsonb", nullable: true),
Message = table.Column<JsonDocument>(type: "jsonb", nullable: false),
Image = table.Column<string>(type: "text", nullable: true),
UrlButton = table.Column<JsonDocument>(type: "jsonb", nullable: true),
Url = table.Column<string>(type: "text", nullable: true),
ButtonText = table.Column<JsonDocument>(type: "jsonb", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Notifications", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Notifications");
}
}
}

View File

@ -123,6 +123,49 @@ namespace Minecraft_Realms_Emulator.Migrations
b.ToTable("Invites");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Notification", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<JsonDocument>("ButtonText")
.HasColumnType("jsonb");
b.Property<bool>("Dismissable")
.HasColumnType("boolean");
b.Property<string>("Image")
.HasColumnType("text");
b.Property<JsonDocument>("Message")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("NotificationUuid")
.IsRequired()
.HasColumnType("text");
b.Property<JsonDocument>("Title")
.HasColumnType("jsonb");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Url")
.HasColumnType("text");
b.Property<JsonDocument>("UrlButton")
.HasColumnType("jsonb");
b.HasKey("Id");
b.ToTable("Notifications");
});
modelBuilder.Entity("Minecraft_Realms_Emulator.Entities.Player", b =>
{
b.Property<int>("Id")

View File

@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Modes.External
{
[Route("/modes/external/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class NotificationsController : ControllerBase
{
private readonly DataContext _context;
public NotificationsController(DataContext context)
{
_context = context;
}
[HttpGet]
public ActionResult<NotificationsResponse> GetNotifications()
{
List<NotificationResponse> notifications = [];
foreach (var notification in _context.Notifications)
{
NotificationResponse notificationResponse = new()
{
NotificationUuid = notification.NotificationUuid,
Dismissable = notification.Dismissable,
Seen = false,
Type = notification.Type,
Title = notification.Title,
Message = notification.Message,
Image = notification.Image,
UrlButton = notification.UrlButton,
Url = notification.Url,
ButtonText = notification.ButtonText,
};
notifications.Add(notificationResponse);
}
NotificationsResponse notificationsResponse = new()
{
Notifications = notifications,
};
return Ok(notificationsResponse);
}
}
}

View File

@ -0,0 +1,52 @@
using Microsoft.AspNetCore.Mvc;
using Minecraft_Realms_Emulator.Attributes;
using Minecraft_Realms_Emulator.Data;
using Minecraft_Realms_Emulator.Responses;
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
[Route("/modes/realms/[controller]")]
[ApiController]
[RequireMinecraftCookie]
public class NotificationsController : ControllerBase
{
private readonly DataContext _context;
public NotificationsController(DataContext context)
{
_context = context;
}
[HttpGet]
public ActionResult<NotificationsResponse> GetNotifications()
{
List<NotificationResponse> notifications = [];
foreach (var notification in _context.Notifications)
{
NotificationResponse notificationResponse = new()
{
NotificationUuid = notification.NotificationUuid,
Dismissable = notification.Dismissable,
Seen = false,
Type = notification.Type,
Title = notification.Title,
Message = notification.Message,
Image = notification.Image,
UrlButton = notification.UrlButton,
Url = notification.Url,
ButtonText = notification.ButtonText,
};
notifications.Add(notificationResponse);
}
NotificationsResponse notificationsResponse = new()
{
Notifications = notifications,
};
return Ok(notificationsResponse);
}
}
}

View File

@ -0,0 +1,14 @@
using Minecraft_Realms_Emulator.Entities;
namespace Minecraft_Realms_Emulator.Responses
{
public class NotificationsResponse
{
public List<NotificationResponse> Notifications { get; set; } = null!;
}
public class NotificationResponse : Notification
{
public bool Seen { get; set; }
}
}