-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SOA-006][Feature] Build DTOs and apply AutoMapperLib (#31)
- Loading branch information
1 parent
2f85a55
commit 68c5486
Showing
31 changed files
with
640 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Contracts.Utilities.Mapper | ||
{ | ||
public interface IMapperService | ||
{ | ||
/// <summary> | ||
/// Execute a mapping from the Source object to a [NEW] Destination object. | ||
/// </summary> | ||
/// <typeparam name="TSource">Source type to use, regardless of the runtime type</typeparam> | ||
/// <typeparam name="TDestination">Destination type to create</typeparam> | ||
/// <param name="source">Source object to map from</param> | ||
/// <returns>Mapped Destination object</returns> | ||
public TDestination Execute<TSource, TDestination>(TSource source); | ||
|
||
/// <summary> | ||
/// Execute a mapping from the Source object to the [EXISTING] Destination object. | ||
/// </summary> | ||
/// <typeparam name="TSource">Source type to use</typeparam> | ||
/// <typeparam name="TDestination">Destination type</typeparam> | ||
/// <param name="source">Source object to map from</param> | ||
/// <param name="destination">Destination object to map into</param> | ||
/// <returns>The mapped Destination object, [SAME] instance as the <paramref name="destination"/> object</returns> | ||
public TDestination Execute<TSource, TDestination>(TSource source, TDestination destination); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Shared.Abstracts | ||
{ | ||
public abstract class AbstractEntityDto | ||
{ | ||
public bool IsDeleted { get; set; } | ||
|
||
public DateTime CreatedDate { get; set; } | ||
|
||
public DateTime UpdatedDate { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Cores/Shared/DTOs/Inputs/FromBody/CreationDtos/CustomerForCreationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.CreationDtos | ||
{ | ||
public sealed class CustomerForCreationDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Cores/Shared/DTOs/Inputs/FromBody/CreationDtos/EmployeeForCreationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.CreationDtos | ||
{ | ||
public sealed class EmployeeForCreationDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Cores/Shared/DTOs/Inputs/FromBody/CreationDtos/ProductForCreationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.CreationDtos | ||
{ | ||
public sealed class ProductForCreationDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Cores/Shared/DTOs/Inputs/FromBody/CreationDtos/StoreForCreationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.CreationDtos | ||
{ | ||
public sealed class StoreForCreationDto | ||
{ | ||
public Guid CompanyId { get; set; } | ||
|
||
public Guid? ManagerId { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Cores/Shared/DTOs/Inputs/FromBody/UpdateDtos/CompanyForUpdateDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.UpdateDtos | ||
{ | ||
public sealed class CompanyForUpdateDto | ||
{ | ||
public string? Name { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Cores/Shared/DTOs/Inputs/FromBody/UpdateDtos/CustomerForUpdateDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.UpdateDtos | ||
{ | ||
public sealed class CustomerForUpdateDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Cores/Shared/DTOs/Inputs/FromBody/UpdateDtos/EmployeeForUpdateDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.UpdateDtos | ||
{ | ||
public sealed class EmployeeForUpdateDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Cores/Shared/DTOs/Inputs/FromBody/UpdateDtos/ProductForUpdateDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.UpdateDtos | ||
{ | ||
public sealed class ProductForUpdateDto | ||
{ | ||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Cores/Shared/DTOs/Inputs/FromBody/UpdateDtos/StoreForUpdateDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Shared.DTOs.Inputs.FromBody.UpdateDtos | ||
{ | ||
public sealed class StoreForUpdateDto | ||
{ | ||
public Guid? ManagerId { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Shared.DTOs.Outputs.EntityDtos | ||
{ | ||
public sealed class CompanyDto : AbstractEntityDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Shared.DTOs.Outputs.EntityDtos | ||
{ | ||
public sealed class CustomerDto : AbstractEntityDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Shared.DTOs.Outputs.EntityDtos | ||
{ | ||
public sealed class EmployeeDto : AbstractEntityDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public Guid? WorkingStoreId { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? FirstName { get; set; } | ||
|
||
public string? LastName { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Shared.DTOs.Outputs.EntityDtos | ||
{ | ||
public sealed class ProductDto : AbstractEntityDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Shared.DTOs.Outputs.EntityDtos | ||
{ | ||
public sealed class StoreDto : AbstractEntityDto | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public Guid CompanyId { get; set; } | ||
|
||
public Guid? ManagerId { get; set; } | ||
|
||
public string? Code { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
public string? Address { get; set; } | ||
|
||
public string? Phone { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Shared.Abstracts; |
25 changes: 25 additions & 0 deletions
25
Implementations/eShopOnlineUtilities/AutoMapper/AutoMapperService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using AutoMapper; | ||
using Contracts.Utilities.Mapper; | ||
|
||
namespace eShopOnlineUtilities.AutoMapper | ||
{ | ||
public sealed class AutoMapperService : IMapperService | ||
{ | ||
private readonly IMapper _autoMapper; | ||
|
||
public AutoMapperService(IMapper autoMapper) | ||
{ | ||
_autoMapper = autoMapper; | ||
} | ||
|
||
public TDestination Execute<TSource, TDestination>(TSource source) | ||
{ | ||
return _autoMapper.Map<TSource, TDestination>(source); | ||
} | ||
|
||
public TDestination Execute<TSource, TDestination>(TSource source, TDestination destination) | ||
{ | ||
return _autoMapper.Map(source, destination); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Implementations/eShopOnlineUtilities/AutoMapper/MappingProfiles.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using AutoMapper; | ||
|
||
namespace eShopOnlineUtilities.AutoMapper.Profiles | ||
{ | ||
public partial class MappingProfiles : Profile | ||
{ | ||
public MappingProfiles() | ||
{ | ||
MappingCompanyProfile(); | ||
MappingCustomerProfile(); | ||
MappingEmployeeProfile(); | ||
MappingProductProfile(); | ||
MappingStoreProfile(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
Implementations/eShopOnlineUtilities/AutoMapper/Profiles/CompanyProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace eShopOnlineUtilities.AutoMapper.Profiles | ||
{ | ||
public partial class MappingProfiles : Profile | ||
{ | ||
private void MappingCompanyProfile() | ||
{ | ||
ReverseMapping_Company_And_CompanyDto(); | ||
ReverseMapping_CompanyForUpdateDto_And_Company(); | ||
} | ||
|
||
private void ReverseMapping_Company_And_CompanyDto() | ||
{ | ||
CreateMap<Company, CompanyDto>().ReverseMap() | ||
.ForMember(right => right.Id, | ||
right_prop => right_prop.MapFrom(left => left.Id)) | ||
.ForMember(right => right.Name, | ||
right_prop => right_prop.MapFrom(left => left.Name)) | ||
.ForMember(right => right.Address, | ||
right_prop => right_prop.MapFrom(left => left.Address)) | ||
.ForMember(right => right.Phone, | ||
right_prop => right_prop.MapFrom(left => left.Phone)) | ||
.ForMember(right => right.IsDeleted, | ||
right_prop => right_prop.MapFrom(left => left.IsDeleted)) | ||
.ForMember(right => right.CreatedDate, | ||
right_prop => right_prop.MapFrom(left => left.CreatedDate)) | ||
.ForMember(right => right.UpdatedDate, | ||
right_prop => right_prop.MapFrom(left => left.UpdatedDate)); | ||
} | ||
|
||
private void ReverseMapping_CompanyForUpdateDto_And_Company() | ||
{ | ||
CreateMap<CompanyForUpdateDto, Company>().ReverseMap() | ||
.ForMember(right => right.Name, | ||
right_prop => right_prop.MapFrom(left => left.Name)) | ||
.ForMember(right => right.Address, | ||
right_prop => right_prop.MapFrom(left => left.Address)) | ||
.ForMember(right => right.Phone, | ||
right_prop => right_prop.MapFrom(left => left.Phone)); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.