Refactoring some Code and clean Code

This commit is contained in:
franc
2025-04-09 15:37:44 +02:00
parent d248ccb1db
commit 127a60b621
19 changed files with 132 additions and 114 deletions
@@ -1,13 +1,8 @@
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;
[ValidateAntiForgeryToken]
[Route("Category")]
public class CategoryController : Controller
{
private readonly ICategoryRepository _categoryRepository;
@@ -19,7 +14,7 @@
// GET: /Category
[HttpGet]
public async Task<ActionResult<IEnumerable<Category>>> Index()
public async Task<IActionResult> Index()
{
var categories = await _categoryRepository.GetAllCategoriesAsync();
return View(categories);
@@ -29,16 +24,16 @@
[HttpGet("{id:guid}")]
public async Task<IActionResult> Details(Guid id)
{
var category = await _categoryRepository.GetCategoryByIdAsync(id);
return View(category);
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)
public async Task<IActionResult> GetRecipesByCategory(Guid id)
{
var recipes = await _categoryRepository.GetRecipesByCategoryAsync(id);
return View(recipes);
var recipes = await _categoryRepository.GetRecipesByCategoryAsync(id);
return Ok(recipes);
}
}
}