11using AutoMapper ;
22using Microsoft . AspNetCore . Http ;
33using Microsoft . AspNetCore . Mvc ;
4- using Microsoft . AspNetCore . Mvc . Formatters ;
4+ using Microsoft . Extensions . Logging ;
55using ReferenceProject . Repo ;
66using System ;
77using System . Collections . Generic ;
@@ -16,9 +16,11 @@ public class ProductsController: ControllerBase
1616 {
1717 Repo . IProductsRepo ProductsRepo { get ; }
1818 IMapper Mapper { get ; }
19+ ILogger < ProductsController > Logger { get ; }
1920
20- public ProductsController ( Repo . IProductsRepo productsRepo , IMapper mapper )
21+ public ProductsController ( IProductsRepo productsRepo , IMapper mapper , ILogger < ProductsController > logger )
2122 {
23+ Logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
2224 Mapper = mapper ?? throw new ArgumentNullException ( nameof ( mapper ) ) ;
2325 ProductsRepo = productsRepo ?? throw new ArgumentNullException ( nameof ( productsRepo ) ) ;
2426 }
@@ -61,7 +63,12 @@ public IActionResult Create(int id, [FromBody]Dto.UpdateProduct newProductDto)
6163 var newProduct = new Model . Product ( id ) ;
6264 Mapper . Map ( newProductDto , newProduct ) ;
6365 ProductsRepo . Create ( newProduct ) ;
64- return Created ( $ "{ id } ", Mapper . Map < Dto . Product > ( ProductsRepo . GetById ( id ) ) ) ;
66+
67+ var createdProduct = ProductsRepo . GetById ( id ) ;
68+
69+ Logger . LogInformation ( "New product was created: {@product}" , createdProduct ) ;
70+
71+ return Created ( $ "{ id } ", Mapper . Map < Dto . Product > ( createdProduct ) ) ;
6572 }
6673
6774 /// <summary>
0 commit comments