From e9386f1edda575d06ed4674ef12a09f7c80f026e Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Mon, 7 Oct 2024 10:03:14 +0200 Subject: [PATCH 1/4] Update controller --- 14/umbraco-cms/reference/mapping.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/14/umbraco-cms/reference/mapping.md b/14/umbraco-cms/reference/mapping.md index 058e700ea42..0c5209c0337 100644 --- a/14/umbraco-cms/reference/mapping.md +++ b/14/umbraco-cms/reference/mapping.md @@ -241,13 +241,15 @@ public class ProductComposer : IComposer #endregion -public class ProductsController : UmbracoApiController +[ApiController] +[Route("/umbraco/api/products")] +public class ProductsController : Controller { private readonly IUmbracoMapper _mapper; public ProductsController(IUmbracoMapper mapper) => _mapper = mapper; - [HttpGet] + [HttpGet("getall")] public HttpResponseMessage GetAll() { var products = FakeServiceCall(); @@ -256,7 +258,7 @@ public class ProductsController : UmbracoApiController return Request.CreateResponse(HttpStatusCode.OK, mapped); } - [HttpGet] + [HttpGet("getfirstproduct")] public HttpResponseMessage GetFirstProduct() { var product = FakeServiceCall().First(); From cd2731051ca197fd2b7cc69bd26c419e5204d20b Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Mon, 7 Oct 2024 10:03:41 +0200 Subject: [PATCH 2/4] Delete obsolete message --- 14/umbraco-cms/reference/mapping.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/14/umbraco-cms/reference/mapping.md b/14/umbraco-cms/reference/mapping.md index 0c5209c0337..aa5eb6b33fd 100644 --- a/14/umbraco-cms/reference/mapping.md +++ b/14/umbraco-cms/reference/mapping.md @@ -189,10 +189,6 @@ The analyzer follows the standard analyzer development patterns, and building th Below you will find a full example showing you how to map a collection of type Product to a collection of type ProductDto. -{% hint style="warning" %} -The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15. -{% endhint %} - ```csharp #region Models From 7eaf161634e15c9a1777fce1de2403d5e8ffd5b9 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Mon, 7 Oct 2024 10:05:34 +0200 Subject: [PATCH 3/4] Update v15 --- 15/umbraco-cms/reference/mapping.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/15/umbraco-cms/reference/mapping.md b/15/umbraco-cms/reference/mapping.md index 058e700ea42..aa5eb6b33fd 100644 --- a/15/umbraco-cms/reference/mapping.md +++ b/15/umbraco-cms/reference/mapping.md @@ -189,10 +189,6 @@ The analyzer follows the standard analyzer development patterns, and building th Below you will find a full example showing you how to map a collection of type Product to a collection of type ProductDto. -{% hint style="warning" %} -The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15. -{% endhint %} - ```csharp #region Models @@ -241,13 +237,15 @@ public class ProductComposer : IComposer #endregion -public class ProductsController : UmbracoApiController +[ApiController] +[Route("/umbraco/api/products")] +public class ProductsController : Controller { private readonly IUmbracoMapper _mapper; public ProductsController(IUmbracoMapper mapper) => _mapper = mapper; - [HttpGet] + [HttpGet("getall")] public HttpResponseMessage GetAll() { var products = FakeServiceCall(); @@ -256,7 +254,7 @@ public class ProductsController : UmbracoApiController return Request.CreateResponse(HttpStatusCode.OK, mapped); } - [HttpGet] + [HttpGet("getfirstproduct")] public HttpResponseMessage GetFirstProduct() { var product = FakeServiceCall().First(); From 8591b026cc7e5e731ae129e3a533b2a068e30c07 Mon Sep 17 00:00:00 2001 From: Erik-Jan Westendorp Date: Tue, 8 Oct 2024 16:06:18 +0200 Subject: [PATCH 4/4] Oops --- 14/umbraco-cms/reference/mapping.md | 8 ++++---- 15/umbraco-cms/reference/mapping.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/14/umbraco-cms/reference/mapping.md b/14/umbraco-cms/reference/mapping.md index aa5eb6b33fd..164e604b4fb 100644 --- a/14/umbraco-cms/reference/mapping.md +++ b/14/umbraco-cms/reference/mapping.md @@ -246,21 +246,21 @@ public class ProductsController : Controller public ProductsController(IUmbracoMapper mapper) => _mapper = mapper; [HttpGet("getall")] - public HttpResponseMessage GetAll() + public IActionResult GetAll() { var products = FakeServiceCall(); var mapped = _mapper.MapEnumerable(products); - return Request.CreateResponse(HttpStatusCode.OK, mapped); + return Ok(mapped); } [HttpGet("getfirstproduct")] - public HttpResponseMessage GetFirstProduct() + public IActionResult GetFirstProduct() { var product = FakeServiceCall().First(); var mapped = _mapper.Map(product); - return Request.CreateResponse(HttpStatusCode.OK, mapped); + return Ok(mapped); } private IEnumerable FakeServiceCall() diff --git a/15/umbraco-cms/reference/mapping.md b/15/umbraco-cms/reference/mapping.md index aa5eb6b33fd..164e604b4fb 100644 --- a/15/umbraco-cms/reference/mapping.md +++ b/15/umbraco-cms/reference/mapping.md @@ -246,21 +246,21 @@ public class ProductsController : Controller public ProductsController(IUmbracoMapper mapper) => _mapper = mapper; [HttpGet("getall")] - public HttpResponseMessage GetAll() + public IActionResult GetAll() { var products = FakeServiceCall(); var mapped = _mapper.MapEnumerable(products); - return Request.CreateResponse(HttpStatusCode.OK, mapped); + return Ok(mapped); } [HttpGet("getfirstproduct")] - public HttpResponseMessage GetFirstProduct() + public IActionResult GetFirstProduct() { var product = FakeServiceCall().First(); var mapped = _mapper.Map(product); - return Request.CreateResponse(HttpStatusCode.OK, mapped); + return Ok(mapped); } private IEnumerable FakeServiceCall()