Skip to content

Commit 80256cb

Browse files
aminsharifiardalis
andauthored
♻️Refactor: Eliminate legacy CPV SDK and unused build directives from projects (#983)
* ♻️ Refactor(domain): use Vogen value objects for Title & Description. * Refactor: Eliminate legacy CPV SDK and unused build directives from test proje --------- Co-authored-by: Steve Smith <steve@kentsmiths.com>
1 parent 9b0c6f7 commit 80256cb

27 files changed

Lines changed: 120 additions & 123 deletions

File tree

sample/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
55
<TargetFramework>net10.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
68
</PropertyGroup>
79
<PropertyGroup>
810
<NoWarn>1591</NoWarn> <!-- Remove this to turn on warnings for missing XML Comments -->

sample/src/NimblePros.SampleToDo.AspireHost/NimblePros.SampleToDo.AspireHost.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
<PropertyGroup>
66
<OutputType>Exe</OutputType>
7-
<ImplicitUsings>enable</ImplicitUsings>
8-
<Nullable>enable</Nullable>
97
<IsAspireHost>true</IsAspireHost>
108
<UserSecretsId>c540eeb6-e06b-4456-a539-be58dd8b88c7</UserSecretsId>
119
</PropertyGroup>

sample/src/NimblePros.SampleToDo.Core/NimblePros.SampleToDo.Core.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />
3-
4-
<PropertyGroup>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
</PropertyGroup>
8-
92
<ItemGroup>
103
<PackageReference Include="Ardalis.GuardClauses" />
114
<PackageReference Include="Ardalis.Result" />

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/Project.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
1+
using NimblePros.SampleToDo.Core.ContributorAggregate.Events;
2+
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
23

34
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
45

@@ -27,6 +28,7 @@ public Project AddItem(ToDoItem newItem)
2728

2829
public Project UpdateName(ProjectName newName)
2930
{
31+
if (Name.Equals(newName)) return this;
3032
Name = newName;
3133
return this;
3234
}

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/Specifications/IncompleteItemsSearchSpec.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public IncompleteItemsSearchSpec(string searchString)
66
{
77
Query
88
.Where(item => !item.IsDone &&
9-
(item.Title.Contains(searchString) ||
10-
item.Description.Contains(searchString)));
9+
(item.Title.Value.Contains(searchString) ||
10+
item.Description.Value.Contains(searchString)));
1111
}
1212
}

sample/src/NimblePros.SampleToDo.Core/ProjectAggregate/ToDoItem.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NimblePros.SampleToDo.Core.ContributorAggregate;
1+
using System.Xml.Linq;
2+
using NimblePros.SampleToDo.Core.ContributorAggregate;
23
using NimblePros.SampleToDo.Core.ProjectAggregate.Events;
34

45
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
@@ -8,14 +9,19 @@ public class ToDoItem : EntityBase<ToDoItem, ToDoItemId>
89
public ToDoItem() : this(Priority.Backlog)
910
{
1011
}
12+
public ToDoItem(ToDoItemTitle title, ToDoItemDescription description) : this(Priority.Backlog)
13+
{
14+
Title = title;
15+
Description = description;
16+
}
1117

1218
public ToDoItem(Priority priority)
1319
{
1420
Priority = priority;
1521
}
1622

17-
public string Title { get; set; } = string.Empty; // TODO: Use Value Object
18-
public string Description { get; set; } = string.Empty; // TODO: Use Value Object
23+
public ToDoItemTitle Title { get; private set; }
24+
public ToDoItemDescription Description { get; private set; }
1925
public ContributorId? ContributorId { get; private set; } // tasks don't have anyone assigned when first created
2026
public bool IsDone { get; private set; }
2127

@@ -48,9 +54,23 @@ public ToDoItem RemoveContributor()
4854
return this;
4955
}
5056

57+
public ToDoItem UpdateTitle(ToDoItemTitle newTitle)
58+
{
59+
if (Title.Equals(newTitle)) return this;
60+
Title = newTitle;
61+
return this;
62+
}
63+
64+
public ToDoItem UpdateDescription(ToDoItemDescription newDescription)
65+
{
66+
if (Description.Equals(newDescription)) return this;
67+
Description = newDescription;
68+
return this;
69+
}
70+
5171
public override string ToString()
5272
{
5373
string status = IsDone ? "Done!" : "Not done.";
54-
return $"{Id}: Status: {status} - {Title} - Priority: {Priority}";
74+
return $"{Id}: Status: {status} - {Title.Value} - Priority: {Priority}";
5575
}
5676
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Vogen;
2+
3+
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
4+
5+
[ValueObject<string>(conversions: Conversions.SystemTextJson)]
6+
public partial struct ToDoItemDescription
7+
{
8+
public const int MaxLength = 200;
9+
private static Validation Validate(in string description) =>
10+
string.IsNullOrEmpty(description)
11+
? Validation.Invalid("Description cannot be empty")
12+
: description.Length > MaxLength
13+
? Validation.Invalid($"Description cannot be longer than {MaxLength} characters")
14+
: Validation.Ok;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Vogen;
2+
3+
namespace NimblePros.SampleToDo.Core.ProjectAggregate;
4+
5+
[ValueObject<string>(conversions: Conversions.SystemTextJson)]
6+
public partial struct ToDoItemTitle
7+
{
8+
public const int MaxLength = 100;
9+
private static Validation Validate(in string title) =>
10+
string.IsNullOrEmpty(title)
11+
? Validation.Invalid("Title cannot be empty")
12+
: title.Length > MaxLength
13+
? Validation.Invalid($"Title cannot be longer than {MaxLength} characters")
14+
: Validation.Ok;
15+
}

sample/src/NimblePros.SampleToDo.Infrastructure/Data/Config/ToDoItemConfiguration.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ public void Configure(EntityTypeBuilder<ToDoItem> builder)
1111
.HasValueGenerator<VogenIdValueGenerator<AppDbContext, ToDoItem, ToDoItemId>>()
1212
.HasVogenConversion()
1313
.IsRequired();
14-
builder.Property(t => t.Title)
15-
.HasMaxLength(DataSchemaConstants.DEFAULT_NAME_LENGTH)
14+
15+
builder.Property(p => p.Title)
16+
.HasVogenConversion()
17+
.HasMaxLength(ToDoItemTitle.MaxLength)
18+
.IsRequired();
19+
20+
builder.Property(p => p.Description)
21+
.HasVogenConversion()
22+
.HasMaxLength(ToDoItemDescription.MaxLength)
1623
.IsRequired();
17-
builder.Property(t => t.Description)
18-
.HasMaxLength(200);
24+
1925
builder.Property(t => t.ContributorId)
2026
.HasConversion(
2127
v => v.HasValue ? v.Value.Value : (int?)null, // to db

sample/src/NimblePros.SampleToDo.Infrastructure/Data/Config/VogenEfCoreConverters.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ namespace NimblePros.SampleToDo.Infrastructure.Data.Config;
99
[EfCoreConverter<ContributorName>]
1010
[EfCoreConverter<ProjectName>]
1111
[EfCoreConverter<ProjectId>]
12+
[EfCoreConverter<ToDoItemTitle>]
13+
[EfCoreConverter<ToDoItemDescription>]
1214
internal partial class VogenEfCoreConverters;

0 commit comments

Comments
 (0)