diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java index de46d99bd144296bc418a0395af29c3d35266d65..9dffb91b4d64cffc20785abf0b07c8e9c099e830 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/AllergyRepository.java @@ -3,7 +3,9 @@ package ntnu.idatt2016.v233.SmartMat.repository; import ntnu.idatt2016.v233.SmartMat.entity.Allergy; import java.util.List; -import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; /** * Repository for allergies @@ -12,13 +14,8 @@ import java.util.Optional; * @version 1.0 * @since 04.04.2023 */ -public interface AllergyRepository { - /** - * Saves a allergy to the database - * - * @param allergy Allergy to save - */ - Allergy save (Allergy allergy); +@Repository +public interface AllergyRepository extends JpaRepository<Allergy, String> { /** * Gets an allergy by name @@ -26,21 +23,6 @@ public interface AllergyRepository { * @param name the name of the allergy * @return an optional containing the Allergy if it exists */ - Optional<Allergy> getByName(String name); - - /** - * Gets all allergies - * - * @return an optional containing a list of all allergies - */ - Optional<List<Allergy>> getAll(); - - - /** - * Deletes an allergy by its name - * - * @param name the name of the allergy - */ - void deleteById(String name); + List<Allergy> findByName(String name); -} + } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java index 900825f32de98996432a448fa651d2725912436f..cb079eb2227357cc362ab5d8d2f85093175e6b8e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java @@ -2,30 +2,19 @@ package ntnu.idatt2016.v233.SmartMat.repository; import ntnu.idatt2016.v233.SmartMat.entity.product.Product; -import java.util.List; import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + /** * Repository for Products - * @author Birk + * @author Birk & Stian * @version 1.0 - * @since 04.04.2023 + * @since 19.04.2023 */ -public interface ProductRepository { - /** - * Saves a Product to the database - * - * @param product Product to save - */ - Product save (Product product); - - /** - * Gets a Product by its ID - * - * @param id the ID of the product - * @return an optional containing the product if it exists - */ - Optional<Product> getById(int id); +@Repository +public interface ProductRepository extends JpaRepository<Product, Long> { /** * Gets a Product by name @@ -33,21 +22,4 @@ public interface ProductRepository { * @param id the ID of the group * @return an optional containing the product if it exists */ - Optional<Product> getByProductName(String name); - - /** - * Gets all Products - * - * @return an optional containing a list of all products - */ - Optional<List<Product>> getAll(); - - - /** - * Deletes a product by its ID - * - * @param id the ID of the Product - */ - void deleteById(int id); - -} + Optional<Product> getByProductName(String name);} 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 2083b38804689cd009b7a2275b70694d7dc9b67e..75a8ed80fc026a19ef9f470c797c30d6f909b37a 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java @@ -1,6 +1,5 @@ package ntnu.idatt2016.v233.SmartMat.repository; -import java.util.List; import java.util.Optional; import ntnu.idatt2016.v233.SmartMat.entity.Recipe; @@ -11,22 +10,8 @@ import ntnu.idatt2016.v233.SmartMat.entity.Recipe; * @author Stian Lyng * @version 1.0 */ -public interface RecipeRepository { - - /** - * Saves a recipe to the database - * - * @param recipe the recipe to save - */ - Recipe save (Recipe recipe); - - /** - * Gets a recipe by its ID - * - * @param id the ID of the recipe - * @return an optional containing the recipe if it exists - */ - Optional<Recipe> getById(long id); +@Repository +public interface RecipeRepository extends JpaRepository<Recipe, Long> { /** * Gets a recipe by its name @@ -35,18 +20,4 @@ public interface RecipeRepository { */ Optional<Recipe> getByName(String name); - /** - * Gets all recipes - * - * @return an optional containing a list of all recipes - */ - Optional<List<Recipe>> getAll(); - - /** - * Deletes a recipe by its ID - * - * @param id the ID of the recipe - */ - void deleteById(int id); - } diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java index 2891cb4f2ce85b3c41d3f4a29bed2e47e3518d4d..9a9ed9a7aa584194a7cf38d24efcdced1caa21dc 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java @@ -12,23 +12,9 @@ import ntnu.idatt2016.v233.SmartMat.entity.ShoppingList; * @version 1.0 * */ -public interface ShoppingListRepository { - - /** - * Saves a shopping list to the database - * - * @param shoppingList the shopping list to save - */ - ShoppingList save (ShoppingList shoppingList); - - /** - * Gets a shopping list by its ID - * - * @param id the ID of the shopping list - * @return an optional containing the shopping list if it exists - */ - Optional<ShoppingList> getById(int id); - +@Repository +public interface ShoppingListRepository extends JpaRepository<ShoppingList, Long>{ + /** * Gets a shopping list by its group ID * @@ -36,14 +22,7 @@ public interface ShoppingListRepository { * @return an optional containing the shopping list if it exists */ Optional<ShoppingList> getByGroupID(int id); - - /** - * Gets all shopping lists - * - * @return an optional containing a list of all shopping lists - */ - Optional<List<ShoppingList>> getAll(); - + /** * Gets all shopping lists by group ID * @@ -51,12 +30,5 @@ public interface ShoppingListRepository { * @return an optional containing a list of all shopping lists in the group */ Optional<List<ShoppingList>> getAllByGroupID(int id); - - /** - * Deletes a shopping list by its ID - * - * @param id the ID of the shopping list - */ - void deleteById(int id); - + }