Write Controller for testing Data

This commit is contained in:
Francesco D'Amico
2025-03-30 15:53:26 +02:00
parent 5c94402c2f
commit a4c8edb572
7 changed files with 229 additions and 0 deletions
@@ -0,0 +1,43 @@
namespace Francesco.Recipes.World.Controller.Category
{
using Francesco.Recipes.World.Models.BackendModels.Category;
using Francesco.Recipes.World.Models.BackendModels.Recipe;
using Francesco.Recipes.World.Repositories.Category;
using Microsoft.AspNetCore.Mvc;
[Route("Category")]
public class CategoryController : Controller
{
private readonly ICategoryRepository _categoryRepository;
public CategoryController(ICategoryRepository categoryRepository)
{
_categoryRepository = categoryRepository;
}
// GET: /Category
[HttpGet]
public async Task<ActionResult<IEnumerable<Category>>> Index()
{
var categories = await _categoryRepository.GetAllCategoriesAsync();
return View(categories);
}
// GET: /Category/{id}
[HttpGet("{id:guid}")]
public async Task<IActionResult> Details(Guid id)
{
var category = await _categoryRepository.GetCategoryByIdAsync(id);
return View(category);
}
// GET: /Category/{id}/recipes
[HttpGet("{id:guid}/recipes")]
public async Task<ActionResult<IEnumerable<Recipe>>> GetRecipesByCategory(Guid id)
{
var recipes = await _categoryRepository.GetRecipesByCategoryAsync(id);
return Ok(recipes);
}
}
}