Skip to content
Snippets Groups Projects
Commit f3714357 authored by Stian Lyng's avatar Stian Lyng
Browse files

change to extend JpaRepository

parent 1036cd16
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......@@ -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);}
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);
}
......@@ -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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment