feat: Add AutoMapper mappings for Codecrete Bill to DTOs
- Add Bill -> SwissQrBillDto mapping - Add Address -> AddressDto mapping - Add AlternativeScheme -> AlternativeSchemeDto mapping - Document AutoMapper policy in comments
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Codecrete.SwissQRBill.Generator;
|
||||||
using DocumentOperator.Application.Common.DTOs;
|
using DocumentOperator.Application.Common.DTOs;
|
||||||
using DocumentOperator.Domain.Models.ValueObjects;
|
using DocumentOperator.Domain.Models.ValueObjects;
|
||||||
using DocumentOperator.Domain.ValueObjects;
|
|
||||||
|
|
||||||
namespace DocumentOperator.Application.Common.Mapping;
|
namespace DocumentOperator.Application.Common.Mapping;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AutoMapper profile for mapping domain entities to DTOs
|
/// AutoMapper profile for mapping domain entities and external models to DTOs.
|
||||||
|
/// NOTE: Always use AutoMapper for all mappings in this project.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MappingProfile : Profile
|
public class MappingProfile : Profile
|
||||||
{
|
{
|
||||||
@@ -19,10 +20,28 @@ public class MappingProfile : Profile
|
|||||||
CreateMap<PdfAMetadata, PdfAValidationResult>()
|
CreateMap<PdfAMetadata, PdfAValidationResult>()
|
||||||
.ForMember(dest => dest.FileSize, opt => opt.MapFrom(src => src.FileSizeBytes));
|
.ForMember(dest => dest.FileSize, opt => opt.MapFrom(src => src.FileSizeBytes));
|
||||||
|
|
||||||
// SwissQrCodeData -> SwissQrCodeDataDto
|
// Codecrete Bill -> SwissQrBillDto
|
||||||
CreateMap<SwissQrCodeData, SwissQrCodeDataDto>();
|
CreateMap<Bill, SwissQrBillDto>()
|
||||||
|
.ForMember(dest => dest.Version, opt => opt.MapFrom(src => src.Version.ToString()))
|
||||||
|
.ForMember(dest => dest.Currency, opt => opt.MapFrom(src => src.Currency ?? "CHF"))
|
||||||
|
.ForMember(dest => dest.Account, opt => opt.MapFrom(src => src.Account ?? string.Empty))
|
||||||
|
.ForMember(dest => dest.ReferenceType, opt => opt.MapFrom(src => src.ReferenceType ?? Bill.ReferenceTypeNoRef));
|
||||||
|
|
||||||
// AddressData -> AddressDataDto
|
// Codecrete Address -> AddressDto
|
||||||
CreateMap<AddressData, AddressDataDto>();
|
CreateMap<Address, AddressDto>()
|
||||||
|
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type.ToString()))
|
||||||
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? string.Empty))
|
||||||
|
.ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.PostalCode ?? string.Empty))
|
||||||
|
.ForMember(dest => dest.Town, opt => opt.MapFrom(src => src.Town ?? string.Empty))
|
||||||
|
.ForMember(dest => dest.CountryCode, opt => opt.MapFrom(src => src.CountryCode ?? string.Empty))
|
||||||
|
#pragma warning disable CS0618 // Suppress obsolete warning for AddressLine1/2 mapping
|
||||||
|
.ForMember(dest => dest.AddressLine1, opt => opt.MapFrom(src => src.AddressLine1))
|
||||||
|
.ForMember(dest => dest.AddressLine2, opt => opt.MapFrom(src => src.AddressLine2));
|
||||||
|
#pragma warning restore CS0618
|
||||||
|
|
||||||
|
// Codecrete AlternativeScheme -> AlternativeSchemeDto
|
||||||
|
CreateMap<AlternativeScheme, AlternativeSchemeDto>()
|
||||||
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? string.Empty))
|
||||||
|
.ForMember(dest => dest.Instruction, opt => opt.MapFrom(src => src.Instruction ?? string.Empty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user