Clean the code and put Index EndPoint

This commit is contained in:
franc
2025-04-16 15:19:33 +02:00
parent b8814ce708
commit 1110c74234
2 changed files with 16 additions and 6 deletions
@@ -1,4 +1,4 @@
namespace Francesco.Recipes.World.Controller.Home
namespace Francesco.Recipes.World.Controller.HomeController
{
using Francesco.Recipes.World.Repositories.Category;
using Francesco.Recipes.World.Repositories.Recipe;
@@ -6,19 +6,26 @@
public class HomeController : Controller
{
private readonly ICategoryRepository _categoryRepository;
private readonly IRecipeRepository _recipeRepository;
private readonly ICategoryRepository _categoryRepository;
public HomeController(ICategoryRepository categoryRepository, IRecipeRepository recipeRepository)
{
_categoryRepository = categoryRepository;
_recipeRepository = recipeRepository;
_categoryRepository = categoryRepository;
}
[HttpGet]
public async Task<IActionResult> Index()
{
var categories = await _categoryRepository.GetAllCategoriesWithRecipesAsync();
return View("Index", categories);
}
[HttpGet("/Home/Search")]
public async Task<IActionResult> Search(string query)
{
var recipes = await _recipeRepository.GetRecipesBySearchQueryAsync(query);
var recipes = await _recipeRepository.SerachRecipeAndIngredientAsync(query);
return PartialView("_SearchResultsPartial", recipes);
}
}
@@ -1,6 +1,7 @@
@model IEnumerable<Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe>
@if (!Model.Any())
@{
if (!Model.Any())
{
<p class="text-muted">Keine Ergebnisse gefunden.</p>
}
@@ -15,7 +16,7 @@ else
@{
var mediaFile = recipe.MediaFiles.FirstOrDefault();
}
@if (mediaFile != null && mediaFile.Data != null)
@if (mediaFile?.Data != null)
{
<img src="data:@mediaFile.MimeType;base64,@Convert.ToBase64String(mediaFile.Data)"
alt="@recipe.Name"
@@ -52,3 +53,5 @@ else
}
</div>
}
}