From ec32bf7a68012385cc784ebd3fa818db8f873b91 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sat, 28 Dec 2024 19:45:49 +0100 Subject: [PATCH 1/8] feat: add Node configuration --- .../Commands/CreateNode/CreateNodeCommand.cs | 17 ++++++- .../Data/Configurations/NodeConfiguration.cs | 44 ++++++++++++------- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs index 0fb812d..623e21d 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs @@ -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."); } } diff --git a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Configurations/NodeConfiguration.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Configurations/NodeConfiguration.cs index 56efb78..69c8194 100644 --- a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Configurations/NodeConfiguration.cs +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Configurations/NodeConfiguration.cs @@ -1,16 +1,28 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace Nodes.Infrastructure.Data.Configurations; - -public class NodeConfiguration : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder 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 +{ + public void Configure(EntityTypeBuilder 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(); + } +} From 099d84c391ab2aa79eaf69c344e4ff29fc2676b5 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sat, 28 Dec 2024 19:46:05 +0100 Subject: [PATCH 2/8] feat: add new migrations --- ...710_ApplyNewNodeConfigurations.Designer.cs | 73 +++++++++ ...241228182710_ApplyNewNodeConfigurations.cs | 58 ++++++++ .../Migrations/NodesDbContextModelSnapshot.cs | 138 +++++++++--------- 3 files changed, 201 insertions(+), 68 deletions(-) create mode 100644 Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.Designer.cs create mode 100644 Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.cs diff --git a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.Designer.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.Designer.cs new file mode 100644 index 0000000..b127a32 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.Designer.cs @@ -0,0 +1,73 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Nodes.Infrastructure.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Nodes.Infrastructure.Data.Migrations +{ + [DbContext(typeof(NodesDbContext))] + [Migration("20241228182710_ApplyNewNodeConfigurations")] + partial class ApplyNewNodeConfigurations + { + /// + protected override void BuildTargetModel(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("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Importance") + .HasColumnType("integer"); + + b.Property("LastModifiedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastModifiedBy") + .HasColumnType("text"); + + b.Property("Phase") + .IsRequired() + .HasColumnType("text"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Nodes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.cs new file mode 100644 index 0000000..8dc6259 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20241228182710_ApplyNewNodeConfigurations.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Nodes.Infrastructure.Data.Migrations +{ + /// + public partial class ApplyNewNodeConfigurations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Title", + schema: "Nodes", + table: "Nodes", + type: "character varying(100)", + maxLength: 100, + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Description", + schema: "Nodes", + table: "Nodes", + type: "character varying(500)", + maxLength: 500, + nullable: false, + oldClrType: typeof(string), + oldType: "text"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Title", + schema: "Nodes", + table: "Nodes", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(100)", + oldMaxLength: 100); + + migrationBuilder.AlterColumn( + name: "Description", + schema: "Nodes", + table: "Nodes", + type: "text", + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(500)", + oldMaxLength: 500); + } + } +} diff --git a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs index bfcc659..cd8b2de 100644 --- a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs @@ -1,68 +1,70 @@ -// -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("Id") - .HasColumnType("uuid"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("text"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("Importance") - .HasColumnType("integer"); - - b.Property("LastModifiedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("LastModifiedBy") - .HasColumnType("text"); - - b.Property("Phase") - .IsRequired() - .HasColumnType("text"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Nodes", "Nodes"); - }); -#pragma warning restore 612, 618 - } - } -} +// +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("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Importance") + .HasColumnType("integer"); + + b.Property("LastModifiedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastModifiedBy") + .HasColumnType("text"); + + b.Property("Phase") + .IsRequired() + .HasColumnType("text"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.ToTable("Nodes", "Nodes"); + }); +#pragma warning restore 612, 618 + } + } +} From bdb40c3ef908b1d2b71134fdab1e2daf0f067232 Mon Sep 17 00:00:00 2001 From: NikolaVetnic Date: Fri, 3 Jan 2025 10:42:08 +0100 Subject: [PATCH 3/8] feat: add validation for categories and tags lists --- .../Nodes/Commands/CreateNode/CreateNodeCommand.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs index 623e21d..b0cfe33 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeCommand.cs @@ -28,6 +28,19 @@ public CreateNodeCommandValidator() RuleFor(x => x.Node.Phase) .NotEmpty().WithMessage("Phase is required."); + + RuleFor(x => x.Node) + .NotNull().WithMessage("Node cannot be null.") + .DependentRules(() => + { + RuleFor(x => x.Node.Categories) + .Must(categories => categories != null && categories.Count > 0) + .WithMessage("At least one category must be provided."); + + RuleFor(x => x.Node.Tags) + .Must(tags => tags != null && tags.Count > 0) + .WithMessage("At least one tag must be provided."); + }); RuleForEach(x => x.Node.Categories) .MaximumLength(50).WithMessage("Category must not exceed 50 characters."); From a181348bc919e24b210419f9e445aa803b0054af Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Fri, 3 Jan 2025 11:59:10 +0100 Subject: [PATCH 4/8] fix: re-implement node validator --- .../BuildingBlocks.Api/Converters/NodeIdConverter.cs | 10 ++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Extensions/ServiceCollectionExtensions.cs | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs new file mode 100644 index 0000000..a1680ba --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs @@ -0,0 +1,10 @@ +using BuildingBlocks.Domain.ValueObjects.Ids; +using Mapster; + +namespace BuildingBlocks.Api.Converters; + +public class NodeIdConverter : IRegister +{ + public void Register(TypeAdapterConfig config) => + config.NewConfig().ConstructUsing(src => NodeId.Of(src.Value)); +} \ No newline at end of file diff --git a/Backend/src/Modules/Nodes/Nodes.Api/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Nodes/Nodes.Api/Extensions/ServiceCollectionExtensions.cs index f9de648..6562ec0 100644 --- a/Backend/src/Modules/Nodes/Nodes.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Nodes/Nodes.Api/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using BuildingBlocks.Api.Converters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Nodes.Application.Extensions; @@ -19,6 +20,8 @@ public static IServiceCollection AddNodesModule private static IServiceCollection AddApiServices(this IServiceCollection services) { + TypeAdapterConfig.GlobalSettings.Scan(typeof(NodeIdConverter).Assembly); + return services; } diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Nodes/Nodes.Application/Extensions/ServiceCollectionExtensions.cs index 91fddc5..28cafb1 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Extensions/ServiceCollectionExtensions.cs @@ -15,6 +15,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection config.AddOpenBehavior(typeof(LoggingBehavior<,>)); }); + services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); + return services; } } From cdfc8203d91665b641b35255b9462098bff6a024 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Fri, 3 Jan 2025 12:28:08 +0100 Subject: [PATCH 5/8] fix: re-implement `file`, `note`, `reminder` and `timeline` validators --- .../BuildingBlocks.Api/Converters/FileIdConverter.cs | 9 +++++++++ .../BuildingBlocks.Api/Converters/NodeIdConverter.cs | 3 +-- .../BuildingBlocks.Api/Converters/NoteIdConverter.cs | 9 +++++++++ .../BuildingBlocks.Api/Converters/ReminderIdConverter.cs | 9 +++++++++ .../BuildingBlocks.Api/Converters/TimelineIdConverter.cs | 9 +++++++++ .../src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs | 1 + .../Files.Api/Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Extensions/ServiceCollectionExtensions.cs | 2 ++ .../Notes.Api/Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Extensions/ServiceCollectionExtensions.cs | 2 ++ .../Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Extensions/ServiceCollectionExtensions.cs | 2 ++ .../Extensions/ServiceCollectionExtensions.cs | 3 +++ .../Extensions/ServiceCollectionExtensions.cs | 2 ++ 14 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/FileIdConverter.cs create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NoteIdConverter.cs create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/ReminderIdConverter.cs create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/TimelineIdConverter.cs create mode 100644 Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/FileIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/FileIdConverter.cs new file mode 100644 index 0000000..73b7f24 --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/FileIdConverter.cs @@ -0,0 +1,9 @@ +using BuildingBlocks.Domain.ValueObjects.Ids; + +namespace BuildingBlocks.Api.Converters; + +public class FileIdConverter : IRegister +{ + public void Register(TypeAdapterConfig config) => + config.NewConfig().ConstructUsing(src => FileAssetId.Of(src.Value)); +} diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs index a1680ba..2bf272f 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NodeIdConverter.cs @@ -1,5 +1,4 @@ using BuildingBlocks.Domain.ValueObjects.Ids; -using Mapster; namespace BuildingBlocks.Api.Converters; @@ -7,4 +6,4 @@ public class NodeIdConverter : IRegister { public void Register(TypeAdapterConfig config) => config.NewConfig().ConstructUsing(src => NodeId.Of(src.Value)); -} \ No newline at end of file +} diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NoteIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NoteIdConverter.cs new file mode 100644 index 0000000..8ae4c50 --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/NoteIdConverter.cs @@ -0,0 +1,9 @@ +using BuildingBlocks.Domain.ValueObjects.Ids; + +namespace BuildingBlocks.Api.Converters; + +public class NoteIdConverter : IRegister +{ + public void Register(TypeAdapterConfig config) => + config.NewConfig().ConstructUsing(src => NoteId.Of(src.Value)); +} diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/ReminderIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/ReminderIdConverter.cs new file mode 100644 index 0000000..0b1bb4b --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/ReminderIdConverter.cs @@ -0,0 +1,9 @@ +using BuildingBlocks.Domain.ValueObjects.Ids; + +namespace BuildingBlocks.Api.Converters; + +public class ReminderIdConverter : IRegister +{ + public void Register(TypeAdapterConfig config) => + config.NewConfig().ConstructUsing(src => ReminderId.Of(src.Value)); +} diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/TimelineIdConverter.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/TimelineIdConverter.cs new file mode 100644 index 0000000..15fa426 --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/Converters/TimelineIdConverter.cs @@ -0,0 +1,9 @@ +using BuildingBlocks.Domain.ValueObjects.Ids; + +namespace BuildingBlocks.Api.Converters; + +public class TimelineIdConverter : IRegister +{ + public void Register(TypeAdapterConfig config) => + config.NewConfig().ConstructUsing(src => TimelineId.Of(src.Value)); +} diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs new file mode 100644 index 0000000..2b89a99 --- /dev/null +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs @@ -0,0 +1 @@ +global using Mapster; \ No newline at end of file diff --git a/Backend/src/Modules/Files/Files.Api/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Files/Files.Api/Extensions/ServiceCollectionExtensions.cs index 1632953..d2dd07a 100644 --- a/Backend/src/Modules/Files/Files.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Files/Files.Api/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using BuildingBlocks.Api.Converters; using Files.Application.Extensions; using Files.Infrastructure; using Microsoft.Extensions.Configuration; @@ -19,6 +20,8 @@ public static IServiceCollection AddFilesModule private static IServiceCollection AddApiServices(this IServiceCollection services) { + TypeAdapterConfig.GlobalSettings.Scan(typeof(FileIdConverter).Assembly); + return services; } diff --git a/Backend/src/Modules/Files/Files.Application/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Files/Files.Application/Extensions/ServiceCollectionExtensions.cs index 3006850..986ee30 100644 --- a/Backend/src/Modules/Files/Files.Application/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Files/Files.Application/Extensions/ServiceCollectionExtensions.cs @@ -15,6 +15,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection config.AddOpenBehavior(typeof(LoggingBehavior<,>)); }); + services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); + return services; } } diff --git a/Backend/src/Modules/Notes/Notes.Api/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Notes/Notes.Api/Extensions/ServiceCollectionExtensions.cs index 6b5f6d4..ac2cb93 100644 --- a/Backend/src/Modules/Notes/Notes.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Notes/Notes.Api/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using BuildingBlocks.Api.Converters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Notes.Application.Extensions; @@ -19,6 +20,8 @@ public static IServiceCollection AddNotesModule private static IServiceCollection AddApiServices(this IServiceCollection services) { + TypeAdapterConfig.GlobalSettings.Scan(typeof(NoteIdConverter).Assembly); + return services; } diff --git a/Backend/src/Modules/Notes/Notes.Application/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Notes/Notes.Application/Extensions/ServiceCollectionExtensions.cs index a3615b1..dcdef9d 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Extensions/ServiceCollectionExtensions.cs @@ -15,6 +15,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection config.AddOpenBehavior(typeof(LoggingBehavior<,>)); }); + services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); + return services; } } diff --git a/Backend/src/Modules/Reminders/Reminders.Api/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Reminders/Reminders.Api/Extensions/ServiceCollectionExtensions.cs index ee2e3cd..8526d23 100644 --- a/Backend/src/Modules/Reminders/Reminders.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Reminders/Reminders.Api/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using BuildingBlocks.Api.Converters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Reminders.Application.Extensions; @@ -19,6 +20,8 @@ public static IServiceCollection AddRemindersModule private static IServiceCollection AddApiServices(this IServiceCollection services) { + TypeAdapterConfig.GlobalSettings.Scan(typeof(ReminderIdConverter).Assembly); + return services; } diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Reminders/Reminders.Application/Extensions/ServiceCollectionExtensions.cs index 2ecf10b..d0c9f15 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Extensions/ServiceCollectionExtensions.cs @@ -15,6 +15,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection config.AddOpenBehavior(typeof(LoggingBehavior<,>)); }); + services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); + return services; } } diff --git a/Backend/src/Modules/Timelines/Timelines.Api/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Timelines/Timelines.Api/Extensions/ServiceCollectionExtensions.cs index f04ff3e..7158a4d 100644 --- a/Backend/src/Modules/Timelines/Timelines.Api/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Timelines/Timelines.Api/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using BuildingBlocks.Api.Converters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Timelines.Application.Extensions; @@ -19,6 +20,8 @@ public static IServiceCollection AddTimelinesModule private static IServiceCollection AddApiServices(this IServiceCollection services) { + TypeAdapterConfig.GlobalSettings.Scan(typeof(TimelineIdConverter).Assembly); + return services; } diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Extensions/ServiceCollectionExtensions.cs b/Backend/src/Modules/Timelines/Timelines.Application/Extensions/ServiceCollectionExtensions.cs index 9ccc69d..55cfef7 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Extensions/ServiceCollectionExtensions.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Extensions/ServiceCollectionExtensions.cs @@ -15,6 +15,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection config.AddOpenBehavior(typeof(LoggingBehavior<,>)); }); + services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); + return services; } } From a6edef68898c74e206ae5b3915d175952189c415 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Fri, 3 Jan 2025 12:31:05 +0100 Subject: [PATCH 6/8] chore: add empty line at the end of the file --- Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs index 2b89a99..766f651 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Api/GlobalUsing.cs @@ -1 +1 @@ -global using Mapster; \ No newline at end of file +global using Mapster; From de42bd43babdbdc80396bddfab6f1e4285f9d432 Mon Sep 17 00:00:00 2001 From: NikolaVetnic Date: Fri, 3 Jan 2025 14:16:01 +0100 Subject: [PATCH 7/8] fix: display id value in query responses properly --- .../ValueObjects/Ids/FileAssetId.cs | 5 ++- .../ValueObjects/Ids/NodeId.cs | 10 +++--- .../ValueObjects/Ids/NoteId.cs | 7 ++-- .../ValueObjects/Ids/ReminderId.cs | 5 ++- .../ValueObjects/Ids/TimelineId.cs | 5 ++- .../ValueObjects/StronglyTypedId.cs | 32 +++---------------- 6 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs index 0411b72..f4cc4e0 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs @@ -2,12 +2,11 @@ namespace BuildingBlocks.Domain.ValueObjects.Ids; -[JsonConverter(typeof(FileAssetIdJsonConverter))] -public record FileAssetId : StronglyTypedId +public class FileAssetId : StronglyTypedId { private FileAssetId(Guid value) : base(value) { } public static FileAssetId Of(Guid value) => new(value); - private class FileAssetIdJsonConverter : StronglyTypedIdJsonConverter; + public override string ToString() => Value.ToString(); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs index d026a7c..475fffd 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs @@ -1,13 +1,13 @@ -using System.Text.Json.Serialization; +using System.Text.Json; +using System.Text.Json.Serialization; namespace BuildingBlocks.Domain.ValueObjects.Ids; -[JsonConverter(typeof(NodeIdJsonConverter))] -public record NodeId : StronglyTypedId +public class NodeId : StronglyTypedId { private NodeId(Guid value) : base(value) { } public static NodeId Of(Guid value) => new(value); - - private class NodeIdJsonConverter : StronglyTypedIdJsonConverter; + + public override string ToString() => Value.ToString(); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs index 63436b0..ca48c4a 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs @@ -2,12 +2,11 @@ namespace BuildingBlocks.Domain.ValueObjects.Ids; -[JsonConverter(typeof(NoteIdJsonConverter))] -public record NoteId : StronglyTypedId +public class NoteId : StronglyTypedId { private NoteId(Guid value) : base(value) { } public static NoteId Of(Guid value) => new(value); - - private class NoteIdJsonConverter : StronglyTypedIdJsonConverter; + + public override string ToString() => Value.ToString(); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs index 9e4195d..c577a5e 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs @@ -2,12 +2,11 @@ namespace BuildingBlocks.Domain.ValueObjects.Ids; -[JsonConverter(typeof(ReminderIdJsonConverter))] -public record ReminderId : StronglyTypedId +public class ReminderId : StronglyTypedId { private ReminderId(Guid value) : base(value) { } public static ReminderId Of(Guid value) => new(value); - private class ReminderIdJsonConverter : StronglyTypedIdJsonConverter; + public override string ToString() => Value.ToString(); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs index fee385e..47d2c93 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs @@ -2,12 +2,11 @@ namespace BuildingBlocks.Domain.ValueObjects.Ids; -[JsonConverter(typeof(TimelineIdJsonConverter))] -public record TimelineId : StronglyTypedId +public class TimelineId : StronglyTypedId { private TimelineId(Guid value) : base(value) { } public static TimelineId Of(Guid value) => new(value); - private class TimelineIdJsonConverter : StronglyTypedIdJsonConverter; + public override string ToString() => Value.ToString(); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/StronglyTypedId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/StronglyTypedId.cs index 41cec1b..b1e0750 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/StronglyTypedId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/StronglyTypedId.cs @@ -1,9 +1,6 @@ -using System.Text.Json.Serialization; -using System.Text.Json; +namespace BuildingBlocks.Domain.ValueObjects; -namespace BuildingBlocks.Domain.ValueObjects; - -public abstract record StronglyTypedId +public abstract class StronglyTypedId { protected StronglyTypedId(Guid value) { @@ -14,27 +11,6 @@ protected StronglyTypedId(Guid value) } public Guid Value { get; } - - public override string ToString() => Value.ToString(); -} - -public class StronglyTypedIdJsonConverter : JsonConverter where T : StronglyTypedId -{ - public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var value = reader.GetString(); - - if (Guid.TryParse(value, out var guid)) - { - var constructor = typeof(T).GetConstructor(new[] { typeof(Guid) }); - - if (constructor != null) - return (T)constructor.Invoke(new object[] { guid }); - } - - throw new JsonException($"Invalid GUID format for {typeof(T).Name}: {value}"); - } - - public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) => - writer.WriteStringValue(value.Value.ToString()); + + public abstract override string ToString(); } From 364ddd71a13fa76f52efebb52cb5baa96644c838 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Fri, 3 Jan 2025 14:23:37 +0100 Subject: [PATCH 8/8] chore: remove unused usings --- .../BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs | 4 +--- .../BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs | 5 +---- .../BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs | 4 +--- .../BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs | 4 +--- .../BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs | 4 +--- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs index f4cc4e0..c09da68 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/FileAssetId.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace BuildingBlocks.Domain.ValueObjects.Ids; +namespace BuildingBlocks.Domain.ValueObjects.Ids; public class FileAssetId : StronglyTypedId { diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs index 475fffd..c259e08 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NodeId.cs @@ -1,7 +1,4 @@ -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace BuildingBlocks.Domain.ValueObjects.Ids; +namespace BuildingBlocks.Domain.ValueObjects.Ids; public class NodeId : StronglyTypedId { diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs index ca48c4a..b5c3dcc 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/NoteId.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace BuildingBlocks.Domain.ValueObjects.Ids; +namespace BuildingBlocks.Domain.ValueObjects.Ids; public class NoteId : StronglyTypedId { diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs index c577a5e..2080e6a 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/ReminderId.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace BuildingBlocks.Domain.ValueObjects.Ids; +namespace BuildingBlocks.Domain.ValueObjects.Ids; public class ReminderId : StronglyTypedId { diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs index 47d2c93..cdad40d 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/ValueObjects/Ids/TimelineId.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace BuildingBlocks.Domain.ValueObjects.Ids; +namespace BuildingBlocks.Domain.ValueObjects.Ids; public class TimelineId : StronglyTypedId {