Bit cleanup
This commit is contained in:
@@ -17,4 +17,8 @@
|
||||
<ProjectReference Include="..\Printbase.Domain\Printbase.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Mappings\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using MediatR;
|
||||
using Printbase.Application.Products.Dtos;
|
||||
|
||||
namespace Printbase.Application.Products.Queries;
|
||||
namespace Printbase.Application.Products.Queries.GetProductById;
|
||||
|
||||
public class GetProductByIdQuery(Guid id, bool includeVariants = true) : IRequest<ProductDto?>
|
||||
{
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using AutoMapper;
|
||||
using Printbase.Application.Products.Commands.CreateProduct;
|
||||
using Printbase.Application.Products.Dtos;
|
||||
using Printbase.Domain.Entities.Products;
|
||||
using Printbase.Infrastructure.DbEntities.Products;
|
||||
|
||||
namespace Printbase.Infrastructure.Mapping;
|
||||
|
||||
public class ProductMappingProfile : Profile
|
||||
{
|
||||
public ProductMappingProfile()
|
||||
{
|
||||
CreateMap<ProductDbEntity, Product>()
|
||||
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
|
||||
.ForMember(dest => dest.Variants, opt => opt.MapFrom(src => src.Variants));
|
||||
|
||||
CreateMap<Product, ProductDbEntity>()
|
||||
.ForMember(dest => dest.Type, opt => opt.Ignore()) // Handle in repository
|
||||
.ForMember(dest => dest.Variants, opt => opt.Ignore()); // Handle in repository
|
||||
|
||||
// ProductVariant mapping
|
||||
CreateMap<ProductVariantDbEntity, ProductVariant>()
|
||||
.ForMember(dest => dest.Product, opt => opt.MapFrom(src => src.Product));
|
||||
|
||||
CreateMap<ProductVariant, ProductVariantDbEntity>()
|
||||
.ForMember(dest => dest.Product, opt => opt.Ignore()); // Handle in repository
|
||||
|
||||
// ProductType mapping
|
||||
CreateMap<ProductTypeDbEntity, ProductType>()
|
||||
.ForMember(dest => dest.Group, opt => opt.MapFrom(src => src.Group))
|
||||
.ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.Products));
|
||||
|
||||
CreateMap<ProductType, ProductTypeDbEntity>()
|
||||
.ForMember(dest => dest.Group, opt => opt.Ignore()) // Handle in repository
|
||||
.ForMember(dest => dest.Products, opt => opt.Ignore()); // Handle in repository
|
||||
|
||||
// ProductGroup mapping
|
||||
CreateMap<ProductGroupDbEntity, ProductGroup>()
|
||||
.ForMember(dest => dest.Types, opt => opt.MapFrom(src => src.Types));
|
||||
|
||||
CreateMap<ProductGroup, ProductGroupDbEntity>()
|
||||
.ForMember(dest => dest.Types, opt => opt.Ignore()); // Handle in repository
|
||||
|
||||
// Domain <-> DTO mappings
|
||||
|
||||
// Product to DTO mapping
|
||||
CreateMap<Product, ProductDto>()
|
||||
.ForMember(dest => dest.TypeName, opt => opt.MapFrom(src => src.Type.Name))
|
||||
.ForMember(dest => dest.GroupName, opt => opt.MapFrom(src => src.Type.Group.Name))
|
||||
.ForMember(dest => dest.Variants, opt => opt.MapFrom(src => src.Variants));
|
||||
|
||||
// ProductVariant to DTO mapping
|
||||
CreateMap<ProductVariant, ProductVariantDto>();
|
||||
|
||||
// Command to Domain mappings
|
||||
|
||||
// CreateProductCommand to Product mapping
|
||||
CreateMap<CreateProductCommand, Product>()
|
||||
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Type, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Variants, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.UpdatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.IsActive, opt => opt.Ignore());
|
||||
|
||||
// CreateProductVariantDto to ProductVariant mapping
|
||||
CreateMap<CreateProductVariantDto, ProductVariant>()
|
||||
.ForMember(dest => dest.Id, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.ProductId, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Product, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.CreatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.UpdatedAt, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.IsActive, opt => opt.Ignore());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using AutoMapper;
|
||||
using Printbase.Application.Products.Commands.CreateProduct;
|
||||
using Printbase.Application.Products.Dtos;
|
||||
using Printbase.Domain.Entities.Products;
|
||||
using Printbase.Infrastructure.DbEntities.Products;
|
||||
|
||||
namespace Printbase.Infrastructure.Mappings;
|
||||
|
||||
public class ProductMappingProfile : Profile
|
||||
{
|
||||
public ProductMappingProfile()
|
||||
{
|
||||
// Product DbEntity -> Domain Entity
|
||||
CreateMap<ProductDbEntity, Product>()
|
||||
.ForMember(dest => dest.Type,
|
||||
opt => opt.MapFrom(src => src.Type))
|
||||
.ForMember(dest => dest.Variants,
|
||||
opt => opt.MapFrom(src => src.Variants));
|
||||
|
||||
// ProductGroup DbEntity -> Domain Entity
|
||||
CreateMap<ProductGroupDbEntity, ProductGroup>()
|
||||
.ForMember(dest => dest.Types,
|
||||
opt => opt.MapFrom(src => src.Types));
|
||||
|
||||
// ProductType DbEntity -> Domain Entity
|
||||
CreateMap<ProductTypeDbEntity, ProductType>()
|
||||
.ForMember(dest => dest.Group,
|
||||
opt => opt.MapFrom(src => src.Group))
|
||||
.ForMember(dest => dest.Products,
|
||||
opt => opt.MapFrom(src => src.Products));
|
||||
|
||||
// ProductVariant DbEntity -> Domain Entity
|
||||
CreateMap<ProductVariantDbEntity, ProductVariant>()
|
||||
.ForMember(dest => dest.Product,
|
||||
opt => opt.MapFrom(src => src.Product));
|
||||
|
||||
// Product Domain Entity -> DbEntity
|
||||
CreateMap<Product, ProductDbEntity>()
|
||||
.ForMember(dest => dest.Type,
|
||||
opt => opt.Ignore()) // in repo
|
||||
.ForMember(dest => dest.Variants,
|
||||
opt => opt.Ignore()); // in repo
|
||||
|
||||
// ProductVariant Domain Entity -> DbEntity
|
||||
CreateMap<ProductVariant, ProductVariantDbEntity>()
|
||||
.ForMember(dest => dest.Product,
|
||||
opt => opt.Ignore()); // in repo
|
||||
|
||||
// ProductType Domain Entity -> DbEntity
|
||||
CreateMap<ProductType, ProductTypeDbEntity>()
|
||||
.ForMember(dest => dest.Group,
|
||||
opt => opt.Ignore()) // in repo
|
||||
.ForMember(dest => dest.Products,
|
||||
opt => opt.Ignore()); // in repo
|
||||
|
||||
// ProductGroup Domain Entity -> DbEntity
|
||||
CreateMap<ProductGroup, ProductGroupDbEntity>()
|
||||
.ForMember(dest => dest.Types,
|
||||
opt => opt.Ignore()); // in repo
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Printbase.Application.Products.Commands.CreateProduct;
|
||||
using Printbase.Application.Products.Queries;
|
||||
using Printbase.Application.Products.Queries.GetProductById;
|
||||
|
||||
namespace Printbase.WebApi.Controllers;
|
||||
|
||||
@@ -11,7 +12,7 @@ public class ProductsController(IMediator mediator) : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[HttpGet("{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetProductById(Guid id, [FromQuery] bool includeVariants = true)
|
||||
|
||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Printbase.Application.Products.Commands.CreateProduct;
|
||||
using Printbase.Domain.Repositories;
|
||||
using Printbase.Infrastructure.Database;
|
||||
using Printbase.Infrastructure.Mapping;
|
||||
using Printbase.Infrastructure.Mappings;
|
||||
using Printbase.Infrastructure.Repositories;
|
||||
|
||||
namespace Printbase.WebApi;
|
||||
@@ -21,7 +21,6 @@ public static class Startup
|
||||
|
||||
services.AddMediatR(cfg => {
|
||||
cfg.RegisterServicesFromAssembly(typeof(CreateProductCommand).Assembly);
|
||||
|
||||
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||
});
|
||||
|
||||
@@ -30,7 +29,10 @@ public static class Startup
|
||||
services.AddScoped<IProductTypeRepository, ProductTypeRepository>();
|
||||
services.AddScoped<IProductGroupRepository, ProductGroupRepository>();
|
||||
|
||||
services.AddAutoMapper(typeof(ProductMappingProfile).Assembly);
|
||||
services.AddAutoMapper(cfg =>
|
||||
{
|
||||
cfg.AddProfile<ProductMappingProfile>();
|
||||
}, typeof(ProductMappingProfile).Assembly);
|
||||
services.AddSwaggerGen();
|
||||
services.AddControllers();
|
||||
services.AddOpenApi();
|
||||
|
||||
Reference in New Issue
Block a user