From 9c9253c94a5e3da797d14c800280c41b80a7cf72 Mon Sep 17 00:00:00 2001 From: Francesco Lorenzo D'Amico Date: Mon, 19 May 2025 13:23:44 +0200 Subject: [PATCH] Implement endpoint to fetch shopping list details by ID including total recipe count --- .../ShoppingList/ShoppingListController.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Francesco.Recipes.World/Controller/ShoppingList/ShoppingListController.cs b/Francesco.Recipes.World/Controller/ShoppingList/ShoppingListController.cs index 648cc7a..8fe8fca 100644 --- a/Francesco.Recipes.World/Controller/ShoppingList/ShoppingListController.cs +++ b/Francesco.Recipes.World/Controller/ShoppingList/ShoppingListController.cs @@ -5,6 +5,7 @@ using Francesco.Recipes.World.Repositories.ShoppingList; using Microsoft.AspNetCore.Mvc; + [Route("ShoppingList")] public class ShoppingListController : Controller { private readonly IShoppingListRepository _shoppingListRepository; @@ -39,5 +40,33 @@ return Json(new { shoppingListId = shoppingList.Id }); } + + [HttpGet("RecipeCount")] + public async Task RecipeCount() + { + var count = await _shoppingListRepository.CountAllRecipeShoppinglistsAsync(); + return Json(new { count }); + } + + // GET: /ShoppingList/Details/{id} + [HttpGet("Details/{id}")] + public async Task Details(Guid id) + { + var shoppingList = await _shoppingListRepository.GetByIdAsync(id); + var recipeCount = await _shoppingListRepository.CountAllRecipeShoppinglistsAsync(); + + if (shoppingList == null) + { + return NotFound(); + } + + var viewModel = new ShoppingListDetailsViewModel + { + ShoppingList = shoppingList, + RecipeCount = recipeCount, + }; + + return View(viewModel); + } } }