GuestLog - Added GuestDocument db table.

This commit is contained in:
2026-06-18 21:23:38 +02:00
parent 26f77bb8fd
commit 86fadf97b4
13 changed files with 502 additions and 2 deletions
@@ -14,7 +14,7 @@
<MudAppBar Elevation="1" Style="opacity: 100%;">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start"
OnClick="@((e) => DrawerToggle())" />
<MudText Typo="Typo.h5" Class="ml-3">Somnia GuestLog</MudText>
<MudText Typo="Typo.h5" Class="ml-3">Somnia.GuestLog</MudText>
<MudSpacer />
<MudToggleIconButton Class="ml-auto" Icon="@Icons.Material.Outlined.LightMode"
ToggledIcon="@Icons.Material.Outlined.DarkMode" ToggledColor="Color.Primary" Color="Color.Primary"
+6
View File
@@ -0,0 +1,6 @@
namespace Somnia.GuestLog;
public static class GuestConsts
{
}
@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Somnia.GuestLog.Models;
namespace Somnia.GuestLog.Infrastructure.EntityConfigs;
public class GuestAddressEntityConfig : IEntityTypeConfiguration<GuestAddress>
{
public void Configure(EntityTypeBuilder<GuestAddress> builder)
{
builder.HasNoKey();
builder.Property(e => e.Address)
.HasMaxLength(128);
builder.Property(e => e.AddressCity)
.HasMaxLength(128);
builder.Property(e => e.AddressProvince)
.HasMaxLength(128);
builder.Property(e => e.AddressState)
.HasMaxLength(128);
//3 letter code: ISO 3166-1 Alfa-3
builder.Property(e => e.AddressCountry)
.IsRequired()
.HasMaxLength(3);
builder.Property(e => e.ZipCode)
.HasMaxLength(3);
}
}
@@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Somnia.GuestLog.Models;
namespace Somnia.GuestLog.Infrastructure.EntityConfigs;
public class GuestDocumentEntityConfig : IEntityTypeConfiguration<GuestDocument>
{
public void Configure(EntityTypeBuilder<GuestDocument> builder)
{
builder.ToTable("GuestDocument");
//PK
builder.HasKey(e => new { e.DocumentType, e.DocumentNum });
builder.Property(e => e.DocumentType)
.IsRequired()
.HasMaxLength(8);
builder.Property(e => e.DocumentNum)
.IsRequired()
.HasMaxLength(64);
// builder.Property(e => e.IssueDate);
builder.Property(e => e.SupportNum)
.HasMaxLength(10);
//3 letter code: ISO 3166-1 Alfa-3
builder.Property(e => e.Nationality)
.HasMaxLength(3);
builder.Property(e => e.Name)
.IsRequired()
.HasMaxLength(64);
builder.Property(e => e.Surname)
.IsRequired()
.HasMaxLength(64);
builder.Property(e => e.Surname2)
.HasMaxLength(64);
// builder.Property(e => e.BirthDate);
builder.Property(e => e.Gender)
.HasMaxLength(1);
builder.Property(e => e.PhoneNumber)
.HasMaxLength(32);
builder.Property(e => e.EmailAddress)
.HasMaxLength(256);
//Set to now on creation.
builder.Property(e => e.CreateTime)
.HasDefaultValueSql("current_timestamp");
builder.Property(e => e.UpdateTime)
.HasDefaultValueSql("current_timestamp");
var addressBuilder = builder.ComplexProperty(e => e.AddressDetails);
addressBuilder.Property(e => e.Address)
.HasMaxLength(128);
addressBuilder.Property(e => e.AddressCity)
.HasMaxLength(128);
addressBuilder.Property(e => e.AddressProvince)
.HasMaxLength(128);
addressBuilder.Property(e => e.AddressState)
.HasMaxLength(128);
//3 letter code: ISO 3166-1 Alfa-3
addressBuilder.Property(e => e.AddressCountry)
.IsRequired()
.HasMaxLength(3);
addressBuilder.Property(e => e.ZipCode)
.HasMaxLength(3);
}
}
@@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore;
using Somnia.GuestLog.Infrastructure.EntityConfigs;
using Somnia.GuestLog.Models;
namespace Somnia.GuestLog.Infrastructure;
public partial class GuestLogContext : DbContext
{
public GuestLogContext(DbContextOptions<GuestLogContext> options)
: base(options)
{ }
public DbSet<GuestDocument> GuestDocuments { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration<GuestDocument>(new GuestDocumentEntityConfig());
OnModelCreatingPartial(modelBuilder);
base.OnModelCreating(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
@@ -0,0 +1,125 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Somnia.GuestLog.Infrastructure;
#nullable disable
namespace Somnia.GuestLog.Infrastructure.Migrations
{
[DbContext(typeof(GuestLogContext))]
[Migration("20260618190348_AddTable_GuestDocuments")]
partial class AddTable_GuestDocuments
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Somnia.GuestLog.Models.GuestDocument", b =>
{
b.Property<string>("DocumentType")
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<string>("DocumentNum")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<DateOnly>("BirthDate")
.HasColumnType("date");
b.Property<DateTime>("CreateTime")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("current_timestamp");
b.Property<string>("EmailAddress")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("Gender")
.HasMaxLength(1)
.HasColumnType("character varying(1)");
b.Property<DateOnly>("IssueDate")
.HasColumnType("date");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("Nationality")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("character varying(3)");
b.Property<string>("PhoneNumber")
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<string>("SupportNum")
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<string>("Surname")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("Surname2")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<DateTime>("UpdateTime")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("current_timestamp");
b.ComplexProperty(typeof(Dictionary<string, object>), "AddressDetails", "Somnia.GuestLog.Models.GuestDocument.AddressDetails#GuestAddress", b1 =>
{
b1.Property<string>("Address")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressCity")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressCountry")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("character varying(3)");
b1.Property<string>("AddressProvince")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressState")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("ZipCode")
.HasMaxLength(3)
.HasColumnType("character varying(3)");
});
b.HasKey("DocumentType", "DocumentNum");
b.ToTable("GuestDocument", (string)null);
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Somnia.GuestLog.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddTable_GuestDocuments : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "GuestDocument",
columns: table => new
{
DocumentType = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
DocumentNum = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
IssueDate = table.Column<DateOnly>(type: "date", nullable: false),
SupportNum = table.Column<string>(type: "character varying(10)", maxLength: 10, nullable: true),
Nationality = table.Column<string>(type: "character varying(3)", maxLength: 3, nullable: false),
Name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Surname = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Surname2 = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
BirthDate = table.Column<DateOnly>(type: "date", nullable: false),
Gender = table.Column<string>(type: "character varying(1)", maxLength: 1, nullable: true),
PhoneNumber = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
EmailAddress = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
CreateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "current_timestamp"),
UpdateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, defaultValueSql: "current_timestamp"),
AddressDetails_Address = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
AddressDetails_AddressCity = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
AddressDetails_AddressCountry = table.Column<string>(type: "character varying(3)", maxLength: 3, nullable: true),
AddressDetails_AddressProvince = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
AddressDetails_AddressState = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
AddressDetails_ZipCode = table.Column<string>(type: "character varying(3)", maxLength: 3, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_GuestDocument", x => new { x.DocumentType, x.DocumentNum });
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "GuestDocument");
}
}
}
@@ -0,0 +1,122 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Somnia.GuestLog.Infrastructure;
#nullable disable
namespace Somnia.GuestLog.Infrastructure.Migrations
{
[DbContext(typeof(GuestLogContext))]
partial class GuestLogContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Somnia.GuestLog.Models.GuestDocument", b =>
{
b.Property<string>("DocumentType")
.HasMaxLength(8)
.HasColumnType("character varying(8)");
b.Property<string>("DocumentNum")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<DateOnly>("BirthDate")
.HasColumnType("date");
b.Property<DateTime>("CreateTime")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("current_timestamp");
b.Property<string>("EmailAddress")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("Gender")
.HasMaxLength(1)
.HasColumnType("character varying(1)");
b.Property<DateOnly>("IssueDate")
.HasColumnType("date");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("Nationality")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("character varying(3)");
b.Property<string>("PhoneNumber")
.HasMaxLength(32)
.HasColumnType("character varying(32)");
b.Property<string>("SupportNum")
.HasMaxLength(10)
.HasColumnType("character varying(10)");
b.Property<string>("Surname")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("Surname2")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<DateTime>("UpdateTime")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("current_timestamp");
b.ComplexProperty(typeof(Dictionary<string, object>), "AddressDetails", "Somnia.GuestLog.Models.GuestDocument.AddressDetails#GuestAddress", b1 =>
{
b1.Property<string>("Address")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressCity")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressCountry")
.IsRequired()
.HasMaxLength(3)
.HasColumnType("character varying(3)");
b1.Property<string>("AddressProvince")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("AddressState")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<string>("ZipCode")
.HasMaxLength(3)
.HasColumnType("character varying(3)");
});
b.HasKey("DocumentType", "DocumentNum");
b.ToTable("GuestDocument", (string)null);
});
#pragma warning restore 612, 618
}
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace Somnia.GuestLog.Models;
public abstract class BaseEntity
{
public abstract string GetFullKey();
}
@@ -0,0 +1,13 @@
namespace Somnia.GuestLog.Models;
public class GuestAddress : BaseEntity
{
public string? Address { get; set; }
public string? AddressCity { get; set; }
public string? AddressProvince { get; set; }
public string? AddressState { get; set; }
public required string AddressCountry { get; set; }
public string? ZipCode { get; set; }
public override string GetFullKey() => "N/A";
}
@@ -0,0 +1,29 @@
namespace Somnia.GuestLog.Models;
public class GuestDocument : BaseEntity
{
public required string DocumentType { get; set; }
public required string DocumentNum { get; set; }
public required DateOnly IssueDate { get; set; }
public string? SupportNum { get; set; }
public required string Nationality { get; set; }
public required string Name { get; set; }
public required string Surname { get; set; }
public string? Surname2 { get; set; }
public required DateOnly BirthDate { get; set; }
public string? Gender { get; set; }
public GuestAddress? AddressDetails { get; set; }
public string? PhoneNumber { get; set; }
public string? EmailAddress { get; set; }
public required DateTime CreateTime { get; set; }
public required DateTime UpdateTime { get; set; }
public override string GetFullKey() => $"{DocumentType}-{DocumentNum}";
}
+11
View File
@@ -1,8 +1,19 @@
using Microsoft.EntityFrameworkCore;
using MudBlazor.Services;
using Somnia.GuestLog.Components;
using Somnia.GuestLog.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
var connectionStringGuestLog = builder.Configuration.GetConnectionString("DbSomniaGuestLog")
?? throw new InvalidOperationException("Connection string 'DbSomniaGuestLog' not found.");
builder.Services.AddDbContextFactory<GuestLogContext>(options =>
{
options.UseNpgsql(connectionStringGuestLog);
});
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
// Add MudBlazor services
builder.Services.AddMudServices();
+3
View File
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"DbSomniaGuestLog": "Host=localhost;Port=5432;Username=postgres;Password=P@ssw0rd;Database=SomniaGuestLog"
},
"Logging": {
"LogLevel": {
"Default": "Information",