Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
using NimblePros.SampleToDo.Core.ContributorAggregate.Events;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;

Expand Down Expand Up @@ -27,6 +28,7 @@ public Project AddItem(ToDoItem newItem)

public Project UpdateName(ProjectName newName)
{
if (Name.Equals(newName)) return this;
Name = newName;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public IncompleteItemsSearchSpec(string searchString)
{
Query
.Where(item => !item.IsDone &&
(item.Title.Contains(searchString) ||
item.Description.Contains(searchString)));
(item.Title.Value.Contains(searchString) ||
item.Description.Value.Contains(searchString)));
}
}
28 changes: 24 additions & 4 deletions sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/ToDoItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NimblePros.SampleToDo.Core.ContributorAggregate;
using System.Xml.Linq;
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;
Expand All @@ -8,14 +9,19 @@ public class ToDoItem : EntityBase<ToDoItem, ToDoItemId>
public ToDoItem() : this(Priority.Backlog)
{
}
public ToDoItem(ToDoItemTitle title, ToDoItemDescription description) : this(Priority.Backlog)
{
Title = title;
Description = description;
}

public ToDoItem(Priority priority)
{
Priority = priority;
}

public string Title { get; set; } = string.Empty; // TODO: Use Value Object
public string Description { get; set; } = string.Empty; // TODO: Use Value Object
public ToDoItemTitle Title { get; private set; }
public ToDoItemDescription Description { get; private set; }
public ContributorId? ContributorId { get; private set; } // tasks don't have anyone assigned when first created
public bool IsDone { get; private set; }

Expand Down Expand Up @@ -48,9 +54,23 @@ public ToDoItem RemoveContributor()
return this;
}

public ToDoItem UpdateTitle(ToDoItemTitle newTitle)
{
if (Title.Equals(newTitle)) return this;
Title = newTitle;
return this;
}

public ToDoItem UpdateDescription(ToDoItemDescription newDescription)
{
if (Description.Equals(newDescription)) return this;
Description = newDescription;
return this;
}

