From 64c274b0124f32e4e74a720f17f4d1bb4e43bd58 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sat, 4 Jan 2025 20:39:41 +0100 Subject: [PATCH 01/16] feat: implement delete file --- .../Endpoints/Files/DeleteFileAsset.cs | 25 +++++++++++++++++++ .../DeleteFileAsset/DeleteFileAssetCommand.cs | 13 ++++++++++ .../DeleteFileAsset/DeleteFileAssetHandler.cs | 22 ++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs create mode 100644 Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs create mode 100644 Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs diff --git a/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs b/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs new file mode 100644 index 0000000..066afc3 --- /dev/null +++ b/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs @@ -0,0 +1,25 @@ +using Files.Application.Entities.Files.Commands.DeleteFileAsset; + +namespace Files.Api.Endpoints.Files; + +public class DeleteFileAsset : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + app.MapDelete("/Files/{fileId}", async (string fileId, ISender sender) => + { + var result = await sender.Send(new DeleteFileAssetCommand(fileId)); + var response = result.Adapt(); + + return Results.Ok(response); + }) + .WithName("DeleteFileAsset") + .Produces() + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound) + .WithSummary("Delete File Asset") + .WithDescription("Delete File Asset"); + } +} + +public record DeleteFileAssetResponse(bool IsSuccess); diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs new file mode 100644 index 0000000..9655434 --- /dev/null +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs @@ -0,0 +1,13 @@ +namespace Files.Application.Entities.Files.Commands.DeleteFileAsset; + +public record DeleteFileAssetCommand(string FileAssetId) : ICommand; + +public record DeleteFileAssetResult(bool IsSuccess); + +public class DeleteFileAssetCommandValidator : AbstractValidator +{ + public DeleteFileAssetCommandValidator() + { + RuleFor(x => x.FileAssetId).NotEmpty().WithMessage("FileAssetId is required"); + } +} diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs new file mode 100644 index 0000000..5cd6443 --- /dev/null +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs @@ -0,0 +1,22 @@ +using Files.Application.Entities.Files.Exceptions; + +namespace Files.Application.Entities.Files.Commands.DeleteFileAsset; + +public class DeleteFileAssetHandler(IFilesDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteFileAssetCommand command, CancellationToken cancellationToken) + { + var fileAsset = await dbContext.FileAssets + .AsNoTracking() + .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(command.FileAssetId)), cancellationToken); + + if (fileAsset is null) + throw new FileAssetNotFoundException(command.FileAssetId); + + + dbContext.FileAssets.Remove(fileAsset); + await dbContext.SaveChangesAsync(cancellationToken); + + return new DeleteFileAssetResult(true); + } +} From a75924f85aff12a392adf4befc70ab50ef1c90d2 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sat, 4 Jan 2025 20:55:09 +0100 Subject: [PATCH 02/16] feat: implement delete `Node` endpoint --- .../Nodes.Api/Endpoints/Nodes/DeleteNode.cs | 25 +++++++++++++++++++ .../Commands/DeleteNode/DeleteNodeCommand.cs | 13 ++++++++++ .../Commands/DeleteNode/DeleteNodeHandler.cs | 22 ++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs create mode 100644 Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs create mode 100644 Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs diff --git a/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs new file mode 100644 index 0000000..d17d1c5 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs @@ -0,0 +1,25 @@ +using Nodes.Application.Entities.Nodes.Commands.DeleteNode; + +namespace Nodes.Api.Endpoints.Nodes; + +public class DeleteNode : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + app.MapDelete("/Nodes/{nodeId}", async (string nodeId, ISender sender) => + { + var result = await sender.Send(new DeleteNodeCommand(nodeId)); + var response = result.Adapt(); + + return Results.Ok(response); + }) + .WithName("DeleteNode") + .Produces() + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound) + .WithSummary("Delete Node") + .WithDescription("Delete Node"); + } +} + +public record DeleteNodeAssetResponse(bool NodeDeleted); \ No newline at end of file diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs new file mode 100644 index 0000000..3052fe0 --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs @@ -0,0 +1,13 @@ +namespace Nodes.Application.Entities.Nodes.Commands.DeleteNode; + +public record DeleteNodeCommand(string NodeId) : ICommand; + +public record DeleteNodeResult(bool NodeDeleted); + +public class DeleteNodeCommandValidator : AbstractValidator +{ + public DeleteNodeCommandValidator() + { + RuleFor(x => x.NodeId).NotEmpty().WithMessage("NodeId is required"); + } +} diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs new file mode 100644 index 0000000..ff751aa --- /dev/null +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs @@ -0,0 +1,22 @@ +using Nodes.Application.Entities.Nodes.Exceptions; + +namespace Nodes.Application.Entities.Nodes.Commands.DeleteNode; + +public class DeleteFileAssetHandler(INodesDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteNodeCommand command, CancellationToken cancellationToken) + { + var node = await dbContext.Nodes + .AsNoTracking() + .SingleOrDefaultAsync(n => n.Id == NodeId.Of(Guid.Parse(command.NodeId)), cancellationToken); + + if (node is null) + throw new NodeNotFoundException(command.NodeId); + + + dbContext.Nodes.Remove(node); + await dbContext.SaveChangesAsync(cancellationToken); + + return new DeleteNodeResult(true); + } +} From ad0c261a5674d0389311300970d58fc8fec2faa4 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sat, 4 Jan 2025 20:56:04 +0100 Subject: [PATCH 03/16] chore: rename response --- .../Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs | 2 +- .../Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs b/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs index 066afc3..1dab979 100644 --- a/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs +++ b/Backend/src/Modules/Files/Files.Api/Endpoints/Files/DeleteFileAsset.cs @@ -22,4 +22,4 @@ public void AddRoutes(IEndpointRouteBuilder app) } } -public record DeleteFileAssetResponse(bool IsSuccess); +public record DeleteFileAssetResponse(bool FileDeleted); diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs index 9655434..617d27a 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs @@ -2,7 +2,7 @@ public record DeleteFileAssetCommand(string FileAssetId) : ICommand; -public record DeleteFileAssetResult(bool IsSuccess); +public record DeleteFileAssetResult(bool FileDeleted); public class DeleteFileAssetCommandValidator : AbstractValidator { From 38d41e9f6fa74ab305142f9d178cf45ae534afb9 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sun, 5 Jan 2025 08:11:47 +0100 Subject: [PATCH 04/16] chore: rename --- .../Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs | 6 +++--- .../Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs index d17d1c5..2c8f2ce 100644 --- a/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs +++ b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs @@ -9,12 +9,12 @@ public void AddRoutes(IEndpointRouteBuilder app) app.MapDelete("/Nodes/{nodeId}", async (string nodeId, ISender sender) => { var result = await sender.Send(new DeleteNodeCommand(nodeId)); - var response = result.Adapt(); + var response = result.Adapt(); return Results.Ok(response); }) .WithName("DeleteNode") - .Produces() + .Produces() .ProducesProblem(StatusCodes.Status400BadRequest) .ProducesProblem(StatusCodes.Status404NotFound) .WithSummary("Delete Node") @@ -22,4 +22,4 @@ public void AddRoutes(IEndpointRouteBuilder app) } } -public record DeleteNodeAssetResponse(bool NodeDeleted); \ No newline at end of file +public record DeleteNodeResponse(bool NodeDeleted); \ No newline at end of file diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs index ff751aa..2a5a03e 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs @@ -2,7 +2,7 @@ namespace Nodes.Application.Entities.Nodes.Commands.DeleteNode; -public class DeleteFileAssetHandler(INodesDbContext dbContext) : ICommandHandler +public class DeleteNodeHandler(INodesDbContext dbContext) : ICommandHandler { public async Task Handle(DeleteNodeCommand command, CancellationToken cancellationToken) { From ec8ca9445c44a41c3d80a9a03ad7b3ef9a50d005 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sun, 5 Jan 2025 08:12:00 +0100 Subject: [PATCH 05/16] feat: implement delete `Note` endpoint --- .../Notes.Api/Endpoints/Notes/DeleteNote.cs | 25 +++++++++++++++++++ .../Commands/DeleteNote/DeleteNoteCommand.cs | 13 ++++++++++ .../Commands/DeleteNote/DeleteNoteHandler.cs | 22 ++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs create mode 100644 Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs create mode 100644 Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs diff --git a/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs new file mode 100644 index 0000000..8c6f405 --- /dev/null +++ b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs @@ -0,0 +1,25 @@ +using Notes.Application.Entities.Notes.Commands.DeleteNote; + +namespace Notes.Api.Endpoints.Notes; + +public class DeleteNote : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + app.MapDelete("/Notes/{noteId}", async (string noteId, ISender sender) => + { + var result = await sender.Send(new DeleteNoteCommand(noteId)); + var response = result.Adapt(); + + return Results.Ok(response); + }) + .WithName("DeleteNote") + .Produces() + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound) + .WithSummary("Delete Note") + .WithDescription("Delete Note"); + } +} + +public record DeleteNoteResponse(bool NoteDeleted); \ No newline at end of file diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs new file mode 100644 index 0000000..104c88a --- /dev/null +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs @@ -0,0 +1,13 @@ +namespace Notes.Application.Entities.Notes.Commands.DeleteNote; + +public record DeleteNoteCommand(string NoteId) : ICommand; + +public record DeleteNoteResult(bool NoteDeleted); + +public class DeleteNoteCommandValidator : AbstractValidator +{ + public DeleteNoteCommandValidator() + { + RuleFor(x => x.NoteId).NotEmpty().WithMessage("NoteId is required"); + } +} \ No newline at end of file diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs new file mode 100644 index 0000000..44c04b6 --- /dev/null +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs @@ -0,0 +1,22 @@ +using Notes.Application.Entities.Notes.Exceptions; + +namespace Notes.Application.Entities.Notes.Commands.DeleteNote; + +public class DeleteNoteHandler(INotesDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteNoteCommand command, CancellationToken cancellationToken) + { + var note = await dbContext.Notes + .AsNoTracking() + .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(command.NoteId)), cancellationToken); + + if (note is null) + throw new NoteNotFoundException(command.NoteId); + + + dbContext.Notes.Remove(note); + await dbContext.SaveChangesAsync(cancellationToken); + + return new DeleteNoteResult(true); + } +} \ No newline at end of file From 05ccb51d3c56d31848c038935d690b8f2a61861e Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sun, 5 Jan 2025 08:21:54 +0100 Subject: [PATCH 06/16] feat: implement delete `Reminder` endpoint --- .../Endpoints/Reminders/DeleteReminder.cs | 25 +++++++++++++++++++ .../DeleteReminder/DeleteReminderCommand.cs | 13 ++++++++++ .../DeleteReminder/DeleteReminderHandler.cs | 22 ++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Backend/src/Modules/Reminders/Reminders.Api/Endpoints/Reminders/DeleteReminder.cs create mode 100644 Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs create mode 100644 Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs diff --git a/Backend/src/Modules/Reminders/Reminders.Api/Endpoints/Reminders/DeleteReminder.cs b/Backend/src/Modules/Reminders/Reminders.Api/Endpoints/Reminders/DeleteReminder.cs new file mode 100644 index 0000000..598ac5d --- /dev/null +++ b/Backend/src/Modules/Reminders/Reminders.Api/Endpoints/Reminders/DeleteReminder.cs @@ -0,0 +1,25 @@ +using Reminders.Application.Entities.Reminders.Commands.DeleteReminder; + +namespace Reminders.Api.Endpoints.Reminders; + +public class DeleteReminder : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + app.MapDelete("/Reminders/{reminderId}", async (string reminderId, ISender sender) => + { + var result = await sender.Send(new DeleteReminderCommand(reminderId)); + var response = result.Adapt(); + + return Results.Ok(response); + }) + .WithName("DeleteReminder") + .Produces() + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound) + .WithSummary("Delete Reminder") + .WithDescription("Delete Reminder"); + } +} + +public record DeleteReminderResponse(bool ReminderDeleted); diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs new file mode 100644 index 0000000..70b7fa3 --- /dev/null +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs @@ -0,0 +1,13 @@ +namespace Reminders.Application.Entities.Reminders.Commands.DeleteReminder; + +public record DeleteReminderCommand(string ReminderId) : ICommand; + +public record DeleteReminderResult(bool ReminderDeleted); + +public class DeleteReminderCommandValidator : AbstractValidator +{ + public DeleteReminderCommandValidator() + { + RuleFor(x => x.ReminderId).NotEmpty().WithMessage("ReminderId is required"); + } +} diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs new file mode 100644 index 0000000..7f007ba --- /dev/null +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs @@ -0,0 +1,22 @@ +using Reminders.Application.Entities.Reminders.Exceptions; + +namespace Reminders.Application.Entities.Reminders.Commands.DeleteReminder; + +public class DeleteReminderHandler(IRemindersDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteReminderCommand command, CancellationToken cancellationToken) + { + var reminder = await dbContext.Reminders + .AsNoTracking() + .SingleOrDefaultAsync(n => n.Id == ReminderId.Of(Guid.Parse(command.ReminderId)), cancellationToken); + + if (reminder is null) + throw new ReminderNotFoundException(command.ReminderId); + + + dbContext.Reminders.Remove(reminder); + await dbContext.SaveChangesAsync(cancellationToken); + + return new DeleteReminderResult(true); + } +} From 9229e77f4edbf886d87cc5f8d3ae4163c04c4441 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sun, 5 Jan 2025 08:29:55 +0100 Subject: [PATCH 07/16] feat: implement delete `Timeline` endpoint --- .../Nodes.Api/Endpoints/Nodes/DeleteNode.cs | 2 +- .../Endpoints/Timelines/DeleteTimeline.cs | 25 +++++++++++++++++++ .../DeleteTimeline/DeleteTimelineCommand.cs | 13 ++++++++++ .../DeleteTimeline/DeleteTimelineHandler.cs | 22 ++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 Backend/src/Modules/Timelines/Timelines.Api/Endpoints/Timelines/DeleteTimeline.cs create mode 100644 Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs create mode 100644 Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs diff --git a/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs index 2c8f2ce..cc09ee3 100644 --- a/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs +++ b/Backend/src/Modules/Nodes/Nodes.Api/Endpoints/Nodes/DeleteNode.cs @@ -22,4 +22,4 @@ public void AddRoutes(IEndpointRouteBuilder app) } } -public record DeleteNodeResponse(bool NodeDeleted); \ No newline at end of file +public record DeleteNodeResponse(bool NodeDeleted); diff --git a/Backend/src/Modules/Timelines/Timelines.Api/Endpoints/Timelines/DeleteTimeline.cs b/Backend/src/Modules/Timelines/Timelines.Api/Endpoints/Timelines/DeleteTimeline.cs new file mode 100644 index 0000000..248fcc4 --- /dev/null +++ b/Backend/src/Modules/Timelines/Timelines.Api/Endpoints/Timelines/DeleteTimeline.cs @@ -0,0 +1,25 @@ +using Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; + +namespace Timelines.Api.Endpoints.Timelines; + +public class DeleteTimeline : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + app.MapDelete("/Timelines/{timelineId}", async (string timelineId, ISender sender) => + { + var result = await sender.Send(new DeleteTimelineCommand(timelineId)); + var response = result.Adapt(); + + return Results.Ok(response); + }) + .WithName("DeleteTimeline") + .Produces() + .ProducesProblem(StatusCodes.Status400BadRequest) + .ProducesProblem(StatusCodes.Status404NotFound) + .WithSummary("Delete Timeline") + .WithDescription("Delete Timeline"); + } +} + +public record DeleteTimelineResponse(bool TimelineDeleted); diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs new file mode 100644 index 0000000..ae561bb --- /dev/null +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs @@ -0,0 +1,13 @@ +namespace Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; + +public record DeleteTimelineCommand(string TimelineId) : ICommand; + +public record DeleteTimelineResult(bool TimelineDeleted); + +public class DeleteTimelineCommandValidator : AbstractValidator +{ + public DeleteTimelineCommandValidator() + { + RuleFor(x => x.TimelineId).NotEmpty().WithMessage("TimelineId is required"); + } +} diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs new file mode 100644 index 0000000..39b4c64 --- /dev/null +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs @@ -0,0 +1,22 @@ +using Timelines.Application.Entities.Timelines.Exceptions; + +namespace Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; + +public class DeleteNodeHandler(ITimelinesDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteTimelineCommand command, CancellationToken cancellationToken) + { + var timeline = await dbContext.Timelines + .AsNoTracking() + .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(command.TimelineId)), cancellationToken); + + if (timeline is null) + throw new TimelineNotFoundException(command.TimelineId); + + + dbContext.Timelines.Remove(timeline); + await dbContext.SaveChangesAsync(cancellationToken); + + return new DeleteTimelineResult(true); + } +} From e4ca8816bb292575df1fabab9a643fd78be81acc Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Sun, 5 Jan 2025 08:32:12 +0100 Subject: [PATCH 08/16] chore: add empty lines and rename --- .../src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs | 2 +- .../Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs | 2 +- .../Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs | 2 +- .../Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs index 8c6f405..70240ad 100644 --- a/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs +++ b/Backend/src/Modules/Notes/Notes.Api/Endpoints/Notes/DeleteNote.cs @@ -22,4 +22,4 @@ public void AddRoutes(IEndpointRouteBuilder app) } } -public record DeleteNoteResponse(bool NoteDeleted); \ No newline at end of file +public record DeleteNoteResponse(bool NoteDeleted); diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs index 104c88a..4f63a4a 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs @@ -10,4 +10,4 @@ public DeleteNoteCommandValidator() { RuleFor(x => x.NoteId).NotEmpty().WithMessage("NoteId is required"); } -} \ No newline at end of file +} diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs index 44c04b6..657d34f 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs @@ -19,4 +19,4 @@ public async Task Handle(DeleteNoteCommand command, Cancellati return new DeleteNoteResult(true); } -} \ No newline at end of file +} diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs index 7f007ba..1c851ec 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs @@ -8,7 +8,7 @@ public async Task Handle(DeleteReminderCommand command, Ca { var reminder = await dbContext.Reminders .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == ReminderId.Of(Guid.Parse(command.ReminderId)), cancellationToken); + .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(command.ReminderId)), cancellationToken); if (reminder is null) throw new ReminderNotFoundException(command.ReminderId); From 4b75aa68cfce409a889bef3790e4e033ba4a706d Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Mon, 13 Jan 2025 16:32:04 +0100 Subject: [PATCH 09/16] chore: fix formatting & delete redundant empty lines --- .../Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs | 1 - .../Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs | 1 - .../Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs | 1 - .../Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs | 1 - .../Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs | 3 +-- 5 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs index 5cd6443..7e02012 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs @@ -13,7 +13,6 @@ public async Task Handle(DeleteFileAssetCommand command, if (fileAsset is null) throw new FileAssetNotFoundException(command.FileAssetId); - dbContext.FileAssets.Remove(fileAsset); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs index 2a5a03e..31454f5 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs @@ -13,7 +13,6 @@ public async Task Handle(DeleteNodeCommand command, Cancellati if (node is null) throw new NodeNotFoundException(command.NodeId); - dbContext.Nodes.Remove(node); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs index 657d34f..69baba2 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs @@ -13,7 +13,6 @@ public async Task Handle(DeleteNoteCommand command, Cancellati if (note is null) throw new NoteNotFoundException(command.NoteId); - dbContext.Notes.Remove(note); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs index 1c851ec..b34f19c 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs @@ -13,7 +13,6 @@ public async Task Handle(DeleteReminderCommand command, Ca if (reminder is null) throw new ReminderNotFoundException(command.ReminderId); - dbContext.Reminders.Remove(reminder); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs index 39b4c64..e968f60 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs @@ -7,13 +7,12 @@ public class DeleteNodeHandler(ITimelinesDbContext dbContext) : ICommandHandler< public async Task Handle(DeleteTimelineCommand command, CancellationToken cancellationToken) { var timeline = await dbContext.Timelines - .AsNoTracking() + .AsNoTracking() .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(command.TimelineId)), cancellationToken); if (timeline is null) throw new TimelineNotFoundException(command.TimelineId); - dbContext.Timelines.Remove(timeline); await dbContext.SaveChangesAsync(cancellationToken); From 708dd41f94424f31daf8d07ac0a72b9d01b2544b Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Tue, 14 Jan 2025 09:36:20 +0100 Subject: [PATCH 10/16] feat: add validation for `Id` and variable rename --- .../Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs | 6 ++++-- .../Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs index 3052fe0..6f6c370 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs @@ -1,6 +1,6 @@ namespace Nodes.Application.Entities.Nodes.Commands.DeleteNode; -public record DeleteNodeCommand(string NodeId) : ICommand; +public record DeleteNodeCommand(string Id) : ICommand; public record DeleteNodeResult(bool NodeDeleted); @@ -8,6 +8,8 @@ public class DeleteNodeCommandValidator : AbstractValidator { public DeleteNodeCommandValidator() { - RuleFor(x => x.NodeId).NotEmpty().WithMessage("NodeId is required"); + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); } } diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs index 31454f5..b3bac01 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteNodeCommand command, Cancellati { var node = await dbContext.Nodes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NodeId.Of(Guid.Parse(command.NodeId)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == NodeId.Of(Guid.Parse(command.Id)), cancellationToken); if (node is null) - throw new NodeNotFoundException(command.NodeId); + throw new NodeNotFoundException(command.Id); dbContext.Nodes.Remove(node); await dbContext.SaveChangesAsync(cancellationToken); From c8e37a4b7ec27e883c5cfe2cea0e7e5fdb111c03 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Tue, 14 Jan 2025 09:38:37 +0100 Subject: [PATCH 11/16] feat: add validation for `Id` and variable rename for the rest of delete command & handler --- .../Commands/DeleteFileAsset/DeleteFileAssetCommand.cs | 6 ++++-- .../Commands/DeleteFileAsset/DeleteFileAssetHandler.cs | 4 ++-- .../Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs | 6 ++++-- .../Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs | 4 ++-- .../Commands/DeleteReminder/DeleteReminderCommand.cs | 6 ++++-- .../Commands/DeleteReminder/DeleteReminderHandler.cs | 4 ++-- .../Commands/DeleteTimeline/DeleteTimelineCommand.cs | 6 ++++-- .../Commands/DeleteTimeline/DeleteTimelineHandler.cs | 4 ++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs index 617d27a..8baf86c 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs @@ -1,6 +1,6 @@ namespace Files.Application.Entities.Files.Commands.DeleteFileAsset; -public record DeleteFileAssetCommand(string FileAssetId) : ICommand; +public record DeleteFileAssetCommand(string Id) : ICommand; public record DeleteFileAssetResult(bool FileDeleted); @@ -8,6 +8,8 @@ public class DeleteFileAssetCommandValidator : AbstractValidator x.FileAssetId).NotEmpty().WithMessage("FileAssetId is required"); + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); } } diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs index 7e02012..8e7d47e 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteFileAssetCommand command, { var fileAsset = await dbContext.FileAssets .AsNoTracking() - .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(command.FileAssetId)), cancellationToken); + .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(command.Id)), cancellationToken); if (fileAsset is null) - throw new FileAssetNotFoundException(command.FileAssetId); + throw new FileAssetNotFoundException(command.Id); dbContext.FileAssets.Remove(fileAsset); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs index 4f63a4a..4d4931c 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs @@ -1,6 +1,6 @@ namespace Notes.Application.Entities.Notes.Commands.DeleteNote; -public record DeleteNoteCommand(string NoteId) : ICommand; +public record DeleteNoteCommand(string Id) : ICommand; public record DeleteNoteResult(bool NoteDeleted); @@ -8,6 +8,8 @@ public class DeleteNoteCommandValidator : AbstractValidator { public DeleteNoteCommandValidator() { - RuleFor(x => x.NoteId).NotEmpty().WithMessage("NoteId is required"); + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); } } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs index 69baba2..e07f326 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteNoteCommand command, Cancellati { var note = await dbContext.Notes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(command.NoteId)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(command.Id)), cancellationToken); if (note is null) - throw new NoteNotFoundException(command.NoteId); + throw new NoteNotFoundException(command.Id); dbContext.Notes.Remove(note); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs index 70b7fa3..93df917 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs @@ -1,6 +1,6 @@ namespace Reminders.Application.Entities.Reminders.Commands.DeleteReminder; -public record DeleteReminderCommand(string ReminderId) : ICommand; +public record DeleteReminderCommand(string Id) : ICommand; public record DeleteReminderResult(bool ReminderDeleted); @@ -8,6 +8,8 @@ public class DeleteReminderCommandValidator : AbstractValidator x.ReminderId).NotEmpty().WithMessage("ReminderId is required"); + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); } } diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs index b34f19c..27bfc5c 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteReminderCommand command, Ca { var reminder = await dbContext.Reminders .AsNoTracking() - .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(command.ReminderId)), cancellationToken); + .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(command.Id)), cancellationToken); if (reminder is null) - throw new ReminderNotFoundException(command.ReminderId); + throw new ReminderNotFoundException(command.Id); dbContext.Reminders.Remove(reminder); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs index ae561bb..ab6299e 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs @@ -1,6 +1,6 @@ namespace Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; -public record DeleteTimelineCommand(string TimelineId) : ICommand; +public record DeleteTimelineCommand(string Id) : ICommand; public record DeleteTimelineResult(bool TimelineDeleted); @@ -8,6 +8,8 @@ public class DeleteTimelineCommandValidator : AbstractValidator x.TimelineId).NotEmpty().WithMessage("TimelineId is required"); + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); } } diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs index e968f60..a6e8754 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteTimelineCommand command, Ca { var timeline = await dbContext.Timelines .AsNoTracking() - .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(command.TimelineId)), cancellationToken); + .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(command.Id)), cancellationToken); if (timeline is null) - throw new TimelineNotFoundException(command.TimelineId); + throw new TimelineNotFoundException(command.Id); dbContext.Timelines.Remove(timeline); await dbContext.SaveChangesAsync(cancellationToken); From f08f8e6a9d103ed5d3cfd60df27c528bcd7d6740 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Tue, 14 Jan 2025 11:17:21 +0100 Subject: [PATCH 12/16] feat: Validate Ids sent as part of requests for the rest of the modules --- .../GetFileAssetByIdHandler.cs | 6 ++++-- .../GetFileAssetById/GetFileAssetByIdQuery.cs | 15 +++++++++++++- .../Queries/GetNoteById/GetNoteByIdHandler.cs | 6 ++++-- .../Queries/GetNoteById/GetNoteByIdQuery.cs | 20 +++++++++++++++++-- .../GetReminderById/GetReminderByIdHandler.cs | 6 ++++-- .../GetReminderById/GetReminderByIdQuery.cs | 15 +++++++++++++- .../GetTimelineById/GetTimelineByIdHandler.cs | 6 ++++-- .../GetTimelineById/GetTimelineByIdQuery.cs | 15 +++++++++++++- 8 files changed, 76 insertions(+), 13 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs index 52a584b..d1d6b9c 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs @@ -7,12 +7,14 @@ internal class GetFileAssetByIdHandler(IFilesDbContext dbContext) : IQueryHandle { public async Task Handle(GetFileAssetByIdQuery query, CancellationToken cancellationToken) { + var fileAssetId = query.Id.ToString(); + var fileAsset = await dbContext.FileAssets .AsNoTracking() - .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(query.Id)), cancellationToken); + .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(fileAssetId)), cancellationToken); if (fileAsset is null) - throw new FileAssetNotFoundException(query.Id); + throw new FileAssetNotFoundException(fileAssetId); return new GetFileAssetByIdResult(fileAsset.ToFileAssetDto()); } diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs index 53bcf99..bf9d525 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs @@ -4,7 +4,20 @@ namespace Files.Application.Entities.Files.Queries.GetFileAssetById; -public record GetFileAssetByIdQuery(string Id) : IQuery; +public record GetFileAssetByIdQuery(FileAssetId Id) : IQuery +{ + public GetFileAssetByIdQuery(string Id) : this(FileAssetId.Of(Guid.Parse(Id))) { } +} // ReSharper disable once NotAccessedPositionalProperty.Global public record GetFileAssetByIdResult(FileAssetDto FileAssetDto); + +public class GetFileAssetByIdQueryValidator : AbstractValidator +{ + public GetFileAssetByIdQueryValidator() + { + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); + } +} diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs index a98d648..4e507ef 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs @@ -7,12 +7,14 @@ internal class GetNoteByIdHandler(INotesDbContext dbContext) : IQueryHandler Handle(GetNoteByIdQuery query, CancellationToken cancellationToken) { + var noteId = query.Id.ToString(); + var note = await dbContext.Notes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(query.Id)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(noteId)), cancellationToken); if (note is null) - throw new NoteNotFoundException(query.Id); + throw new NoteNotFoundException(noteId); return new GetNoteByIdResult(note.ToNoteDto()); } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs index 7d7c8be..ca7e6d6 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs @@ -1,7 +1,23 @@ -using Notes.Application.Entities.Notes.Dtos; +// ReSharper disable ClassNeverInstantiated.Global + +using Notes.Application.Entities.Notes.Dtos; namespace Notes.Application.Entities.Notes.Queries.GetNoteById; -public record GetNoteByIdQuery(string Id) : IQuery; +public record GetNoteByIdQuery(NoteId Id) : IQuery +{ + public GetNoteByIdQuery(string Id) : this(NoteId.Of(Guid.Parse(Id))) { } +} +// ReSharper disable once NotAccessedPositionalProperty.Global public record GetNoteByIdResult(NoteDto NoteDto); + +public class GetNoteByIdQueryValidator : AbstractValidator +{ + public GetNoteByIdQueryValidator() + { + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); + } +} diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs index 4089172..d29be53 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs @@ -7,12 +7,14 @@ internal class GetReminderByIdHandler(IRemindersDbContext dbContext) : IQueryHan { public async Task Handle(GetReminderByIdQuery query, CancellationToken cancellationToken) { + var reminderId = query.Id.ToString(); + var reminder = await dbContext.Reminders .AsNoTracking() - .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(query.Id)), cancellationToken); + .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(reminderId)), cancellationToken); if (reminder is null) - throw new ReminderNotFoundException(query.Id); + throw new ReminderNotFoundException(reminderId); return new GetReminderByIdResult(reminder.ToReminderDto()); } diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs index 8be8cc8..1a6108d 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs @@ -4,7 +4,20 @@ namespace Reminders.Application.Entities.Reminders.Queries.GetReminderById; -public record GetReminderByIdQuery(string Id) : IQuery; +public record GetReminderByIdQuery(ReminderId Id) : IQuery +{ + public GetReminderByIdQuery(string Id) : this(ReminderId.Of(Guid.Parse(Id))) { } +} // ReSharper disable once NotAccessedPositionalProperty.Global public record GetReminderByIdResult(ReminderDto ReminderDto); + +public class GetReminderByIdQueryValidator : AbstractValidator +{ + public GetReminderByIdQueryValidator() + { + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); + } +} diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs index f31d0b6..69eb9c3 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs @@ -7,12 +7,14 @@ internal class GetTimelineByIdHandler(ITimelinesDbContext dbContext) : IQueryHan { public async Task Handle(GetTimelineByIdQuery query, CancellationToken cancellationToken) { + var timelineId = query.Id.ToString(); + var timeline = await dbContext.Timelines .AsNoTracking() - .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(query.Id)), cancellationToken); + .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(timelineId)), cancellationToken); if (timeline is null) - throw new TimelineNotFoundException(query.Id); + throw new TimelineNotFoundException(timelineId); return new GetTimelineByIdResult(timeline.ToTimelineDto()); } diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs index 9e07fb5..17a3fa2 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs @@ -4,7 +4,20 @@ namespace Timelines.Application.Entities.Timelines.Queries.GetTimelineById; -public record GetTimelineByIdQuery(string Id) : IQuery; +public record GetTimelineByIdQuery(TimelineId Id) : IQuery +{ + public GetTimelineByIdQuery(string Id) : this(TimelineId.Of(Guid.Parse(Id))) { } +} // ReSharper disable once NotAccessedPositionalProperty.Global public record GetTimelineByIdResult(TimelineDto TimelineDto); + +public class GetTimelineByIdQueryValidator : AbstractValidator +{ + public GetTimelineByIdQueryValidator() + { + RuleFor(x => x.Id) + .NotEmpty().WithMessage("Id is required.") + .Must(value => Guid.TryParse(value.ToString(), out _)).WithMessage("Id is not valid."); + } +} From 14263e493a8be8ad866ccd13b46aa8fad61b4fcf Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Wed, 15 Jan 2025 12:30:48 +0100 Subject: [PATCH 13/16] chore: remove variable and make adjustments to GetByIdHandlers --- .../Queries/GetFileAssetById/GetFileAssetByIdHandler.cs | 6 ++---- .../Nodes/Queries/GetNodeById/GetNodeByIdHandler.cs | 6 ++---- .../Notes/Queries/GetNoteById/GetNoteByIdHandler.cs | 6 ++---- .../Queries/GetReminderById/GetReminderByIdHandler.cs | 6 ++---- .../Queries/GetTimelineById/GetTimelineByIdHandler.cs | 6 ++---- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs index d1d6b9c..dff0115 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdHandler.cs @@ -7,14 +7,12 @@ internal class GetFileAssetByIdHandler(IFilesDbContext dbContext) : IQueryHandle { public async Task Handle(GetFileAssetByIdQuery query, CancellationToken cancellationToken) { - var fileAssetId = query.Id.ToString(); - var fileAsset = await dbContext.FileAssets .AsNoTracking() - .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(fileAssetId)), cancellationToken); + .SingleOrDefaultAsync(f => f.Id == query.Id, cancellationToken); if (fileAsset is null) - throw new FileAssetNotFoundException(fileAssetId); + throw new FileAssetNotFoundException(query.Id.ToString()); return new GetFileAssetByIdResult(fileAsset.ToFileAssetDto()); } diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdHandler.cs index 279532a..ee239da 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdHandler.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdHandler.cs @@ -7,14 +7,12 @@ internal class GetNodeByIdHandler(INodesDbContext dbContext) : IQueryHandler Handle(GetNodeByIdQuery query, CancellationToken cancellationToken) { - var nodeId = query.Id.ToString(); - var node = await dbContext.Nodes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NodeId.Of(Guid.Parse(nodeId)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == query.Id, cancellationToken); if (node is null) - throw new NodeNotFoundException(nodeId); + throw new NodeNotFoundException(query.Id.ToString()); return new GetNodeByIdResult(node.ToNodeDto()); } diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs index 4e507ef..af1f6df 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdHandler.cs @@ -7,14 +7,12 @@ internal class GetNoteByIdHandler(INotesDbContext dbContext) : IQueryHandler Handle(GetNoteByIdQuery query, CancellationToken cancellationToken) { - var noteId = query.Id.ToString(); - var note = await dbContext.Notes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(noteId)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == query.Id, cancellationToken); if (note is null) - throw new NoteNotFoundException(noteId); + throw new NoteNotFoundException(query.Id.ToString()); return new GetNoteByIdResult(note.ToNoteDto()); } diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs index d29be53..321d50d 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdHandler.cs @@ -7,14 +7,12 @@ internal class GetReminderByIdHandler(IRemindersDbContext dbContext) : IQueryHan { public async Task Handle(GetReminderByIdQuery query, CancellationToken cancellationToken) { - var reminderId = query.Id.ToString(); - var reminder = await dbContext.Reminders .AsNoTracking() - .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(reminderId)), cancellationToken); + .SingleOrDefaultAsync(r => r.Id == query.Id, cancellationToken); if (reminder is null) - throw new ReminderNotFoundException(reminderId); + throw new ReminderNotFoundException(query.Id.ToString()); return new GetReminderByIdResult(reminder.ToReminderDto()); } diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs index 69eb9c3..8f9fef9 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdHandler.cs @@ -7,14 +7,12 @@ internal class GetTimelineByIdHandler(ITimelinesDbContext dbContext) : IQueryHan { public async Task Handle(GetTimelineByIdQuery query, CancellationToken cancellationToken) { - var timelineId = query.Id.ToString(); - var timeline = await dbContext.Timelines .AsNoTracking() - .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(timelineId)), cancellationToken); + .SingleOrDefaultAsync(t => t.Id == query.Id, cancellationToken); if (timeline is null) - throw new TimelineNotFoundException(timelineId); + throw new TimelineNotFoundException(query.Id.ToString()); return new GetTimelineByIdResult(timeline.ToTimelineDto()); } From dbb5f4866fb54b7bb721e089af3317406bf109c4 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Wed, 15 Jan 2025 12:36:53 +0100 Subject: [PATCH 14/16] chore: add empty line after ReSharper comment in GetByIdQuery files --- .../Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs | 1 + .../Entities/Nodes/Queries/GetNodeById/GetNodeByIdQuery.cs | 1 + .../Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs | 1 + .../Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs | 1 + .../Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs | 1 + 5 files changed, 5 insertions(+) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs index bf9d525..7f8ca5a 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Queries/GetFileAssetById/GetFileAssetByIdQuery.cs @@ -10,6 +10,7 @@ public GetFileAssetByIdQuery(string Id) : this(FileAssetId.Of(Guid.Parse(Id))) { } // ReSharper disable once NotAccessedPositionalProperty.Global + public record GetFileAssetByIdResult(FileAssetDto FileAssetDto); public class GetFileAssetByIdQueryValidator : AbstractValidator diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdQuery.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdQuery.cs index 5a3b6e6..289a736 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdQuery.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/GetNodeById/GetNodeByIdQuery.cs @@ -10,6 +10,7 @@ public GetNodeByIdQuery(string Id) : this(NodeId.Of(Guid.Parse(Id))) { } } // ReSharper disable once NotAccessedPositionalProperty.Global + public record GetNodeByIdResult(NodeDto NodeDto); public class GetNodeByIdQueryValidator : AbstractValidator diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs index ca7e6d6..61aa4d0 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Queries/GetNoteById/GetNoteByIdQuery.cs @@ -10,6 +10,7 @@ public GetNoteByIdQuery(string Id) : this(NoteId.Of(Guid.Parse(Id))) { } } // ReSharper disable once NotAccessedPositionalProperty.Global + public record GetNoteByIdResult(NoteDto NoteDto); public class GetNoteByIdQueryValidator : AbstractValidator diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs index 1a6108d..cc70f76 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Queries/GetReminderById/GetReminderByIdQuery.cs @@ -10,6 +10,7 @@ public GetReminderByIdQuery(string Id) : this(ReminderId.Of(Guid.Parse(Id))) { } } // ReSharper disable once NotAccessedPositionalProperty.Global + public record GetReminderByIdResult(ReminderDto ReminderDto); public class GetReminderByIdQueryValidator : AbstractValidator diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs index 17a3fa2..0868f8c 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Queries/GetTimelineById/GetTimelineByIdQuery.cs @@ -10,6 +10,7 @@ public GetTimelineByIdQuery(string Id) : this(TimelineId.Of(Guid.Parse(Id))) { } } // ReSharper disable once NotAccessedPositionalProperty.Global + public record GetTimelineByIdResult(TimelineDto TimelineDto); public class GetTimelineByIdQueryValidator : AbstractValidator From 208c22fb993c607feff2feb08573cad8d0201353 Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Wed, 15 Jan 2025 13:09:49 +0100 Subject: [PATCH 15/16] refactor: make delete commands strongly typed --- .../Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs | 5 ++++- .../Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs | 4 ++-- .../Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs | 5 ++++- .../Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs | 4 ++-- .../Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs | 5 ++++- .../Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs | 4 ++-- .../Commands/DeleteReminder/DeleteReminderCommand.cs | 5 ++++- .../Commands/DeleteReminder/DeleteReminderHandler.cs | 4 ++-- .../Commands/DeleteTimeline/DeleteTimelineCommand.cs | 5 ++++- .../Commands/DeleteTimeline/DeleteTimelineHandler.cs | 4 ++-- 10 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs index 8baf86c..cce4416 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetCommand.cs @@ -1,6 +1,9 @@ namespace Files.Application.Entities.Files.Commands.DeleteFileAsset; -public record DeleteFileAssetCommand(string Id) : ICommand; +public record DeleteFileAssetCommand(FileAssetId Id) : ICommand +{ + public DeleteFileAssetCommand(string Id) : this(FileAssetId.Of(Guid.Parse(Id))) { } +} public record DeleteFileAssetResult(bool FileDeleted); diff --git a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs index 8e7d47e..183d6b8 100644 --- a/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs +++ b/Backend/src/Modules/Files/Files.Application/Entities/Files/Commands/DeleteFileAsset/DeleteFileAssetHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteFileAssetCommand command, { var fileAsset = await dbContext.FileAssets .AsNoTracking() - .SingleOrDefaultAsync(f => f.Id == FileAssetId.Of(Guid.Parse(command.Id)), cancellationToken); + .SingleOrDefaultAsync(f => f.Id == command.Id, cancellationToken); if (fileAsset is null) - throw new FileAssetNotFoundException(command.Id); + throw new FileAssetNotFoundException(command.Id.ToString()); dbContext.FileAssets.Remove(fileAsset); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs index 6f6c370..645c4cb 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeCommand.cs @@ -1,6 +1,9 @@ namespace Nodes.Application.Entities.Nodes.Commands.DeleteNode; -public record DeleteNodeCommand(string Id) : ICommand; +public record DeleteNodeCommand(NodeId Id) : ICommand +{ + public DeleteNodeCommand(string Id) : this(NodeId.Of(Guid.Parse(Id))) { } +} public record DeleteNodeResult(bool NodeDeleted); diff --git a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs index b3bac01..1106ae3 100644 --- a/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs +++ b/Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/DeleteNode/DeleteNodeHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteNodeCommand command, Cancellati { var node = await dbContext.Nodes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NodeId.Of(Guid.Parse(command.Id)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == command.Id, cancellationToken); if (node is null) - throw new NodeNotFoundException(command.Id); + throw new NodeNotFoundException(command.Id.ToString()); dbContext.Nodes.Remove(node); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs index 4d4931c..8cac44d 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteCommand.cs @@ -1,6 +1,9 @@ namespace Notes.Application.Entities.Notes.Commands.DeleteNote; -public record DeleteNoteCommand(string Id) : ICommand; +public record DeleteNoteCommand(NoteId Id) : ICommand +{ + public DeleteNoteCommand(string Id) : this(NoteId.Of(Guid.Parse(Id))) { } +} public record DeleteNoteResult(bool NoteDeleted); diff --git a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs index e07f326..d281bfd 100644 --- a/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs +++ b/Backend/src/Modules/Notes/Notes.Application/Entities/Notes/Commands/DeleteNote/DeleteNoteHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteNoteCommand command, Cancellati { var note = await dbContext.Notes .AsNoTracking() - .SingleOrDefaultAsync(n => n.Id == NoteId.Of(Guid.Parse(command.Id)), cancellationToken); + .SingleOrDefaultAsync(n => n.Id == command.Id, cancellationToken); if (note is null) - throw new NoteNotFoundException(command.Id); + throw new NoteNotFoundException(command.Id.ToString()); dbContext.Notes.Remove(note); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs index 93df917..5d22e5c 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderCommand.cs @@ -1,6 +1,9 @@ namespace Reminders.Application.Entities.Reminders.Commands.DeleteReminder; -public record DeleteReminderCommand(string Id) : ICommand; +public record DeleteReminderCommand(ReminderId Id) : ICommand +{ + public DeleteReminderCommand(string Id) : this(ReminderId.Of(Guid.Parse(Id))) { } +} public record DeleteReminderResult(bool ReminderDeleted); diff --git a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs index 27bfc5c..24ef323 100644 --- a/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs +++ b/Backend/src/Modules/Reminders/Reminders.Application/Entities/Reminders/Commands/DeleteReminder/DeleteReminderHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteReminderCommand command, Ca { var reminder = await dbContext.Reminders .AsNoTracking() - .SingleOrDefaultAsync(r => r.Id == ReminderId.Of(Guid.Parse(command.Id)), cancellationToken); + .SingleOrDefaultAsync(r => r.Id == command.Id, cancellationToken); if (reminder is null) - throw new ReminderNotFoundException(command.Id); + throw new ReminderNotFoundException(command.Id.ToString()); dbContext.Reminders.Remove(reminder); await dbContext.SaveChangesAsync(cancellationToken); diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs index ab6299e..32b7874 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineCommand.cs @@ -1,6 +1,9 @@ namespace Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; -public record DeleteTimelineCommand(string Id) : ICommand; +public record DeleteTimelineCommand(TimelineId Id) : ICommand +{ + public DeleteTimelineCommand(string Id) : this(TimelineId.Of(Guid.Parse(Id))) { } +} public record DeleteTimelineResult(bool TimelineDeleted); diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs index a6e8754..305faa7 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs @@ -8,10 +8,10 @@ public async Task Handle(DeleteTimelineCommand command, Ca { var timeline = await dbContext.Timelines .AsNoTracking() - .SingleOrDefaultAsync(t => t.Id == TimelineId.Of(Guid.Parse(command.Id)), cancellationToken); + .SingleOrDefaultAsync(t => t.Id == command.Id, cancellationToken); if (timeline is null) - throw new TimelineNotFoundException(command.Id); + throw new TimelineNotFoundException(command.Id.ToString()); dbContext.Timelines.Remove(timeline); await dbContext.SaveChangesAsync(cancellationToken); From 3dc8612d5ac17d4a110f33cfcf13ede67a3b3f7c Mon Sep 17 00:00:00 2001 From: Hunor Tot-Bagi Date: Thu, 16 Jan 2025 06:22:29 +0100 Subject: [PATCH 16/16] fix: rename class --- .../Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs index 305faa7..731e7cc 100644 --- a/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs +++ b/Backend/src/Modules/Timelines/Timelines.Application/Entities/Timelines/Commands/DeleteTimeline/DeleteTimelineHandler.cs @@ -2,7 +2,7 @@ namespace Timelines.Application.Entities.Timelines.Commands.DeleteTimeline; -public class DeleteNodeHandler(ITimelinesDbContext dbContext) : ICommandHandler +public class DeleteTimelineHandler(ITimelinesDbContext dbContext) : ICommandHandler { public async Task Handle(DeleteTimelineCommand command, CancellationToken cancellationToken) {