diff --git a/Aberwyn/Controllers/MealController.cs b/Aberwyn/Controllers/MealController.cs index 9272520..c677423 100644 --- a/Aberwyn/Controllers/MealController.cs +++ b/Aberwyn/Controllers/MealController.cs @@ -18,7 +18,11 @@ namespace Aberwyn.Controllers _configuration = configuration; _env = env; } - + [HttpGet("/meal")] + public IActionResult Index() + { + return View("Index"); + } [HttpGet] public IActionResult View(int? id, bool edit = false) { diff --git a/Aberwyn/Controllers/MealMenuApiController.cs b/Aberwyn/Controllers/MealMenuApiController.cs index 57b7956..02d7d17 100644 --- a/Aberwyn/Controllers/MealMenuApiController.cs +++ b/Aberwyn/Controllers/MealMenuApiController.cs @@ -30,11 +30,12 @@ namespace Aberwyn.Controllers [HttpGet("getMeals")] public IActionResult GetMeals() { - var meals = _menuService.GetMealsDetailed(); // Hämtar med ImageData - var mealDtos = meals.Select(MealDto.FromMeal).ToList(); + var meals = _menuService.GetMealsSlim(true); + var mealDtos = meals.Select(m => MealDto.FromMeal(m, includeThumbnail: true)).ToList(); // 👈 fix return Ok(mealDtos); } + [HttpGet("getWeeklyMenu")] public IActionResult GetWeeklyMenu(int weekNumber, int year) { diff --git a/Aberwyn/Data/MenuService.cs b/Aberwyn/Data/MenuService.cs index 4ba0483..e0d071c 100644 --- a/Aberwyn/Data/MenuService.cs +++ b/Aberwyn/Data/MenuService.cs @@ -165,9 +165,35 @@ public class MenuService _context.SaveChanges(); return updatedCount; } - - public List GetAllWeeklyMenus() +public List GetMealsSlim(bool includeThumbnail = false) { + if (includeThumbnail) + { + return _context.Meals + .Select(m => new Meal + { + Id = m.Id, + Name = m.Name, + Description = m.Description, + ThumbnailData = m.ThumbnailData + }) + .ToList(); + } + else + { + return _context.Meals + .Select(m => new Meal + { + Id = m.Id, + Name = m.Name, + Description = m.Description + }) + .ToList(); + } +} + + public List GetAllWeeklyMenus() + { var menus = _context.WeeklyMenus.ToList(); var allMeals = _context.Meals.ToDictionary(m => m.Id, m => m.Name); diff --git a/Aberwyn/Models/MenuViewModel.cs b/Aberwyn/Models/MenuViewModel.cs index 335cd0e..449763e 100644 --- a/Aberwyn/Models/MenuViewModel.cs +++ b/Aberwyn/Models/MenuViewModel.cs @@ -104,20 +104,39 @@ public class WeeklyMenu public string? ImageData { get; set; } // base64 public string? ImageMimeType { get; set; } - public static MealDto FromMeal(Meal meal) + public static MealListDto FromMeal(Meal meal, bool includeThumbnail = false) { - return new MealDto + return new MealListDto { Id = meal.Id, Name = meal.Name, - Category = meal.Category, - IsAvailable = meal.IsAvailable, - ImageUrl = meal.ImageUrl, - ImageMimeType = meal.ImageMimeType, - ImageData = meal.ImageData != null ? Convert.ToBase64String(meal.ImageData) : null + Description = meal.Description, + ThumbnailData = includeThumbnail && meal.ThumbnailData != null + ? Convert.ToBase64String(meal.ThumbnailData) + : null }; } - } + } + public class MealListDto + { + public int Id { get; set; } + public string Name { get; set; } = ""; + public string? Description { get; set; } + public string? ThumbnailData { get; set; } + + public static MealListDto FromMeal(Meal meal, bool includeThumbnail = false) + { + return new MealListDto + { + Id = meal.Id, + Name = meal.Name, + Description = meal.Description, + ThumbnailData = includeThumbnail && meal.ThumbnailData != null + ? Convert.ToBase64String(meal.ThumbnailData) + : null + }; + } + } } diff --git a/Aberwyn/Views/Meal/Index.cshtml b/Aberwyn/Views/Meal/Index.cshtml new file mode 100644 index 0000000..2ba182a --- /dev/null +++ b/Aberwyn/Views/Meal/Index.cshtml @@ -0,0 +1,48 @@ + + + + + Måltider + + + + + + + + + + + + + + diff --git a/Aberwyn/wwwroot/css/meal-gallery.css b/Aberwyn/wwwroot/css/meal-gallery.css new file mode 100644 index 0000000..6601d7a --- /dev/null +++ b/Aberwyn/wwwroot/css/meal-gallery.css @@ -0,0 +1,107 @@ +body { + background-color: #f7f7f7; + font-family: 'Segoe UI', sans-serif; + color: #222; + margin: 0; + } + + .meal-gallery-container { + max-width: 1200px; + margin: 0 auto; + padding: 2rem 1rem; + } + + .meal-gallery-header { + text-align: center; + margin-bottom: 2rem; + } + + .meal-gallery-header h1 { + font-size: 2.4rem; + font-weight: 600; + } + + .search-container { + margin-top: 1rem; + position: relative; + max-width: 400px; + margin-inline: auto; + } + + .search-container input { + width: 100%; + padding: 10px 38px 10px 12px; + border-radius: 25px; + border: 1px solid #ccc; + font-size: 1rem; + } + + .search-container i { + position: absolute; + right: 12px; + top: 50%; + transform: translateY(-50%); + color: #888; + } + + .meal-gallery-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); + gap: 24px; + } + + .meal-card { + background: white; + border-radius: 12px; + overflow: hidden; + box-shadow: 0 2px 8px rgba(0,0,0,0.05); + transition: transform 0.2s ease, box-shadow 0.2s ease; + display: flex; + flex-direction: column; + } + + .meal-card:hover { + transform: scale(1.015); + box-shadow: 0 4px 12px rgba(0,0,0,0.1); + } + + .meal-card img { + width: 100%; + height: 200px; + object-fit: cover; + } + + .meal-card-content { + padding: 16px; + display: flex; + flex-direction: column; + flex-grow: 1; + } + + .meal-card-content h3 { + margin: 0 0 8px; + font-size: 1.2rem; + color: #111; + } + + .meal-card-content p { + flex-grow: 1; + font-size: 0.95rem; + color: #555; + } + + .btn-readmore { + align-self: flex-start; + background: #007d36; + color: white; + padding: 8px 12px; + border-radius: 6px; + text-decoration: none; + font-size: 0.95rem; + margin-top: 12px; + } + + .btn-readmore:hover { + background: #005c27; + } + \ No newline at end of file diff --git a/Aberwyn/wwwroot/images/fallback.jpg b/Aberwyn/wwwroot/images/fallback.jpg new file mode 100644 index 0000000..042b110 Binary files /dev/null and b/Aberwyn/wwwroot/images/fallback.jpg differ