Notifications-Identifiable

This commit is contained in:
2025-07-01 22:35:44 +02:00
parent 314700aa8e
commit f1d3203ae1
5 changed files with 164 additions and 26 deletions

View File

@ -0,0 +1,88 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using API.Schema.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace API.Migrations.notifications
{
[DbContext(typeof(NotificationsContext))]
[Migration("20250701203510_Notification-Identifiable")]
partial class NotificationIdentifiable
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("API.Schema.Notification", b =>
{
b.Property<string>("Key")
.HasColumnType("text");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Message")
.IsRequired()
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<byte>("Urgency")
.HasColumnType("smallint");
b.HasKey("Key");
b.ToTable("Notifications");
});
modelBuilder.Entity("API.Schema.NotificationConnectors.NotificationConnector", b =>
{
b.Property<string>("Name")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("Body")
.IsRequired()
.HasMaxLength(4096)
.HasColumnType("character varying(4096)");
b.Property<Dictionary<string, string>>("Headers")
.IsRequired()
.HasColumnType("hstore");
b.Property<string>("HttpMethod")
.IsRequired()
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<string>("Url")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.HasKey("Name");
b.ToTable("NotificationConnectors");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace API.Migrations.notifications
{
/// <inheritdoc />
public partial class NotificationIdentifiable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Notifications",
table: "Notifications");
migrationBuilder.DropColumn(
name: "NotificationId",
table: "Notifications");
migrationBuilder.AddColumn<string>(
name: "Key",
table: "Notifications",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddPrimaryKey(
name: "PK_Notifications",
table: "Notifications",
column: "Key");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_Notifications",
table: "Notifications");
migrationBuilder.DropColumn(
name: "Key",
table: "Notifications");
migrationBuilder.AddColumn<string>(
name: "NotificationId",
table: "Notifications",
type: "character varying(64)",
maxLength: 64,
nullable: false,
defaultValue: "");
migrationBuilder.AddPrimaryKey(
name: "PK_Notifications",
table: "Notifications",
column: "NotificationId");
}
}
}

View File

@ -18,7 +18,7 @@ namespace API.Migrations.notifications
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "9.0.3") .HasAnnotation("ProductVersion", "9.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore"); NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore");
@ -26,9 +26,8 @@ namespace API.Migrations.notifications
modelBuilder.Entity("API.Schema.Notification", b => modelBuilder.Entity("API.Schema.Notification", b =>
{ {
b.Property<string>("NotificationId") b.Property<string>("Key")
.HasMaxLength(64) .HasColumnType("text");
.HasColumnType("character varying(64)");
b.Property<DateTime>("Date") b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
@ -46,7 +45,7 @@ namespace API.Migrations.notifications
b.Property<byte>("Urgency") b.Property<byte>("Urgency")
.HasColumnType("smallint"); .HasColumnType("smallint");
b.HasKey("NotificationId"); b.HasKey("Key");
b.ToTable("Notifications"); b.ToTable("Notifications");
}); });

View File

@ -3,13 +3,9 @@ using Microsoft.EntityFrameworkCore;
namespace API.Schema; namespace API.Schema;
[PrimaryKey("NotificationId")] [PrimaryKey(nameof(Key))]
public class Notification public class Notification : Identifiable
{ {
[StringLength(64)]
[Required]
public string NotificationId { get; init; }
[Required] [Required]
public NotificationUrgency Urgency { get; init; } public NotificationUrgency Urgency { get; init; }
@ -25,8 +21,8 @@ public class Notification
public DateTime Date { get; init; } public DateTime Date { get; init; }
public Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null) public Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null)
: base(TokenGen.CreateToken("Notification"))
{ {
this.NotificationId = TokenGen.CreateToken("Notification");
this.Title = title; this.Title = title;
this.Message = message; this.Message = message;
this.Urgency = urgency; this.Urgency = urgency;
@ -36,17 +32,21 @@ public class Notification
/// <summary> /// <summary>
/// EF ONLY!!! /// EF ONLY!!!
/// </summary> /// </summary>
public Notification(string notificationId, string title, string message, NotificationUrgency urgency, DateTime date) public Notification(string key, string title, string message, NotificationUrgency urgency, DateTime date)
: base(key)
{ {
this.NotificationId = notificationId;
this.Title = title; this.Title = title;
this.Message = message; this.Message = message;
this.Urgency = urgency; this.Urgency = urgency;
this.Date = date; this.Date = date;
} }
public override string ToString() public override string ToString() => $"{base.ToString()} {Urgency} {Title}";
{ }
return $"{NotificationId} {Urgency} {Title}";
} public enum NotificationUrgency : byte
{
Low = 1,
Normal = 3,
High = 5
} }

View File

@ -1,8 +0,0 @@
namespace API.Schema;
public enum NotificationUrgency : byte
{
Low = 1,
Normal = 3,
High = 5
}