From 4e813e9b72affa28be591282162d3ba07941f5d2 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Wed, 12 Feb 2025 11:40:03 +0100 Subject: [PATCH] feat: add migrations & adapt Dtos --- .../Data/INodesService.cs | 2 + .../Nodes/Node/Dtos/NodeDto.cs | 5 +- .../Notes/Note/Dtos/NoteDto.cs | 8 +- .../Nodes.Application/Data/NodesService.cs | 19 ++- .../20250212094411_AddNote.Designer.cs | 81 ++++++++++ .../Data/Migrations/20250212094411_AddNote.cs | 30 ++++ .../Migrations/NodesDbContextModelSnapshot.cs | 152 +++++++++--------- .../Notes.Api/Endpoints/Notes/CreateNote.cs | 2 + .../Notes.Application/Data/NotesService.cs | 9 +- .../Commands/CreateNote/CreateNoteCommand.cs | 15 +- .../Commands/CreateNote/CreateNoteHandler.cs | 10 +- .../Notes/Extensions/NoteExtensions.cs | 13 +- .../Queries/ListNotes/ListNotesHandler.cs | 13 +- .../Data/Extensions/InitialData.cs | 9 +- .../20250212094755_AddNode.Designer.cs | 84 ++++++++++ .../Data/Migrations/20250212094755_AddNode.cs | 43 +++++ .../Migrations/NotesDbContextModelSnapshot.cs | 5 + .../Data/NotesDbContext.cs | 3 +- 18 files changed, 398 insertions(+), 105 deletions(-) create mode 100644 Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.Designer.cs create mode 100644 Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.cs create mode 100644 Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.Designer.cs create mode 100644 Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.cs diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Application/Data/INodesService.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Application/Data/INodesService.cs index d7a81529..989b277e 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Application/Data/INodesService.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Application/Data/INodesService.cs @@ -1,5 +1,6 @@ using BuildingBlocks.Domain.Nodes.Node.Dtos; using BuildingBlocks.Domain.Nodes.Node.ValueObjects; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; using BuildingBlocks.Domain.Reminders.Reminder.ValueObjects; namespace BuildingBlocks.Application.Data; @@ -9,4 +10,5 @@ public interface INodesService Task GetNodeByIdAsync(NodeId nodeId, CancellationToken cancellationToken); Task GetNodeBaseByIdAsync(NodeId nodeId, CancellationToken cancellationToken); Task AddReminder(NodeId nodeId, ReminderId reminderId, CancellationToken cancellationToken); + Task AddNote(NodeId nodeId, NoteId noteId, CancellationToken cancellationToken); } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Nodes/Node/Dtos/NodeDto.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Nodes/Node/Dtos/NodeDto.cs index c3d26eda..903d2ada 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Nodes/Node/Dtos/NodeDto.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Nodes/Node/Dtos/NodeDto.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using BuildingBlocks.Domain.Notes.Note.Dtos; using BuildingBlocks.Domain.Reminders.Reminder.Dtos; namespace BuildingBlocks.Domain.Nodes.Node.Dtos; @@ -13,5 +14,7 @@ public class NodeDto( List categories, List tags) : NodeBaseDto(id, title, description, timestamp, importance, phase, categories, tags) { - [JsonPropertyName("reminders")] public List Reminders { get; } = []; + [JsonPropertyName("reminders")] public List Reminders { get; } = []; + + [JsonPropertyName("notes")] public List Notes { get; } = []; } diff --git a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Notes/Note/Dtos/NoteDto.cs b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Notes/Note/Dtos/NoteDto.cs index 1d6ea7d4..9c5c5d0d 100644 --- a/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Notes/Note/Dtos/NoteDto.cs +++ b/Backend/src/BuildingBlocks/BuildingBlocks.Domain/Notes/Note/Dtos/NoteDto.cs @@ -1,4 +1,6 @@ -using BuildingBlocks.Domain.Notes.Note.ValueObjects; +using System.Text.Json.Serialization; +using BuildingBlocks.Domain.Nodes.Node.Dtos; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; namespace BuildingBlocks.Domain.Notes.Note.Dtos; @@ -10,6 +12,8 @@ public class NoteDto( string owner, List relatedNotes, List sharedWith, - bool isPublic) : NoteBaseDto(id, title, content, timestamp, owner, relatedNotes, sharedWith, isPublic) + bool isPublic, + NodeBaseDto node) : NoteBaseDto(id, title, content, timestamp, owner, relatedNotes, sharedWith, isPublic) { + [JsonPropertyName("note")] public NodeBaseDto Node { get; set; } = node; } diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Data/NodesService.cs b/Backend/src/Modules/Nodes/Nodes.Application/Data/NodesService.cs index 33c3e316..57e5784a 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Data/NodesService.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Data/NodesService.cs @@ -1,6 +1,7 @@ using BuildingBlocks.Application.Data; using BuildingBlocks.Domain.Nodes.Node.Dtos; using BuildingBlocks.Domain.Nodes.Node.ValueObjects; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; using BuildingBlocks.Domain.Reminders.Reminder.ValueObjects; using Mapster; using Microsoft.Extensions.DependencyInjection; @@ -24,6 +25,14 @@ public async Task GetNodeByIdAsync(NodeId nodeId, CancellationToken can nodeDto.Reminders.Add(reminder); } + var notesService = serviceProvider.GetRequiredService(); + + foreach (var noteId in node.NoteIds) + { + var note = await notesService.GetNoteBaseByIdAsync(noteId, cancellationToken); + nodeDto.Notes.Add(note); + } + return nodeDto; } @@ -41,5 +50,13 @@ public async Task AddReminder(NodeId nodeId, ReminderId reminderId, Cancellation node.AddReminder(reminderId); await nodesRepository.UpdateNodeAsync(node, cancellationToken); - } + } + + public async Task AddNote(NodeId nodeId, NoteId noteId, CancellationToken cancellationToken) + { + var node = await nodesRepository.GetNodeByIdAsync(nodeId, cancellationToken); + node.AddNote(noteId); + + await nodesRepository.UpdateNodeAsync(node, cancellationToken); + } } diff --git a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.Designer.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.Designer.cs new file mode 100644 index 00000000..7be24da8 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.Designer.cs @@ -0,0 +1,81 @@ +// +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("20250212094411_AddNote")] + partial class AddNote + { + /// + 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("NoteIds") + .HasColumnType("text") + .HasColumnName("NoteIds"); + + b.Property("Phase") + .IsRequired() + .HasColumnType("text"); + + b.Property("ReminderIds") + .HasColumnType("text") + .HasColumnName("ReminderIds"); + + 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/20250212094411_AddNote.cs b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.cs new file mode 100644 index 00000000..0ff93c48 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/20250212094411_AddNote.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Nodes.Infrastructure.Data.Migrations +{ + /// + public partial class AddNote : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NoteIds", + schema: "Nodes", + table: "Nodes", + type: "text", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "NoteIds", + schema: "Nodes", + table: "Nodes"); + } + } +} 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 fc2f05fd..f53898f6 100644 --- a/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs +++ b/Backend/src/Modules/Nodes/Nodes.Infrastructure/Data/Migrations/NodesDbContextModelSnapshot.cs @@ -1,74 +1,78 @@ -// -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("SerializedReminderIds") - .HasColumnType("text") - .HasColumnName("ReminderIds"); - - 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 - } - } -} +// +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("NoteIds") + .HasColumnType("text") + .HasColumnName("NoteIds"); + + b.Property("Phase") + .IsRequired() + .HasColumnType("text"); + + b.Property("ReminderIds") + .HasColumnType("text") + .HasColumnName("ReminderIds"); + + 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/Notes/Notes.Api/Endpoints/Notes/CreateNote.cs b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/CreateNote.cs index dee6bcb1..1ed3916c 100644 --- a/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/CreateNote.cs +++ b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/CreateNote.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using BuildingBlocks.Domain.Nodes.Node.ValueObjects; using BuildingBlocks.Domain.Notes.Note.ValueObjects; using Notes.Application.Entities.Notes.Commands.CreateNote; @@ -33,6 +34,7 @@ public record CreateNoteRequest public string Owner { get; set; } public List SharedWith { get; set; } public bool IsPublic { get; set; } + public NodeId NodeId { get; set; } } public record CreateNoteResponse(NoteId Id); diff --git a/Backend/src/Modules/Notes/Notes.Application/Data/NotesService.cs b/Backend/src/Modules/Notes/Notes.Application/Data/NotesService.cs index 92295042..2c9d8209 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Data/NotesService.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Data/NotesService.cs @@ -2,8 +2,8 @@ using BuildingBlocks.Domain.Notes.Note.Dtos; using BuildingBlocks.Domain.Notes.Note.ValueObjects; using Mapster; +using Microsoft.Extensions.DependencyInjection; using Notes.Application.Data.Abstractions; -using Notes.Application.Entities.Notes.Extensions; namespace Notes.Application.Data; @@ -12,9 +12,12 @@ public class NotesService(INotesRepository notesRepository, IServiceProvider ser public async Task GetNoteByIdAsync(NoteId noteId, CancellationToken cancellationToken) { var note = await notesRepository.GetNoteByIdAsync(noteId, cancellationToken); - var noteDto = note.ToNoteDto(); + var noteDto = note.Adapt(); - return noteDto; + var node = await serviceProvider.GetRequiredService().GetNodeBaseByIdAsync(note.NodeId, cancellationToken); + noteDto.Node = node; + + return noteDto; } public async Task GetNoteBaseByIdAsync(NoteId noteId, CancellationToken cancellationToken) diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteCommand.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteCommand.cs index 6f496a53..e70b3060 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteCommand.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteCommand.cs @@ -1,15 +1,17 @@ -using BuildingBlocks.Domain.Notes.Note.ValueObjects; +using BuildingBlocks.Domain.Nodes.Node.ValueObjects; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; namespace Notes.Application.Entities.Notes.Commands.CreateNote; public record CreateNoteCommand : ICommand { - public string Title { get; set; } - public string Content { get; set; } - public DateTime Timestamp { get; set; } - public string Owner { get; set; } + public required string Title { get; set; } + public required string Content { get; set; } + public required DateTime Timestamp { get; set; } + public required string Owner { get; set; } public List SharedWith { get; set; } - public bool IsPublic { get; set; } + public required bool IsPublic { get; set; } + public required NodeId NodeId { get; set; } } public record CreateNoteResult(NoteId Id); @@ -23,5 +25,6 @@ public CreateNoteCommandValidator() RuleFor(x => x.Timestamp).NotEmpty().WithMessage("Timestamp is required."); RuleFor(x => x.Owner).NotEmpty().WithMessage("Owner is required."); RuleFor(x => x.IsPublic).NotEmpty().WithMessage("Please specify whether the note is public or private."); + RuleFor(x => x.NodeId).NotEmpty().WithMessage("NodeId is required."); } } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteHandler.cs index 02b74579..d2b09376 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/CreateNote/CreateNoteHandler.cs @@ -1,9 +1,10 @@ -using BuildingBlocks.Domain.Notes.Note.ValueObjects; +using BuildingBlocks.Application.Data; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; using Notes.Application.Data.Abstractions; namespace Notes.Application.Entities.Notes.Commands.CreateNote; -internal class CreateNoteHandler(INotesDbContext dbContext) +internal class CreateNoteHandler(INotesDbContext dbContext, INodesService nodeService) : ICommandHandler { public async Task Handle(CreateNoteCommand command, CancellationToken cancellationToken) @@ -13,6 +14,8 @@ public async Task Handle(CreateNoteCommand command, Cancellati dbContext.Notes.Add(note); await dbContext.SaveChangesAsync(cancellationToken); + await nodeService.AddNote(note.NodeId, note.Id, cancellationToken); + return new CreateNoteResult(note.Id); } } @@ -28,7 +31,8 @@ public static Note ToNote(this CreateNoteCommand command) command.Timestamp, command.Owner, command.SharedWith, - command.IsPublic + command.IsPublic, + command.NodeId ); } } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Extensions/NoteExtensions.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Extensions/NoteExtensions.cs index 5ae3c963..ce30e612 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Extensions/NoteExtensions.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Extensions/NoteExtensions.cs @@ -1,10 +1,11 @@ -using BuildingBlocks.Domain.Notes.Note.Dtos; +using BuildingBlocks.Domain.Nodes.Node.Dtos; +using BuildingBlocks.Domain.Notes.Note.Dtos; namespace Notes.Application.Entities.Notes.Extensions; public static class NoteExtensions { - public static NoteDto ToNoteDto(this Note note) + public static NoteDto ToNoteDto(this Note note, NodeBaseDto node) { return new NoteDto( note.Id.ToString(), @@ -14,11 +15,7 @@ public static NoteDto ToNoteDto(this Note note) note.Owner, note.RelatedNotes, note.SharedWith, - note.IsPublic); - } - - public static IEnumerable ToNodeDtoList(this IEnumerable notes) - { - return notes.Select(ToNoteDto); + note.IsPublic, + node); } } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/ListNotes/ListNotesHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/ListNotes/ListNotesHandler.cs index 0c12bd80..1e5e46c5 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/ListNotes/ListNotesHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/ListNotes/ListNotesHandler.cs @@ -1,11 +1,12 @@ -using BuildingBlocks.Application.Pagination; +using BuildingBlocks.Application.Data; +using BuildingBlocks.Application.Pagination; using BuildingBlocks.Domain.Notes.Note.Dtos; using Notes.Application.Data.Abstractions; using Notes.Application.Entities.Notes.Extensions; namespace Notes.Application.Entities.Notes.Queries.ListNotes; -internal class ListNotesHandler(INotesDbContext dbContext) : IQueryHandler +internal class ListNotesHandler(INotesDbContext dbContext, INodesService nodesService) : IQueryHandler { public async Task Handle(ListNotesQuery query, CancellationToken cancellationToken) { @@ -21,11 +22,17 @@ public async Task Handle(ListNotesQuery query, CancellationToke .Take(pageSize) .ToListAsync(cancellationToken: cancellationToken); + var noteDtos = notes.Select(r => + { + var node = nodesService.GetNodeBaseByIdAsync(r.NodeId, cancellationToken).GetAwaiter().GetResult(); + return r.ToNoteDto(node); + }).ToList(); + return new ListNotesResult( new PaginatedResult( pageIndex, pageSize, totalCount, - notes.ToNodeDtoList())); + noteDtos)); } } diff --git a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Extensions/InitialData.cs b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Extensions/InitialData.cs index 60a76f37..781486ec 100644 --- a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Extensions/InitialData.cs +++ b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Extensions/InitialData.cs @@ -1,4 +1,5 @@ -using BuildingBlocks.Domain.Notes.Note.ValueObjects; +using BuildingBlocks.Domain.Nodes.Node.ValueObjects; +using BuildingBlocks.Domain.Notes.Note.ValueObjects; namespace Notes.Infrastructure.Data.Extensions; @@ -14,7 +15,8 @@ internal static class InitialData DateTime.UtcNow, "Timo", ["Michael", "Dirk"], - false + false, + NodeId.Of(Guid.Parse("2df76835-c92b-45d0-9232-61901c4abe97")) ), Note.Create( @@ -24,7 +26,8 @@ internal static class InitialData DateTime.UtcNow, "Thomas", ["Daniel","Claus"], - true + true, + NodeId.Of(Guid.Parse("6968d886-9e39-4fc0-9f2c-a5fbc1548970")) ) }; } diff --git a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.Designer.cs b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.Designer.cs new file mode 100644 index 00000000..764c6348 --- /dev/null +++ b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.Designer.cs @@ -0,0 +1,84 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Notes.Infrastructure.Data; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Notes.Infrastructure.Data.Migrations +{ + [DbContext(typeof(NotesDbContext))] + [Migration("20250212094755_AddNode")] + partial class AddNode + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Notes") + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Notes.Domain.Models.Note", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("text"); + + b.Property("IsPublic") + .HasColumnType("boolean"); + + b.Property("LastModifiedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastModifiedBy") + .HasColumnType("text"); + + b.Property("NodeId") + .HasColumnType("uuid"); + + b.Property("Owner") + .IsRequired() + .HasColumnType("text"); + + b.Property("RelatedNotes") + .HasColumnType("text") + .HasColumnName("RelatedNotes"); + + b.Property("SharedWith") + .HasColumnType("text") + .HasColumnName("SharedWith"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("NodeId"); + + b.ToTable("Notes", "Notes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.cs b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.cs new file mode 100644 index 00000000..77363a0c --- /dev/null +++ b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/20250212094755_AddNode.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Notes.Infrastructure.Data.Migrations +{ + /// + public partial class AddNode : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "NodeId", + schema: "Notes", + table: "Notes", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + + migrationBuilder.CreateIndex( + name: "IX_Notes_NodeId", + schema: "Notes", + table: "Notes", + column: "NodeId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_Notes_NodeId", + schema: "Notes", + table: "Notes"); + + migrationBuilder.DropColumn( + name: "NodeId", + schema: "Notes", + table: "Notes"); + } + } +} diff --git a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/NotesDbContextModelSnapshot.cs b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/NotesDbContextModelSnapshot.cs index 95710644..efa377ea 100644 --- a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/NotesDbContextModelSnapshot.cs +++ b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/Migrations/NotesDbContextModelSnapshot.cs @@ -47,6 +47,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LastModifiedBy") .HasColumnType("text"); + b.Property("NodeId") + .HasColumnType("uuid"); + b.Property("Owner") .IsRequired() .HasColumnType("text"); @@ -68,6 +71,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("NodeId"); + b.ToTable("Notes", "Notes"); }); #pragma warning restore 612, 618 diff --git a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/NotesDbContext.cs b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/NotesDbContext.cs index df1e1d8c..6171c44d 100644 --- a/Backend/src/Modules/Notes/Notes.Infrastructure/Data/NotesDbContext.cs +++ b/Backend/src/Modules/Notes/Notes.Infrastructure/Data/NotesDbContext.cs @@ -1,5 +1,6 @@ using Notes.Application.Data.Abstractions; using System.Reflection; +using BuildingBlocks.Domain.Nodes.Node.ValueObjects; using BuildingBlocks.Domain.Notes.Note.ValueObjects; namespace Notes.Infrastructure.Data; @@ -47,7 +48,7 @@ protected override void OnModelCreating(ModelBuilder builder) // Configure NodeId with the value converter entity.Property(r => r.NodeId) - .HasConversion(new NoteIdValueConverter()) // Apply the value converter + .HasConversion(new NodeIdValueConverter()) // Apply the value converter .IsRequired(); });