diff --git a/src/Printbase.Application/Printbase.Application.csproj b/src/Printbase.Application/Printbase.Application.csproj
index da6040d..e80f671 100644
--- a/src/Printbase.Application/Printbase.Application.csproj
+++ b/src/Printbase.Application/Printbase.Application.csproj
@@ -17,4 +17,8 @@
+
+
+
+
diff --git a/src/Printbase.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs b/src/Printbase.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs
index dea9e4a..6fef39d 100644
--- a/src/Printbase.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs
+++ b/src/Printbase.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs
@@ -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
{
diff --git a/src/Printbase.Infrastructure/Mapping/ProductMappingProfile.cs b/src/Printbase.Infrastructure/Mapping/ProductMappingProfile.cs
deleted file mode 100644
index 8adab9c..0000000
--- a/src/Printbase.Infrastructure/Mapping/ProductMappingProfile.cs
+++ /dev/null
@@ -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()
- .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.Type))
- .ForMember(dest => dest.Variants, opt => opt.MapFrom(src => src.Variants));
-
- CreateMap()
- .ForMember(dest => dest.Type, opt => opt.Ignore()) // Handle in repository
- .ForMember(dest => dest.Variants, opt => opt.Ignore()); // Handle in repository
-
- // ProductVariant mapping
- CreateMap()
- .ForMember(dest => dest.Product, opt => opt.MapFrom(src => src.Product));
-
- CreateMap()
- .ForMember(dest => dest.Product, opt => opt.Ignore()); // Handle in repository
-
- // ProductType mapping
- CreateMap()
- .ForMember(dest => dest.Group, opt => opt.MapFrom(src => src.Group))
- .ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.Products));
-
- CreateMap()
- .ForMember(dest => dest.Group, opt => opt.Ignore()) // Handle in repository
- .ForMember(dest => dest.Products, opt => opt.Ignore()); // Handle in repository
-
- // ProductGroup mapping
- CreateMap()
- .ForMember(dest => dest.Types, opt => opt.MapFrom(src => src.Types));
-
- CreateMap()
- .ForMember(dest => dest.Types, opt => opt.Ignore()); // Handle in repository
-
- // Domain <-> DTO mappings
-
- // Product to DTO mapping
- CreateMap()
- .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();
-
- // Command to Domain mappings
-
- // CreateProductCommand to Product mapping
- CreateMap()
- .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()
- .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());
- }
-}
\ No newline at end of file
diff --git a/src/Printbase.Infrastructure/Mappings/ProductMappingProfile.cs b/src/Printbase.Infrastructure/Mappings/ProductMappingProfile.cs
new file mode 100644
index 0000000..8a7e2ab
--- /dev/null
+++ b/src/Printbase.Infrastructure/Mappings/ProductMappingProfile.cs
@@ -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()
+ .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()
+ .ForMember(dest => dest.Types,
+ opt => opt.MapFrom(src => src.Types));
+
+ // ProductType DbEntity -> Domain Entity
+ CreateMap()
+ .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()
+ .ForMember(dest => dest.Product,
+ opt => opt.MapFrom(src => src.Product));
+
+ // Product Domain Entity -> DbEntity
+ CreateMap()
+ .ForMember(dest => dest.Type,
+ opt => opt.Ignore()) // in repo
+ .ForMember(dest => dest.Variants,
+ opt => opt.Ignore()); // in repo
+
+ // ProductVariant Domain Entity -> DbEntity
+ CreateMap()
+ .ForMember(dest => dest.Product,
+ opt => opt.Ignore()); // in repo
+
+ // ProductType Domain Entity -> DbEntity
+ CreateMap()
+ .ForMember(dest => dest.Group,
+ opt => opt.Ignore()) // in repo
+ .ForMember(dest => dest.Products,
+ opt => opt.Ignore()); // in repo
+
+ // ProductGroup Domain Entity -> DbEntity
+ CreateMap()
+ .ForMember(dest => dest.Types,
+ opt => opt.Ignore()); // in repo
+ }
+}
\ No newline at end of file
diff --git a/src/Printbase.WebApi/Controllers/ProductsController.cs b/src/Printbase.WebApi/Controllers/ProductsController.cs
index acdb870..c635f65 100644
--- a/src/Printbase.WebApi/Controllers/ProductsController.cs
+++ b/src/Printbase.WebApi/Controllers/ProductsController.cs
@@ -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 GetProductById(Guid id, [FromQuery] bool includeVariants = true)
diff --git a/src/Printbase.WebApi/Startup.cs b/src/Printbase.WebApi/Startup.cs
index ec24ff3..000273e 100644
--- a/src/Printbase.WebApi/Startup.cs
+++ b/src/Printbase.WebApi/Startup.cs
@@ -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();
services.AddScoped();
- services.AddAutoMapper(typeof(ProductMappingProfile).Assembly);
+ services.AddAutoMapper(cfg =>
+ {
+ cfg.AddProfile();
+ }, typeof(ProductMappingProfile).Assembly);
services.AddSwaggerGen();
services.AddControllers();
services.AddOpenApi();