Implement endpoint to fetch shopping list details by ID including total recipe count
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
using Francesco.Recipes.World.Repositories.ShoppingList;
|
using Francesco.Recipes.World.Repositories.ShoppingList;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
[Route("ShoppingList")]
|
||||||
public class ShoppingListController : Controller
|
public class ShoppingListController : Controller
|
||||||
{
|
{
|
||||||
private readonly IShoppingListRepository _shoppingListRepository;
|
private readonly IShoppingListRepository _shoppingListRepository;
|
||||||
@@ -39,5 +40,33 @@
|
|||||||
|
|
||||||
return Json(new { shoppingListId = shoppingList.Id });
|
return Json(new { shoppingListId = shoppingList.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("RecipeCount")]
|
||||||
|
public async Task<IActionResult> RecipeCount()
|
||||||
|
{
|
||||||
|
var count = await _shoppingListRepository.CountAllRecipeShoppinglistsAsync();
|
||||||
|
return Json(new { count });
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: /ShoppingList/Details/{id}
|
||||||
|
[HttpGet("Details/{id}")]
|
||||||
|
public async Task<IActionResult> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user