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 f675fea2cbd5b3061941f11b931f2f5d87d949b5..ac02c0502d2c934026828878f37851cd0c55aa4a 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.model.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 2bacb4c9d0301fe47e9a4cb1a0108ca771e3224c..63e319b33dc79d15923e521d718e5f1e5a3853f7 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.model.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 cae4ee3d68f3231fa3071601fce73cf22c718ca0..020a57fa07863136ed41c0e5e02abb53f877fa18 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/RecipeRepository.java @@ -1,8 +1,10 @@ package ntnu.idatt2016.v233.SmartMat.repository; -import java.util.List; import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + import ntnu.idatt2016.v233.SmartMat.model.Recipe; /** @@ -11,22 +13,8 @@ import ntnu.idatt2016.v233.SmartMat.model.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 +23,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 5153b8ee5f6138ab876e15fc651e43b2703411fd..3c69beedd2a649cb94e4ecfef09b463a9456e7ec 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java @@ -3,6 +3,9 @@ package ntnu.idatt2016.v233.SmartMat.repository; import java.util.List; import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + import ntnu.idatt2016.v233.SmartMat.model.ShoppingList; /** @@ -12,23 +15,9 @@ import ntnu.idatt2016.v233.SmartMat.model.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 +25,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 +33,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); - + }