public override string ToString()
{
string status = IsDone ? "Done!" : "Not done.";
return $"{Id}: Status: {status} - {Title} - Priority: {Priority}";
return $"{Id}: Status: {status} - {Title.Value} - Priority: {Priority}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Vogen;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;

[ValueObject<string>(conversions: Conversions.SystemTextJson)]
public partial struct ToDoItemDescription
{
public const int MaxLength = 200;
private static Validation Validate(in string description) =>
string.IsNullOrEmpty(description)
? Validation.Invalid("Description cannot be empty")
: description.Length > MaxLength
? Validation.Invalid($"Description cannot be longer than {MaxLength} characters")
: Validation.Ok;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Vogen;

namespace NimblePros.SampleToDo.Core.ProjectAggregate;

[ValueObject<string>(conversions: Conversions.SystemTextJson)]
public partial struct ToDoItemTitle
{
public const int MaxLength = 100;
private static Validation Validate(in string title) =>
string.IsNullOrEmpty(title)
? Validation.Invalid("Title cannot be empty")
: title.Length > MaxLength
? Validation.Invalid($"Title cannot be longer than {MaxLength} characters")
: Validation.Ok;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ public void Configure(EntityTypeBuilder<ToDoItem> builder)
.HasValueGenerator<VogenIdValueGenerator<AppDbContext, ToDoItem, ToDoItemId>>()
.HasVogenConversion()
.IsRequired();
builder.Property(t => t.Title)
.HasMaxLength(DataSchemaConstants.DEFAULT_NAME_LENGTH)

builder.Property(p => p.Title)
.HasVogenConversion()
.HasMaxLength(ToDoItemTitle.MaxLength)
.IsRequired();

builder.Property(p => p.Description)
.HasVogenConversion()
.HasMaxLength(ToDoItemDescription.MaxLength)
.IsRequired();
builder.Property(t => t.Description)
.HasMaxLength(200);

builder.Property(t => t.ContributorId)
.HasConversion(
v => v.HasValue ? v.Value.Value : (int?)null, // to db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ namespace NimblePros.SampleToDo.Infrastructure.Data.Config;
[EfCoreConverter<ContributorName>]
[EfCoreConverter<ProjectName>]
[EfCoreConverter<ProjectId>]
[EfCoreConverter<ToDoItemTitle>]
[EfCoreConverter<ToDoItemDescription>]
internal partial class VogenEfCoreConverters;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.UseCases.Projects;
using NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.UseCases.Projects;
using NimblePros.SampleToDo.UseCases.Projects.ListShallow;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.UseCases.Projects;
using NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand All @@ -17,7 +17,7 @@ public async Task<IEnumerable<ToDoItemDto>> ListAsync(int projectId)
var projectParameter = new SqlParameter("@projectId", System.Data.SqlDbType.Int);
var result = await _db.ToDoItems.FromSqlRaw("SELECT Id, Title, Description, IsDone, ContributorId FROM ToDoItems WHERE ProjectId = @ProjectId",
projectParameter) // don't fetch other big columns
.Select(x => new ToDoItemDto(x.Id, x.Title, x.Description, x.IsDone, x.ContributorId))
.Select(x => new ToDoItemDto(x.Id, x.Title.Value, x.Description.Value, x.IsDone, x.ContributorId))
.ToListAsync();

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.UseCases.Projects;
using NimblePros.SampleToDo.UseCases.Projects.ListShallow;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;

namespace NimblePros.SampleToDo.Infrastructure.Data.Queries;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using NimblePros.SampleToDo.Infrastructure.Data.Queries;
using NimblePros.SampleToDo.Infrastructure.Email;
using NimblePros.SampleToDo.UseCases.Contributors.Queries.List;
using NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
using NimblePros.SampleToDo.UseCases.Projects.ListShallow;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;
using NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;
using NimblePros.SharedKernel;

namespace NimblePros.SampleToDo.Infrastructure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NimblePros.SampleToDo.Core.ContributorAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.AddToDoItem;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.AddToDoItem;

/// <summary>
/// Creates a new ToDoItem and adds it to a Project
Expand All @@ -12,5 +12,5 @@ namespace NimblePros.SampleToDo.UseCases.Projects.AddToDoItem;
/// <param name="Description"></param>
public record AddToDoItemCommand(ProjectId ProjectId,
ContributorId? ContributorId,
string Title,
string Description) : ICommand<Result<ToDoItemId>>;
ToDoItemTitle Title,
ToDoItemDescription Description) : ICommand<Result<ToDoItemId>>;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

namespace NimblePros.SampleToDo.UseCases.Projects.AddToDoItem;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.AddToDoItem;

public class AddToDoItemHandler : ICommandHandler<AddToDoItemCommand, Result<ToDoItemId>>
{
Expand All @@ -22,13 +22,9 @@ public async ValueTask<Result<ToDoItemId>> Handle(AddToDoItemCommand request,
return Result.NotFound();
}

var newItem = new ToDoItem()
{
Title = request.Title!,
Description = request.Description!
};
var newItem = new ToDoItem(title: request.Title!, description: request.Description!);

if(request.ContributorId.HasValue)
if (request.ContributorId.HasValue)
{
newItem.AddContributor(request.ContributorId.Value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Create;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Create;

/// <summary>
/// Create a new Project.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Create;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Create;

public class CreateProjectHandler(IRepository<Project> repository) : ICommandHandler<CreateProjectCommand, Result<ProjectId>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Delete;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Delete;

public record DeleteProjectCommand(ProjectId ProjectId) : ICommand<Result>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Delete;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Delete;

public class DeleteProjectHandler : ICommandHandler<DeleteProjectCommand, Result>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.MarkToDoItemComplete;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.MarkToDoItemComplete;

/// <summary>
/// Create a new Project.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

namespace NimblePros.SampleToDo.UseCases.Projects.MarkToDoItemComplete;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.MarkToDoItemComplete;

public class MarkToDoItemCompleteHandler : ICommandHandler<MarkToDoItemCompleteCommand, Result>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Update;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Update;

public record UpdateProjectCommand(ProjectId ProjectId, ProjectName NewName) : ICommand<Result<ProjectDto>>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.Update;
namespace NimblePros.SampleToDo.UseCases.Projects.Commands.Update;

public class UpdateProjectHandler : ICommandHandler<UpdateProjectCommand, Result<ProjectDto>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.Core.ProjectAggregate.Specifications;

namespace NimblePros.SampleToDo.UseCases.Projects.GetWithAllItems;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.GetWithAllItems;

/// <summary>
/// Queries don't necessarily need to use repository methods, but they can if it's convenient
Expand All @@ -22,7 +22,7 @@ public async ValueTask<Result<ProjectWithAllItemsDto>> Handle(GetProjectWithAllI
if (project == null) return Result.NotFound();

var items = project.Items
.Select(i => new ToDoItemDto(i.Id, i.Title, i.Description, i.IsDone, i.ContributorId)).ToList();
.Select(i => new ToDoItemDto(i.Id, i.Title.Value, i.Description.Value, i.IsDone, i.ContributorId)).ToList();
return new ProjectWithAllItemsDto(project.Id, project.Name, items, project.Status.ToString())
;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;

namespace NimblePros.SampleToDo.UseCases.Projects.GetWithAllItems;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.GetWithAllItems;

public record GetProjectWithAllItemsQuery(ProjectId ProjectId) :
IQuery<Result<ProjectWithAllItemsDto>>, ICacheable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;

/// <summary>
/// Represents a service that will actually fetch the necessary data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;

public class ListIncompleteItemsByProjectHandler : IQueryHandler<ListIncompleteItemsByProjectQuery, Result<IEnumerable<ToDoItemDto>>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListIncompleteItems;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListIncompleteItems;

public record ListIncompleteItemsByProjectQuery(int ProjectId) :
IQuery<Result<IEnumerable<ToDoItemDto>>>, ICacheable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListShallow;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;

/// <summary>
/// Represents a service that will actually fetch the necessary data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListShallow;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;

public class ListProjectsShallowHandler(IListProjectsShallowQueryService query)
: IQueryHandler<ListProjectsShallowQuery, Result<IEnumerable<ProjectDto>>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NimblePros.SampleToDo.UseCases.Projects.ListShallow;
namespace NimblePros.SampleToDo.UseCases.Projects.Queries.ListShallow;

public record ListProjectsShallowQuery(int? Skip, int? Take) :
IQuery<Result<IEnumerable<ProjectDto>>>, ICacheable
Expand Down
9 changes: 4 additions & 5 deletions sample/src/NimblePros.SampleToDo.Web/CachingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

namespace NimblePros.SampleToDo.Web;

public class CachingBehavior<TRequest, TResponse>(IMemoryCache cache,
ILogger<CachingBehavior<TRequest, TResponse>> logger,
IOptions<CachingOptions> cachingOptions) :
IPipelineBehavior<TRequest, TResponse?>
where TRequest : notnull, IMessage
public class CachingBehavior<TRequest, TResponse>(
IMemoryCache cache,ILogger<CachingBehavior<TRequest, TResponse>> logger,
IOptions<CachingOptions> cachingOptions) :
IPipelineBehavior<TRequest, TResponse?> where TRequest : notnull, IMessage
{
private readonly IMemoryCache _cache = cache;
private readonly ILogger<CachingBehavior<TRequest, TResponse>> _logger = logger;
Expand Down
2 changes: 1 addition & 1 deletion sample/src/NimblePros.SampleToDo.Web/Projects/Create.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NimblePros.SampleToDo.Core.ProjectAggregate;
using NimblePros.SampleToDo.UseCases.Projects.Create;
using NimblePros.SampleToDo.UseCases.Projects.Commands.Create;
using NimblePros.SampleToDo.Web.Extensions;

namespace NimblePros.SampleToDo.Web.Projects;
Expand Down
Loading
Loading