Skip to content

Commit 00e9222

Browse files
committed
add mapster
1 parent ef4740a commit 00e9222

File tree

31 files changed

+446
-135
lines changed

31 files changed

+446
-135
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"mapster.tool": {
6+
"version": "8.0.1",
7+
"commands": [
8+
"dotnet-mapster"
9+
]
10+
}
11+
}
12+
}

src/BuildingBlocks/CoolStore.AppContracts/CoolStore.AppContracts.csproj

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="Mapster.Core" Version="1.1.5" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
12+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
1013
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.1" />
1114
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="5.0.1" />
1215
<PackageReference Include="RestEase" Version="1.5.2" />
@@ -15,20 +18,32 @@
1518
<PrivateAssets>all</PrivateAssets>
1619
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1720
</PackageReference>
18-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
19-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
21+
2022
</ItemGroup>
2123

2224
<ItemGroup>
25+
<ProjectReference Include="..\..\Customer\CustomerService.Core\CustomerService.Core.csproj" />
26+
<ProjectReference Include="..\..\Product\ProductService.Core\ProductService.Core.csproj" />
27+
<ProjectReference Include="..\..\Setting\SettingService.Core\SettingService.Core.csproj" />
2328
<ProjectReference Include="..\N8T.Core\N8T.Core.csproj" />
2429
<ProjectReference Include="..\N8T.Infrastructure.EfCore\N8T.Infrastructure.EfCore.csproj" />
2530
<ProjectReference Include="..\N8T.Infrastructure.OTel\N8T.Infrastructure.OTel.csproj" />
2631
<ProjectReference Include="..\N8T.Infrastructure\N8T.Infrastructure.csproj" />
2732
</ItemGroup>
2833

2934
<ItemGroup>
30-
<Folder Include="Events\" />
31-
<Folder Include="Requests\" />
35+
<Generated Include="**\*.g.cs" />
3236
</ItemGroup>
3337

38+
<Target Name="CleanGenerated">
39+
<Delete Files="@(Generated)" />
40+
</Target>
41+
42+
<Target Name="Mapster" AfterTargets="AfterBuild">
43+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
44+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n CoolStore.AppContracts.Dtos -o Dtos" />
45+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n CoolStore.AppContracts.Dtos -o Dtos" />
46+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a &quot;$(TargetDir)$(ProjectName).dll&quot; -n CoolStore.AppContracts.Mappers -o Mappers\Generated" />
47+
</Target>
48+
3449
</Project>

src/BuildingBlocks/CoolStore.AppContracts/Dtos/CountryDto.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CoolStore.AppContracts.Dtos
4+
{
5+
public partial class CountryDto
6+
{
7+
public string Name { get; set; }
8+
public Guid Id { get; set; }
9+
public DateTime Created { get; set; }
10+
public DateTime? Updated { get; set; }
11+
}
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Linq.Expressions;
3+
using CoolStore.AppContracts.Dtos;
4+
using SettingService.Core.Entities;
5+
6+
namespace CoolStore.AppContracts.Dtos
7+
{
8+
public static partial class CountryMapper
9+
{
10+
public static CountryDto AdaptToDto(this Country p1)
11+
{
12+
return p1 == null ? null : new CountryDto()
13+
{
14+
Name = p1.Name,
15+
Id = p1.Id,
16+
Created = p1.Created,
17+
Updated = p1.Updated
18+
};
19+
}
20+
public static CountryDto AdaptTo(this Country p2, CountryDto p3)
21+
{
22+
if (p2 == null)
23+
{
24+
return null;
25+
}
26+
CountryDto result = p3 ?? new CountryDto();
27+
28+
result.Name = p2.Name;
29+
result.Id = p2.Id;
30+
result.Created = p2.Created;
31+
result.Updated = p2.Updated;
32+
return result;
33+
34+
}
35+
public static Expression<Func<Country, CountryDto>> ProjectToDto => p4 => new CountryDto()
36+
{
37+
Name = p4.Name,
38+
Id = p4.Id,
39+
Created = p4.Created,
40+
Updated = p4.Updated
41+
};
42+
}
43+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace CoolStore.AppContracts.Dtos
4+
{
5+
public partial class CreditCardDto
6+
{
7+
public string NameOnCard { get; set; }
8+
public string CardNumber { get; set; }
9+
public bool Active { get; set; }
10+
public DateTime Expiry { get; set; }
11+
public Guid Id { get; set; }
12+
public DateTime Created { get; set; }
13+
public DateTime? Updated { get; set; }
14+
}
15+
}

src/BuildingBlocks/CoolStore.AppContracts/Dtos/CustomerDto.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace CoolStore.AppContracts.Dtos
4+
{
5+
public partial class CustomerDto
6+
{
7+
public string FirstName { get; set; }
8+
public string LastName { get; set; }
9+
public string Email { get; set; }
10+
public decimal Balance { get; set; }
11+
public Guid CountryId { get; set; }
12+
public Guid Id { get; set; }
13+
public DateTime Created { get; set; }
14+
public DateTime? Updated { get; set; }
15+
}
16+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Linq.Expressions;
3+
using CoolStore.AppContracts.Dtos;
4+
using CustomerService.Core.Entities;
5+
6+
namespace CoolStore.AppContracts.Dtos
7+
{
8+
public static partial class CustomerMapper
9+
{
10+
public static CustomerDto AdaptToDto(this Customer p1)
11+
{
12+
return p1 == null ? null : new CustomerDto()
13+
{
14+
FirstName = p1.FirstName,
15+
LastName = p1.LastName,
16+
Email = p1.Email,
17+
Balance = p1.Balance,
18+
CountryId = p1.CountryId,
19+
Id = p1.Id,
20+
Created = p1.Created,
21+
Updated = p1.Updated
22+
};
23+
}
24+
public static CustomerDto AdaptTo(this Customer p2, CustomerDto p3)
25+
{
26+
if (p2 == null)
27+
{
28+
return null;
29+
}
30+
CustomerDto result = p3 ?? new CustomerDto();
31+
32+
result.FirstName = p2.FirstName;
33+
result.LastName = p2.LastName;
34+
result.Email = p2.Email;
35+
result.Balance = p2.Balance;
36+
result.CountryId = p2.CountryId;
37+
result.Id = p2.Id;
38+
result.Created = p2.Created;
39+
result.Updated = p2.Updated;
40+
return result;
41+
42+
}
43+
public static Expression<Func<Customer, CustomerDto>> ProjectToDto => p4 => new CustomerDto()
44+
{
45+
FirstName = p4.FirstName,
46+
LastName = p4.LastName,
47+
Email = p4.Email,
48+
Balance = p4.Balance,
49+
CountryId = p4.CountryId,
50+
Id = p4.Id,
51+
Created = p4.Created,
52+
Updated = p4.Updated
53+
};
54+
}
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CoolStore.AppContracts.Dtos
4+
{
5+
public partial class ProductCodeDto
6+
{
7+
public string Name { get; set; }
8+
public Guid Id { get; set; }
9+
public DateTime Created { get; set; }
10+
public DateTime? Updated { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)