diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/dto/response/WeeklyMenuResponse.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/dto/response/WeeklyMenuResponse.java index 109e337e00229e68a6678390276de9a4559a02af..3e203560a7b6adcd7692eab13a2339f6685b0038 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/dto/response/WeeklyMenuResponse.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/dto/response/WeeklyMenuResponse.java @@ -17,6 +17,7 @@ public class WeeklyMenuResponse { private Integer recipeId; private String recipeName; private String recipeDescription; + private String recipeImage; private long matchingProducts; } \ No newline at end of file diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java index 122fda1f81b8bcef94b3207023c7eb84d4a6edb4..efea184a9be3a68979ecd5739d621bb4eeb251b4 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java @@ -22,63 +22,8 @@ public interface RecipeRepository extends JpaRepository<Recipe, Long> { */ List<Recipe> findAllByName(String name); - /** - * Finds the top 5 recipes with products that have a match with items in the given fridge. - * Returns a list of Object arrays, where each array contains the recipe details and product information. - * - * @param fridgeId the ID of the fridge to use for matching products - * @return a list of Object arrays with recipe and product details - */ - @Query(value = """ - WITH fridge_products AS ( - SELECT ean - FROM public.fridge_product - WHERE fridge_id = :fridgeId - ), - matched_products_count AS ( - SELECT - r.recipe_id, - r.recipe_name, - COUNT(*) AS product_count - FROM - public.recipe_product rp - JOIN public.recipe r ON rp.recipe_id = r.recipe_id - JOIN fridge_products fp ON rp.ean = fp.ean - GROUP BY - r.recipe_id, - r.recipe_name - ), - top_5_recipes AS ( - SELECT - recipe_id, - recipe_name, - product_count - FROM - matched_products_count - ORDER BY - product_count DESC, - recipe_id - LIMIT 5 - ) - SELECT - t.recipe_id, - t.recipe_name, - p.ean, - p.item_name, - p.description, - (rp.ean IN (SELECT ean FROM fridge_products)) AS in_fridge - FROM - top_5_recipes t - JOIN public.recipe_product rp ON t.recipe_id = rp.recipe_id - JOIN public.product p ON rp.ean = p.ean - ORDER BY - t.recipe_id, - p.ean; - """, nativeQuery = true) - List<Object[]> findTop5RecipesWithProductsRaw(@Param("fridgeId") long fridgeId); - @Query( value = """ - SELECT r.recipe_id, r.recipe_name,r.recipe_description,r.image_url,r.guide, COUNT(fp.ean) as product_count + SELECT r.recipe_id, r.recipe_name,r.recipe_description,r.image_url, COUNT(fp.ean) as product_count FROM recipe r LEFT JOIN recipe_product rp ON r.recipe_id = rp.recipe_id LEFT JOIN fridge_product fp ON rp.ean = fp.ean AND fp.fridge_id = :fridgeId diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java index 870b355345307ddf7c590960c34793f9b6f4a9e9..8965be1d7bf2c390a0420fffd4f13a01b9593c33 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/WeeklyMenuService.java @@ -38,7 +38,8 @@ public class WeeklyMenuService { (Integer) row[0], (String) row[1], (String) row[2], - (long) row[3] + (String) row[3], + (long) row[4] )) .collect(Collectors.toList());