Interface RecipeRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Recipe,
,Long> org.springframework.data.jpa.repository.JpaRepository<Recipe,
,Long> org.springframework.data.repository.ListCrudRepository<Recipe,
,Long> org.springframework.data.repository.ListPagingAndSortingRepository<Recipe,
,Long> org.springframework.data.repository.PagingAndSortingRepository<Recipe,
,Long> org.springframework.data.repository.query.QueryByExampleExecutor<Recipe>
,org.springframework.data.repository.Repository<Recipe,
Long>
public interface RecipeRepository
extends org.springframework.data.jpa.repository.JpaRepository<Recipe,Long>
This interface defines the methods for the recipe repository
- Version:
- 2.0
- Author:
- Stian Lyng
-
Method Summary
Modifier and TypeMethodDescriptionfindAllByName
(String name) Gets a recipe by its nameGets a list of recipes with their productsfindWeeklyMenu
(long fridgeId) Gets a weekly menu for a fridgeMethods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save
Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush
Methods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAll
Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAll
Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAll
Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findAllByName
Gets a recipe by its name- Parameters:
name
- the name of the recipe- Returns:
- an optional containing the recipe if it exists
-
findWeeklyMenu
@Query(value="select p2.item_name, f.fridge_id\nfrom fridge f\ninner join fridge_product fp on f.fridge_id = fp.fridge_id and f.fridge_id = :fridgeId\ninner join product p2 on p2.ean = fp.ean\n", nativeQuery=true) List<Object[]> findWeeklyMenu(long fridgeId) Gets a weekly menu for a fridge- Parameters:
fridgeId
- the id of the fridge- Returns:
- a list of objects containing the name of the product and the id of the fridge
-
findRecipeProductsWithName
@Query(value="SELECT r.recipe_id, r.recipe_name, r.recipe_description, r.image_url, p.item_name\nFROM recipe r\ninner JOIN recipe_product rp ON r.recipe_id = rp.recipe_id\ninner join product p on rp.ean = p.ean\n", nativeQuery=true) List<Object[]> findRecipeProductsWithName()Gets a list of recipes with their products- Returns:
- a list of objects containing the recipe id, name, description, image url and product name
-