Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Node Entity Configuration #32

Merged
merged 10 commits into from
Jan 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ public CreateNodeCommandValidator()
RuleFor(x => x.Node.Title)
.NotEmpty().WithMessage("Title is required.")
.MaximumLength(100).WithMessage("Title must not exceed 100 characters.");

RuleFor(x => x.Node.Description)
.NotEmpty().WithMessage("Description is required.")
.MaximumLength(500).WithMessage("Description must not exceed 500 characters.");

// ToDo: Add remaining Node command validators
RuleFor(x => x.Node.Timestamp)
.LessThanOrEqualTo(DateTime.Now).WithMessage("Timestamp cannot be in the future.");

RuleFor(x => x.Node.Importance)
.InclusiveBetween(1, 10).WithMessage("Importance must be between 1 and 10.");

RuleFor(x => x.Node.Phase)
.NotEmpty().WithMessage("Phase is required.");

RuleForEach(x => x.Node.Categories)
.MaximumLength(50).WithMessage("Category must not exceed 50 characters.");

RuleForEach(x => x.Node.Tags)
.MaximumLength(50).WithMessage("Tag must not exceed 50 characters.");
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Nodes.Infrastructure.Data.Configurations;

public class NodeConfiguration : IEntityTypeConfiguration<Node>
{
public void Configure(EntityTypeBuilder<Node> builder)
{
builder.HasKey(n => n.Id);
builder.Property(n => n.Id).HasConversion(
nodeId => nodeId.Value,
dbId => NodeId.Of(dbId));

// ToDo: Add remaining Node configuration commands
}
}
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Nodes.Infrastructure.Data.Configurations;

public class NodeConfiguration : IEntityTypeConfiguration<Node>
{
public void Configure(EntityTypeBuilder<Node> builder)
{
builder.HasKey(n => n.Id);
builder.Property(n => n.Id).HasConversion(
nodeId => nodeId.Value,
dbId => NodeId.Of(dbId));

builder.Property(n => n.Title)
.IsRequired()
.HasMaxLength(100);

builder.Property(n => n.Description)
.IsRequired()
.HasMaxLength(500);

builder.Property(n => n.Importance)
.IsRequired();

builder.Property(n => n.Phase)
.IsRequired();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Nodes.Infrastructure.Data.Migrations
{
/// <inheritdoc />
public partial class ApplyNewNodeConfigurations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Title",
schema: "Nodes",
table: "Nodes",
type: "character varying(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "text");

migrationBuilder.AlterColumn<string>(
name: "Description",
schema: "Nodes",
table: "Nodes",
type: "character varying(500)",
maxLength: 500,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Title",
schema: "Nodes",
table: "Nodes",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(100)",
oldMaxLength: 100);

migrationBuilder.AlterColumn<string>(
name: "Description",
schema: "Nodes",
table: "Nodes",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(500)",
oldMaxLength: 500);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,68 +1,70 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Nodes.Infrastructure.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Nodes.Infrastructure.Data.Migrations
{
[DbContext(typeof(NodesDbContext))]
partial class NodesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Nodes")
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("Nodes.Domain.Models.Node", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");

b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone");

b.Property<string>("CreatedBy")
.HasColumnType("text");

b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");

b.Property<int>("Importance")
.HasColumnType("integer");

b.Property<DateTime?>("LastModifiedAt")
.HasColumnType("timestamp with time zone");

b.Property<string>("LastModifiedBy")
.HasColumnType("text");

b.Property<string>("Phase")
.IsRequired()
.HasColumnType("text");

b.Property<DateTime>("Timestamp")
.HasColumnType("timestamp with time zone");

b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");

b.HasKey("Id");

b.ToTable("Nodes", "Nodes");
});
#pragma warning restore 612, 618
}
}
}
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Nodes.Infrastructure.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Nodes.Infrastructure.Data.Migrations
{
[DbContext(typeof(NodesDbContext))]
partial class NodesDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Nodes")
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

modelBuilder.Entity("Nodes.Domain.Models.Node", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");

b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone");

b.Property<string>("CreatedBy")
.HasColumnType("text");

b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");

b.Property<int>("Importance")
.HasColumnType("integer");

b.Property<DateTime?>("LastModifiedAt")
.HasColumnType("timestamp with time zone");

b.Property<string>("LastModifiedBy")
.HasColumnType("text");

b.Property<string>("Phase")
.IsRequired()
.HasColumnType("text");

b.Property<DateTime>("Timestamp")
.HasColumnType("timestamp with time zone");

b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.HasKey("Id");

b.ToTable("Nodes", "Nodes");
});
#pragma warning restore 612, 618
}
}
}
Loading