Skip to content

Commit 81bc0e1

Browse files
committed
chore: fix command fields
1 parent bb0b05d commit 81bc0e1

File tree

7 files changed

+51
-38
lines changed

7 files changed

+51
-38
lines changed

Backend/src/Modules/Nodes/Nodes.Application/Data/NodesService.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Mapster;
66
using Microsoft.Extensions.DependencyInjection;
77
using Nodes.Application.Data.Abstractions;
8-
using Nodes.Application.Entities.Nodes.Extensions;
98

109
namespace Nodes.Application.Data;
1110

@@ -14,7 +13,7 @@ public class NodesService(INodesRepository nodesRepository, IServiceProvider ser
1413
public async Task<NodeDto> GetNodeByIdAsync(NodeId nodeId, CancellationToken cancellationToken)
1514
{
1615
var node = await nodesRepository.GetNodeByIdAsync(nodeId, cancellationToken);
17-
var nodeDto = node.ToNodeDto();
16+
var nodeDto = node.Adapt<NodeDto>();
1817

1918
var remindersService = serviceProvider.GetRequiredService<IRemindersService>();
2019

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
using BuildingBlocks.Domain.Nodes.Node.Dtos;
22
using BuildingBlocks.Domain.Nodes.Node.ValueObjects;
3+
using BuildingBlocks.Domain.Timelines.Timeline.ValueObjects;
34

45
namespace Nodes.Application.Entities.Nodes.Commands.CreateNode;
56

67
// ReSharper disable once ClassNeverInstantiated.Global
7-
public record CreateNodeCommand(NodeDto Node) : ICommand<CreateNodeResult>;
8+
public record CreateNodeCommand : ICommand<CreateNodeResult>
9+
{
10+
public required string Title { get; set; }
11+
public required string Description { get; set; }
12+
public required string Phase { get; set; }
13+
public required DateTime Timestamp { get; set; }
14+
public required int Importance { get; set; }
15+
public required List<string> Categories { get; set; }
16+
public required List<string> Tags { get; set; }
17+
public required TimelineId TimelineId { get; set; }
18+
}
819

920
// ReSharper disable once NotAccessedPositionalProperty.Global
1021
public record CreateNodeResult(NodeId Id);
@@ -13,40 +24,40 @@ public class CreateNodeCommandValidator : AbstractValidator<CreateNodeCommand>
1324
{
1425
public CreateNodeCommandValidator()
1526
{
16-
RuleFor(x => x.Node.Title)
27+
RuleFor(x => x.Title)
1728
.NotEmpty().WithMessage("Title is required.")
1829
.MaximumLength(100).WithMessage("Title must not exceed 100 characters.");
1930

20-
RuleFor(x => x.Node.Description)
31+
RuleFor(x => x.Description)
2132
.NotEmpty().WithMessage("Description is required.")
2233
.MaximumLength(500).WithMessage("Description must not exceed 500 characters.");
2334

24-
RuleFor(x => x.Node.Timestamp)
35+
RuleFor(x => x.Timestamp)
2536
.LessThanOrEqualTo(DateTime.Now).WithMessage("Timestamp cannot be in the future.");
2637

27-
RuleFor(x => x.Node.Importance)
38+
RuleFor(x => x.Importance)
2839
.InclusiveBetween(1, 10).WithMessage("Importance must be between 1 and 10.");
2940

30-
RuleFor(x => x.Node.Phase)
41+
RuleFor(x => x.Phase)
3142
.NotEmpty().WithMessage("Phase is required.");
3243

33-
RuleFor(x => x.Node)
44+
RuleFor(x => x)
3445
.NotNull().WithMessage("Node cannot be null.")
3546
.DependentRules(() =>
3647
{
37-
RuleFor(x => x.Node.Categories)
48+
RuleFor(x => x.Categories)
3849
.Must(categories => categories != null && categories.Count > 0)
3950
.WithMessage("At least one category must be provided.");
4051

41-
RuleFor(x => x.Node.Tags)
52+
RuleFor(x => x.Tags)
4253
.Must(tags => tags != null && tags.Count > 0)
4354
.WithMessage("At least one tag must be provided.");
4455
});
4556

46-
RuleForEach(x => x.Node.Categories)
57+
RuleForEach(x => x.Categories)
4758
.MaximumLength(50).WithMessage("Category must not exceed 50 characters.");
4859

49-
RuleForEach(x => x.Node.Tags)
60+
RuleForEach(x => x.Tags)
5061
.MaximumLength(50).WithMessage("Tag must not exceed 50 characters.");
5162
}
5263
}

Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Commands/CreateNode/CreateNodeHandler.cs

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ public static Node ToNode(this CreateNodeCommand command)
2222
{
2323
return Node.Create(
2424
NodeId.Of(Guid.NewGuid()),
25-
command.Node.Title,
26-
command.Node.Description,
27-
command.Node.Phase,
28-
command.Node.Timestamp,
29-
command.Node.Importance,
30-
command.Node.Categories,
31-
command.Node.Tags
25+
command.Title,
26+
command.Description,
27+
command.Phase,
28+
command.Timestamp,
29+
command.Importance,
30+
command.Categories,
31+
command.Tags,
32+
command.TimelineId
3233
);
3334
}
3435
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using BuildingBlocks.Domain.Nodes.Node.Dtos;
2+
using BuildingBlocks.Domain.Timelines.Timeline.Dtos;
23

34
namespace Nodes.Application.Entities.Nodes.Extensions;
45

56
public static class NodeExtensions
67
{
7-
public static NodeDto ToNodeDto(this Node node)
8+
public static NodeDto ToNodeDto(this Node node, TimelineBaseDto timeline)
89
{
910
return new NodeDto(
1011
node.Id.ToString(),
@@ -14,11 +15,7 @@ public static NodeDto ToNodeDto(this Node node)
1415
node.Importance,
1516
node.Phase,
1617
node.Categories.ToList(),
17-
node.Tags.ToList());
18-
}
19-
20-
public static IEnumerable<NodeDto> ToNodeDtoList(this IEnumerable<Node> nodes)
21-
{
22-
return nodes.Select(ToNodeDto);
18+
node.Tags.ToList(),
19+
timeline);
2320
}
2421
}

Backend/src/Modules/Nodes/Nodes.Application/Entities/Nodes/Queries/ListNodes/ListNodesHandler.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
using BuildingBlocks.Application.Data;
12
using BuildingBlocks.Application.Pagination;
23
using BuildingBlocks.Domain.Nodes.Node.Dtos;
34
using Nodes.Application.Data.Abstractions;
45
using Nodes.Application.Entities.Nodes.Extensions;
56

67
namespace Nodes.Application.Entities.Nodes.Queries.ListNodes;
78

8-
internal class ListNodesHandler(INodesDbContext dbContext) : IQueryHandler<ListNodesQuery, ListNodesResult>
9+
internal class ListNodesHandler(INodesDbContext dbContext, ITimelinesService timelinesService) : IQueryHandler<ListNodesQuery, ListNodesResult>
910
{
1011
// todo: Refactor so that Services are used
1112
public async Task<ListNodesResult> Handle(ListNodesQuery query, CancellationToken cancellationToken)
@@ -22,11 +23,17 @@ public async Task<ListNodesResult> Handle(ListNodesQuery query, CancellationToke
2223
.Take(pageSize)
2324
.ToListAsync(cancellationToken: cancellationToken);
2425

26+
var nodeDtos = nodes.Select(n =>
27+
{
28+
var timeline = timelinesService.GetTimelineBaseDtoAsync(n.TimelineId, cancellationToken).GetAwaiter().GetResult();
29+
return n.ToNodeDto(timeline);
30+
}).ToList();
31+
2532
return new ListNodesResult(
2633
new PaginatedResult<NodeDto>(
2734
pageIndex,
2835
pageSize,
2936
totalCount,
30-
nodes.ToNodeDtoList()));
37+
nodeDtos));
3138
}
3239
}

