diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListReposity.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java similarity index 97% rename from src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListReposity.java rename to src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java index 2db46021ade35e46a7fa840ec3d54764823c8721..5153b8ee5f6138ab876e15fc651e43b2703411fd 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListReposity.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ShoppingListRepository.java @@ -12,7 +12,7 @@ import ntnu.idatt2016.v233.SmartMat.model.ShoppingList; * @version 1.0 * */ -public interface ShoppingListReposity { +public interface ShoppingListRepository { /** * Saves a shopping list to the database diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java new file mode 100644 index 0000000000000000000000000000000000000000..a9d38f5c36349ee7c1910beba4ef4aac73854a60 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/ShoppingListService.java @@ -0,0 +1,84 @@ +package ntnu.idatt2016.v233.SmartMat.service; + +import java.util.List; +import java.util.Optional; + +import ntnu.idatt2016.v233.SmartMat.model.ShoppingList; +import ntnu.idatt2016.v233.SmartMat.repository.ShoppingListRepository; + +/** + * Service for the shopping list + * + * @author Stian Lyng + * @version 1.0 + */ +public class ShoppingListService { + + ShoppingListRepository shoppingListRepository; + /** + * Creates a new ShoppingListService + * + * @param shoppingListRepository The repository to use + */ + public ShoppingListService(ShoppingListRepository shoppingListRepository) { + this.shoppingListRepository = shoppingListRepository; + } + + /** + * Saves a shopping list to the database + * @param shoppingList the shopping list to save + * @return the saved shopping list + */ + public ShoppingList saveShoppingList(ShoppingList shoppingList) { + return shoppingListRepository.save(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 + */ + public Optional<ShoppingList> getShoppingListById(int id) { + return shoppingListRepository.getById(id); + } + + /** + * Gets a shopping list by its group ID + * + * @param id the ID of the group + * @return an optional containing the shopping list if it exists + */ + public Optional<ShoppingList> getShoppingListByGroupId(int id) { + return shoppingListRepository.getByGroupID(id); + } + + /** + * Gets all shopping lists + * + * @return an optional containing a list of all shopping lists if they exist + */ + public Optional<List<ShoppingList>> getAllShoppingLists() { + return shoppingListRepository.getAll(); + } + + /** + * Gets all shopping lists by group ID + * + * @param id the ID of the group + * @return an optional containing a list of all shopping lists if they exist + */ + public Optional<List<ShoppingList>> getAllShoppingListsByGroupId(int id) { + return shoppingListRepository.getAllByGroupID(id); + } + + /** + * Deletes a shopping list by its ID + * + * @param id the ID of the shopping list + */ + public void deleteShoppingListById(int id) { + shoppingListRepository.deleteById(id); + } + +}