Backend/src/Modules/Nodes/Nodes.Domain/Models/Node.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public class Node : Aggregate<NodeId>
1919

2020
public required string Title { get; set; }
2121
public required string Description { get; set; }
22+
public required string Phase { get; set; }
2223
public required DateTime Timestamp { get; set; }
2324
public required int Importance { get; set; }
24-
public required string Phase { get; set; }
25+
2526
public List<ReminderId> ReminderIds { get; set; } = [];
2627
public required TimelineId TimelineId { get; set; }
2728

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
using Timelines.Application.Data.Abstractions;
1+
using BuildingBlocks.Application.Data;
22
using Timelines.Application.Entities.Timelines.Exceptions;
3-
using Timelines.Application.Entities.Timelines.Extensions;
43

54
namespace Timelines.Application.Entities.Timelines.Queries.GetTimelineById;
65

7-
internal class GetTimelineByIdHandler(ITimelinesDbContext dbContext) : IQueryHandler<GetTimelineByIdQuery, GetTimelineByIdResult>
6+
internal class GetTimelineByIdHandler(ITimelinesService timelinesService) : IQueryHandler<GetTimelineByIdQuery, GetTimelineByIdResult>
87
{
98
public async Task<GetTimelineByIdResult> Handle(GetTimelineByIdQuery query, CancellationToken cancellationToken)
109
{
11-
var timeline = await dbContext.Timelines
12-
.AsNoTracking()
13-
.SingleOrDefaultAsync(t => t.Id == query.Id, cancellationToken);
10+
var timelineDto = await timelinesService.GetTimelineById(query.Id, cancellationToken);
1411

15-
if (timeline is null)
12+
if (timelineDto is null)
1613
throw new TimelineNotFoundException(query.Id.ToString());
1714

18-
return new GetTimelineByIdResult(timeline.ToTimelineDto());
15+
return new GetTimelineByIdResult(timelineDto);
1916
}
2017
}

0 commit comments

Comments
 (0)